diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp index b6b550619..fb0180268 100644 --- a/src/cat/LuaScriptInterface.cpp +++ b/src/cat/LuaScriptInterface.cpp @@ -485,7 +485,6 @@ void LuaScriptInterface::initSimulationAPI() {NULL, NULL} }; luaL_register(l, "simulation", simulationAPIMethods); - int simulationAPI = lua_gettop(l); //Sim shortcut lua_getglobal(l, "simulation"); @@ -495,7 +494,6 @@ void LuaScriptInterface::initSimulationAPI() SETCONST(l, XRES); SETCONST(l, YRES); SETCONST(l, PT_NUM); - lua_pushinteger(l, luacon_sim->NUM_PARTS); lua_setfield(l, simulationAPI, "NUM_PARTS"); SETCONST(l, R_TEMP); SETCONST(l, MAX_TEMP); SETCONST(l, MIN_TEMP); @@ -506,7 +504,7 @@ void LuaScriptInterface::initSimulationAPI() SETCONST(l, TOOL_AIR); SETCONST(l, TOOL_PGRV); SETCONST(l, TOOL_NGRV); - lua_pushinteger(l, luacon_sim->tools.size()); lua_setfield(l, simulationAPI, "TOOL_WIND"); + lua_pushinteger(l, luacon_sim->tools.size()); lua_setfield(l, -2, "TOOL_WIND"); SETCONST(l, DECO_DRAW); SETCONST(l, DECO_CLEAR); SETCONST(l, DECO_ADD); @@ -524,7 +522,7 @@ void LuaScriptInterface::initSimulationAPI() std::string propertyName = (*iter).Name; std::transform(propertyName.begin(), propertyName.end(), propertyName.begin(), ::toupper); lua_pushinteger(l, particlePropertiesCount); - lua_setfield(l, simulationAPI, ("FIELD_"+propertyName).c_str()); + lua_setfield(l, -2, ("FIELD_"+propertyName).c_str()); particleProperties[particlePropertiesCount++] = *iter; } } @@ -1717,8 +1715,6 @@ void LuaScriptInterface::initElementsAPI() lua_getglobal(l, "elements"); lua_setglobal(l, "elem"); - int elementsAPI = lua_gettop(l); - //Static values //Element types/properties/states SETCONST(l, TYPE_PART); @@ -1770,13 +1766,13 @@ void LuaScriptInterface::initElementsAPI() if(luacon_sim->elements[i].Enabled) { lua_pushinteger(l, i); - lua_setfield(l, elementsAPI, luacon_sim->elements[i].Identifier); + lua_setfield(l, -2, luacon_sim->elements[i].Identifier); char realIdentifier[20]; sprintf(realIdentifier, "DEFAULT_PT_%s", luacon_sim->elements[i].Name); if (i != 0 && i != PT_NBHL && i != PT_NWHL && strcmp(luacon_sim->elements[i].Identifier, realIdentifier)) { lua_pushinteger(l, i); - lua_setfield(l, elementsAPI, realIdentifier); + lua_setfield(l, -2, realIdentifier); } } } @@ -2321,10 +2317,8 @@ void LuaScriptInterface::initGraphicsAPI() lua_getglobal(l, "graphics"); lua_setglobal(l, "gfx"); - int graphicsAPI = lua_gettop(l); - - lua_pushinteger(l, XRES+BARSIZE); lua_setfield(l, graphicsAPI, "WIDTH"); - lua_pushinteger(l, YRES+MENUSIZE); lua_setfield(l, graphicsAPI, "HEIGHT"); + lua_pushinteger(l, XRES+BARSIZE); lua_setfield(l, -2, "WIDTH"); + lua_pushinteger(l, YRES+MENUSIZE); lua_setfield(l, -2, "HEIGHT"); } int LuaScriptInterface::graphics_textSize(lua_State * l) @@ -2781,6 +2775,8 @@ bool LuaScriptInterface::OnKeyRelease(int key, Uint16 character, bool shift, boo void LuaScriptInterface::OnTick() { + lua_getglobal(l, "simulation"); + lua_pushinteger(l, luacon_sim->NUM_PARTS); lua_setfield(l, -2, "NUM_PARTS"); ui::Engine::Ref().LastTick(clock()); if(luacon_mousedown) luacon_mouseevent(luacon_mousex, luacon_mousey, luacon_mousebutton, LUACON_MPRESS, 0); diff --git a/src/cat/LuaScriptInterface.h b/src/cat/LuaScriptInterface.h index ad0b70f88..5a09be929 100644 --- a/src/cat/LuaScriptInterface.h +++ b/src/cat/LuaScriptInterface.h @@ -40,7 +40,7 @@ class Tool; // idea from mniip, makes things much simpler #define SETCONST(L, NAME)\ lua_pushinteger(L, NAME);\ - lua_setfield(L, -2, #NAME); + lua_setfield(L, -2, #NAME) class TPTScriptInterface; class LuaScriptInterface: public CommandInterface diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index f4992b294..97a81c5cc 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -27,6 +27,11 @@ #include "gui/interface/Keys.h" #include "simulation/Snapshot.h" #include "debug/DebugInfo.h" +#ifdef LUACONSOLE +#include "cat/LuaScriptInterface.h" +#else +#include "cat/TPTScriptInterface.h" +#endif //#include "debug/ElementPopulation.h" using namespace std; diff --git a/src/gui/game/GameController.h b/src/gui/game/GameController.h index cc49f3b15..32755dfb7 100644 --- a/src/gui/game/GameController.h +++ b/src/gui/game/GameController.h @@ -14,11 +14,6 @@ #include "gui/console/ConsoleController.h" #include "gui/localbrowser/LocalBrowserController.h" #include "gui/options/OptionsController.h" -#ifdef LUACONSOLE -#include "cat/LuaScriptInterface.h" -#else -#include "cat/TPTScriptInterface.h" -#endif #include "client/ClientListener.h" #include "RenderPreset.h" #include "Menu.h"