Skip to content

Instantly share code, notes, and snippets.

@andrewpisula
Created November 23, 2018 16:46
Show Gist options
  • Save andrewpisula/7ae6edd55665dd898fe1a0d0c654efe7 to your computer and use it in GitHub Desktop.
Save andrewpisula/7ae6edd55665dd898fe1a0d0c654efe7 to your computer and use it in GitHub Desktop.
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
Copy link

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