MCPcopy Create free account
hub / github.com/The-Powder-Toy/The-Powder-Toy / LuaScriptInterface

Method LuaScriptInterface

src/lua/LuaScriptInterface.cpp:128–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126}
127
128LuaScriptInterface::LuaScriptInterface(GameController *newGameController, GameModel *newGameModel) :
129 CommandInterface(newGameController, newGameModel),
130 ren(newGameModel->GetRenderer()),
131 gameModel(newGameModel),
132 gameController(newGameController),
133 window(gameController->GetView()),
134 sim(gameModel->GetSimulation()),
135 g(ui::Engine::Ref().g),
136 customElements(PT_NUM),
137 gameControllerEventHandlers(std::variant_size_v<GameControllerEvent>)
138{
139 auto &prefs = GlobalPrefs::Ref();
140 luaHookTimeout = prefs.Get("LuaHookTimeout", 3000);
141 for (auto moving = 0; moving < PT_NUM; ++moving)
142 {
143 for (auto into = 0; into < PT_NUM; ++into)
144 {
145 customCanMove[moving][into] = 0;
146 }
147 }
148 luaState = LuaStatePtr(luaL_newstate());
149 L = luaState.get();
150 lua_sethook(L, hook, LUA_MASKCOUNT, 200);
151 lua_atpanic(L, atPanic);
152 luaL_openlibs(L);
153 {
154 luaopen_bit(L);
155 lua_pop(L, 1);
156 }
157 LuaBz2::Open(L);
158 LuaElements::Open(L);
159 LuaEvent::Open(L);
160 LuaFileSystem::Open(L);
161 LuaGraphics::Open(L);
162 LuaHttp::Open(L);
163 LuaInterface::Open(L);
164 LuaMisc::Open(L);
165 LuaPlatform::Open(L);
166 LuaRenderer::Open(L);
167 LuaSimulation::Open(L);
168 LuaSocket::Open(L);
169 LuaTools::Open(L);
170 {
171 lua_getglobal(L, "os");
172 lua_pushcfunction(L, osExit);
173 lua_setfield(L, -2, "exit");
174 lua_pop(L, 1);
175 }
176 {
177 lua_getglobal(L, "math");
178 lua_pushcfunction(L, mathRandom);
179 lua_setfield(L, -2, "random");
180 lua_pushcfunction(L, mathRandomseed);
181 lua_setfield(L, -2, "randomseed");
182 lua_pop(L, 1);
183 }
184 auto compatSpan = compat_lua.AsCharSpan();
185 if (luaL_loadbuffer(L, compatSpan.data(), compatSpan.size(), "@[built-in compat.lua]") || tpt_lua_pcall(L, 0, 0, 0, eventTraitNone))

Callers

nothing calls this directly

Calls 11

luaopen_bitFunction · 0.85
tpt_lua_pcallFunction · 0.85
tpt_lua_toByteStringFunction · 0.85
getMethod · 0.80
dataMethod · 0.80
ByteStringClass · 0.50
GetRendererMethod · 0.45
GetViewMethod · 0.45
GetSimulationMethod · 0.45
GetMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected