diff options
Diffstat (limited to 'src/state.cpp')
-rw-r--r-- | src/state.cpp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/state.cpp b/src/state.cpp index 7585132..77e1fd9 100644 --- a/src/state.cpp +++ b/src/state.cpp | |||
@@ -31,6 +31,7 @@ THE SOFTWARE. | |||
31 | =============================================================================== | 31 | =============================================================================== |
32 | */ | 32 | */ |
33 | 33 | ||
34 | #include "_pch.h" | ||
34 | #include "state.h" | 35 | #include "state.h" |
35 | 36 | ||
36 | #include "intercopycontext.h" | 37 | #include "intercopycontext.h" |
@@ -39,8 +40,6 @@ THE SOFTWARE. | |||
39 | #include "tools.h" | 40 | #include "tools.h" |
40 | #include "universe.h" | 41 | #include "universe.h" |
41 | 42 | ||
42 | #include <source_location> | ||
43 | |||
44 | // ################################################################################################# | 43 | // ################################################################################################# |
45 | 44 | ||
46 | static constexpr char const* kOnStateCreate{ "on_state_create" }; // update lanes.lua if the name changes! | 45 | static constexpr char const* kOnStateCreate{ "on_state_create" }; // update lanes.lua if the name changes! |
@@ -184,9 +183,9 @@ namespace state { | |||
184 | STACK_CHECK(L_, 1); | 183 | STACK_CHECK(L_, 1); |
185 | // capture error and raise it in caller state | 184 | // capture error and raise it in caller state |
186 | std::string_view const _stateType{ mode_ == LookupMode::LaneBody ? "lane" : "keeper" }; | 185 | std::string_view const _stateType{ mode_ == LookupMode::LaneBody ? "lane" : "keeper" }; |
187 | std::ignore = lua_pushstringview(L_, _stateType); // L_: on_state_create() "<type>" | 186 | std::ignore = luaG_pushstring(L_, _stateType); // L_: on_state_create() "<type>" |
188 | if (lua_pcall(L_, 1, 0, 0) != LUA_OK) { | 187 | if (lua_pcall(L_, 1, 0, 0) != LUA_OK) { |
189 | raise_luaL_error(from_, "%s failed: \"%s\"", kOnStateCreate, lua_isstring(L_, -1) ? lua_tostring(L_, -1) : lua_typename(L_, lua_type(L_, -1))); | 188 | raise_luaL_error(from_, "%s failed: \"%s\"", kOnStateCreate, lua_isstring(L_, -1) ? lua_tostring(L_, -1) : luaG_typename(L_, luaG_type(L_, -1))); |
190 | } | 189 | } |
191 | STACK_CHECK(L_, 0); | 190 | STACK_CHECK(L_, 0); |
192 | } | 191 | } |
@@ -205,7 +204,7 @@ namespace state { | |||
205 | if (U->provideAllocator != nullptr) { // we have a function we can call to obtain an allocator | 204 | if (U->provideAllocator != nullptr) { // we have a function we can call to obtain an allocator |
206 | lua_pushcclosure(from, U->provideAllocator, 0); | 205 | lua_pushcclosure(from, U->provideAllocator, 0); |
207 | lua_call(from, 0, 1); | 206 | lua_call(from, 0, 1); |
208 | AllocatorDefinition* const _def{ lua_tofulluserdata<AllocatorDefinition>(from, -1) }; | 207 | AllocatorDefinition* const _def{ luaG_tofulluserdata<AllocatorDefinition>(from, -1) }; |
209 | lua_State* const _L{ lua_newstate(_def->allocF, _def->allocUD) }; | 208 | lua_State* const _L{ lua_newstate(_def->allocF, _def->allocUD) }; |
210 | lua_pop(from, 1); | 209 | lua_pop(from, 1); |
211 | return _L; | 210 | return _L; |
@@ -353,7 +352,7 @@ namespace state { | |||
353 | 352 | ||
354 | STACK_CHECK(_L, 0); | 353 | STACK_CHECK(_L, 0); |
355 | // after all this, register everything we find in our name<->function database | 354 | // after all this, register everything we find in our name<->function database |
356 | lua_pushglobaltable(_L); // L: _G | 355 | luaG_pushglobaltable(_L); // L: _G |
357 | tools::PopulateFuncLookupTable(_L, -1, {}); | 356 | tools::PopulateFuncLookupTable(_L, -1, {}); |
358 | lua_pop(_L, 1); // L: | 357 | lua_pop(_L, 1); // L: |
359 | STACK_CHECK(_L, 0); | 358 | STACK_CHECK(_L, 0); |
@@ -365,19 +364,19 @@ namespace state { | |||
365 | kLookupRegKey.pushValue(_L); // L: {} | 364 | kLookupRegKey.pushValue(_L); // L: {} |
366 | lua_pushnil(_L); // L: {} nil | 365 | lua_pushnil(_L); // L: {} nil |
367 | while (lua_next(_L, -2)) { // L: {} k v | 366 | while (lua_next(_L, -2)) { // L: {} k v |
368 | std::ignore = lua_pushstringview(_L, "["); // L: {} k v "[" | 367 | std::ignore = luaG_pushstring(_L, "["); // L: {} k v "[" |
369 | 368 | ||
370 | lua_getglobal(_L, "tostring"); // L: {} k v "[" tostring | 369 | lua_getglobal(_L, "tostring"); // L: {} k v "[" tostring |
371 | lua_pushvalue(_L, -4); // L: {} k v "[" tostring k | 370 | lua_pushvalue(_L, -4); // L: {} k v "[" tostring k |
372 | lua_call(_L, 1, 1); // L: {} k v "[" 'k' | 371 | lua_call(_L, 1, 1); // L: {} k v "[" 'k' |
373 | 372 | ||
374 | std::ignore = lua_pushstringview(_L, "] = "); // L: {} k v "[" 'k' "] = " | 373 | std::ignore = luaG_pushstring(_L, "] = "); // L: {} k v "[" 'k' "] = " |
375 | 374 | ||
376 | lua_getglobal(_L, "tostring"); // L: {} k v "[" 'k' "] = " tostring | 375 | lua_getglobal(_L, "tostring"); // L: {} k v "[" 'k' "] = " tostring |
377 | lua_pushvalue(_L, -5); // L: {} k v "[" 'k' "] = " tostring v | 376 | lua_pushvalue(_L, -5); // L: {} k v "[" 'k' "] = " tostring v |
378 | lua_call(_L, 1, 1); // L: {} k v "[" 'k' "] = " 'v' | 377 | lua_call(_L, 1, 1); // L: {} k v "[" 'k' "] = " 'v' |
379 | lua_concat(_L, 4); // L: {} k v "[k] = v" | 378 | lua_concat(_L, 4); // L: {} k v "[k] = v" |
380 | DEBUGSPEW_CODE(DebugSpew(U_) << lua_tostringview(_L, -1) << std::endl); | 379 | DEBUGSPEW_CODE(DebugSpew(U_) << luaG_tostring(_L, -1) << std::endl); |
381 | lua_pop(_L, 2); // L: {} k | 380 | lua_pop(_L, 2); // L: {} k |
382 | } // lua_next() // L: {} | 381 | } // lua_next() // L: {} |
383 | lua_pop(_L, 1); // L: | 382 | lua_pop(_L, 1); // L: |