Fix LuaScriptInterface ctor stack imbalance

This commit is contained in:
Tamás Bálint Misius
2023-09-02 13:32:39 +02:00
parent 52a4917624
commit 6a64de8297

View File

@@ -291,6 +291,7 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
lua_atpanic(l, atPanic); lua_atpanic(l, atPanic);
luaL_openlibs(l); luaL_openlibs(l);
luaopen_bit(l); luaopen_bit(l);
lua_pop(l, 1);
lua_pushliteral(l, "Luacon_ci"); lua_pushliteral(l, "Luacon_ci");
lua_pushlightuserdata(l, this); lua_pushlightuserdata(l, this);
@@ -536,6 +537,7 @@ tpt.partsdata = nil");
{ {
throw std::runtime_error(ByteString("failed to load built-in eventcompat: ") + tpt_lua_toByteString(l, -1)); throw std::runtime_error(ByteString("failed to load built-in eventcompat: ") + tpt_lua_toByteString(l, -1));
} }
lua_pop(l, 1);
} }
void LuaScriptInterface::custom_init_can_move() void LuaScriptInterface::custom_init_can_move()
@@ -796,13 +798,14 @@ void LuaScriptInterface::initInterfaceAPI()
{NULL, NULL} {NULL, NULL}
}; };
luaL_register(l, "interface", interfaceAPIMethods); luaL_register(l, "interface", interfaceAPIMethods);
//Ren shortcut
lua_getglobal(l, "interface");
initLuaSDLKeys(l); initLuaSDLKeys(l);
lua_pushinteger(l, GameController::mouseUpNormal); lua_setfield(l, -2, "MOUSE_UP_NORMAL"); lua_pushinteger(l, GameController::mouseUpNormal); lua_setfield(l, -2, "MOUSE_UP_NORMAL");
lua_pushinteger(l, GameController::mouseUpBlur); lua_setfield(l, -2, "MOUSE_UP_BLUR"); lua_pushinteger(l, GameController::mouseUpBlur); lua_setfield(l, -2, "MOUSE_UP_BLUR");
lua_pushinteger(l, GameController::mouseUpDrawEnd); lua_setfield(l, -2, "MOUSE_UP_DRAW_END"); lua_pushinteger(l, GameController::mouseUpDrawEnd); lua_setfield(l, -2, "MOUSE_UP_DRAW_END");
lua_pop(l, 1);
//Ren shortcut
lua_getglobal(l, "interface");
lua_setglobal(l, "ui"); lua_setglobal(l, "ui");
Luna<LuaWindow>::Register(l); Luna<LuaWindow>::Register(l);
@@ -1169,10 +1172,6 @@ void LuaScriptInterface::initSimulationAPI()
}; };
luaL_register(l, "simulation", simulationAPIMethods); luaL_register(l, "simulation", simulationAPIMethods);
//Sim shortcut
lua_getglobal(l, "simulation");
lua_setglobal(l, "sim");
//Static values //Static values
SETCONST(l, CELL); SETCONST(l, CELL);
SETCONST(l, XCELLS); SETCONST(l, XCELLS);
@@ -1254,6 +1253,12 @@ void LuaScriptInterface::initSimulationAPI()
lua_pushcfunction(l, simulation_deletesign); lua_pushcfunction(l, simulation_deletesign);
lua_setfield(l, -2, "delete"); lua_setfield(l, -2, "delete");
lua_setfield(l, -2, "signs"); lua_setfield(l, -2, "signs");
lua_pop(l, 1);
//Sim shortcut
lua_getglobal(l, "simulation");
lua_setglobal(l, "sim");
} }
void LuaScriptInterface::set_map(int x, int y, int width, int height, float value, int map) // A function so this won't need to be repeated many times later void LuaScriptInterface::set_map(int x, int y, int width, int height, float value, int map) // A function so this won't need to be repeated many times later
@@ -2745,10 +2750,6 @@ void LuaScriptInterface::initRendererAPI()
}; };
luaL_register(l, "renderer", rendererAPIMethods); luaL_register(l, "renderer", rendererAPIMethods);
//Ren shortcut
lua_getglobal(l, "renderer");
lua_setglobal(l, "ren");
//Static values //Static values
//Particle pixel modes/fire mode/effects //Particle pixel modes/fire mode/effects
SETCONST(l, PMODE); SETCONST(l, PMODE);
@@ -2796,6 +2797,12 @@ void LuaScriptInterface::initRendererAPI()
SETCONST(l, DISPLAY_WARP); SETCONST(l, DISPLAY_WARP);
SETCONST(l, DISPLAY_PERS); SETCONST(l, DISPLAY_PERS);
SETCONST(l, DISPLAY_EFFE); SETCONST(l, DISPLAY_EFFE);
lua_pop(l, 1);
//Ren shortcut
lua_getglobal(l, "renderer");
lua_setglobal(l, "ren");
} }
//get/set render modes list //get/set render modes list
@@ -3022,10 +3029,6 @@ void LuaScriptInterface::initElementsAPI()
}; };
luaL_register(l, "elements", elementsAPIMethods); luaL_register(l, "elements", elementsAPIMethods);
//elem shortcut
lua_getglobal(l, "elements");
lua_setglobal(l, "elem");
//Static values //Static values
//Element types/properties/states //Element types/properties/states
SETCONST(l, TYPE_PART); SETCONST(l, TYPE_PART);
@@ -3095,6 +3098,12 @@ void LuaScriptInterface::initElementsAPI()
} }
} }
} }
lua_pop(l, 1);
//elem shortcut
lua_getglobal(l, "elements");
lua_setglobal(l, "elem");
} }
void LuaScriptInterface::LuaGetProperty(lua_State* l, StructProperty property, intptr_t propertyAddress) void LuaScriptInterface::LuaGetProperty(lua_State* l, StructProperty property, intptr_t propertyAddress)
@@ -3923,12 +3932,14 @@ void LuaScriptInterface::initGraphicsAPI()
}; };
luaL_register(l, "graphics", graphicsAPIMethods); luaL_register(l, "graphics", graphicsAPIMethods);
lua_pushinteger(l, WINDOWW); lua_setfield(l, -2, "WIDTH");
lua_pushinteger(l, WINDOWH); lua_setfield(l, -2, "HEIGHT");
lua_pop(l, 1);
//elem shortcut //elem shortcut
lua_getglobal(l, "graphics"); lua_getglobal(l, "graphics");
lua_setglobal(l, "gfx"); lua_setglobal(l, "gfx");
lua_pushinteger(l, WINDOWW); lua_setfield(l, -2, "WIDTH");
lua_pushinteger(l, WINDOWH); lua_setfield(l, -2, "HEIGHT");
} }
int LuaScriptInterface::graphics_textSize(lua_State * l) int LuaScriptInterface::graphics_textSize(lua_State * l)
@@ -4175,6 +4186,7 @@ void LuaScriptInterface::initFileSystemAPI()
{NULL, NULL} {NULL, NULL}
}; };
luaL_register(l, "fileSystem", fileSystemAPIMethods); luaL_register(l, "fileSystem", fileSystemAPIMethods);
lua_pop(l, 1);
//elem shortcut //elem shortcut
lua_getglobal(l, "fileSystem"); lua_getglobal(l, "fileSystem");
@@ -4284,6 +4296,7 @@ void LuaScriptInterface::initPlatformAPI()
{NULL, NULL} {NULL, NULL}
}; };
luaL_register(l, "platform", platformAPIMethods); luaL_register(l, "platform", platformAPIMethods);
lua_pop(l, 1);
//elem shortcut //elem shortcut
lua_getglobal(l, "platform"); lua_getglobal(l, "platform");
@@ -4357,9 +4370,6 @@ void LuaScriptInterface::initEventAPI()
}; };
luaL_register(l, "event", eventAPIMethods); luaL_register(l, "event", eventAPIMethods);
lua_getglobal(l, "event");
lua_setglobal(l, "evt");
lua_pushinteger(l, VariantIndex<GameControllerEvent, TextInputEvent >()); lua_setfield(l, -2, "textinput" ); lua_pushinteger(l, VariantIndex<GameControllerEvent, TextInputEvent >()); lua_setfield(l, -2, "textinput" );
lua_pushinteger(l, VariantIndex<GameControllerEvent, TextEditingEvent>()); lua_setfield(l, -2, "textediting"); lua_pushinteger(l, VariantIndex<GameControllerEvent, TextEditingEvent>()); lua_setfield(l, -2, "textediting");
lua_pushinteger(l, VariantIndex<GameControllerEvent, KeyPressEvent >()); lua_setfield(l, -2, "keypress" ); lua_pushinteger(l, VariantIndex<GameControllerEvent, KeyPressEvent >()); lua_setfield(l, -2, "keypress" );
@@ -4373,6 +4383,11 @@ void LuaScriptInterface::initEventAPI()
lua_pushinteger(l, VariantIndex<GameControllerEvent, CloseEvent >()); lua_setfield(l, -2, "close" ); lua_pushinteger(l, VariantIndex<GameControllerEvent, CloseEvent >()); lua_setfield(l, -2, "close" );
lua_pushinteger(l, VariantIndex<GameControllerEvent, BeforeSimEvent >()); lua_setfield(l, -2, "beforesim" ); lua_pushinteger(l, VariantIndex<GameControllerEvent, BeforeSimEvent >()); lua_setfield(l, -2, "beforesim" );
lua_pushinteger(l, VariantIndex<GameControllerEvent, AfterSimEvent >()); lua_setfield(l, -2, "aftersim" ); lua_pushinteger(l, VariantIndex<GameControllerEvent, AfterSimEvent >()); lua_setfield(l, -2, "aftersim" );
lua_pop(l, 1);
lua_getglobal(l, "event");
lua_setglobal(l, "evt");
} }
int LuaScriptInterface::event_register(lua_State * l) int LuaScriptInterface::event_register(lua_State * l)