Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A simple lua c parser I wrote when I was bored.
DWORD HandlerState;
void LuaC_Handler(std::vector<std::string> it) {
if (HandlerState == NULL) {
HandlerState = rlua_newthread(rawstate);
}
if (it.at(0) == "getglobal") {
rlua_getglobal(HandlerState, it.at(1).c_str());
}
if (it.at(0) == "getfield") {
rlua_getfield(HandlerState, std::stoi(it.at(1)), it.at(2).c_str());
}
if (it.at(0) == "setfield") {
rlua_setfield(HandlerState, std::stoi(it.at(1)), it.at(2).c_str());
}
if (it.at(0) == "call" || it.at(0) == "pcall") {
rlua_call(HandlerState, std::stoi(it.at(1)), std::stoi(it.at(2)));
}
if (it.at(0) == "pushvalue") {
rlua_pushvalue(HandlerState, std::stoi(it.at(1)));
}
if (it.at(0) == "pushboolean") {
rlua_pushboolean(HandlerState, it.at(0) == "true");
}
if (it.at(0) == "pushstring") {
std::string BuiltString;
for (int i = 1; i < it.size() - 1; ++i) {
BuiltString += it.at(i) + " ";
}
rlua_pushstring(HandlerState, BuiltString.c_str());
}
if (it.at(0) == "pushnumber") {
rlua_pushnumber(HandlerState, std::stod(it.at(1)));
}
if (it.at(0) == "pushnil") {
rlua_pushnil(HandlerState);
}
if (it.at(0) == "settop") {
rlua_settop(HandlerState, std::stoi(it.at(1)));
}
if (it.at(0) == "emptystack") {
rlua_emptystack(HandlerState);
}
if (it.at(0) == "pop") {
rlua_pop(HandlerState, std::stoi(it.at(1)));
}
}
@Cyberhound

This comment has been minimized.

Copy link

@Cyberhound Cyberhound commented Nov 23, 2018

Add pcall noobo also don't do a new state stick with the "rawstate" (global state)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment