diff options
Diffstat (limited to 'src/state.cpp')
-rw-r--r-- | src/state.cpp | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/src/state.cpp b/src/state.cpp index 4a5f995..1ba5a77 100644 --- a/src/state.cpp +++ b/src/state.cpp | |||
@@ -191,26 +191,27 @@ static void open1lib(DEBUGSPEW_PARAM_COMMA(Universe* U) lua_State* L, char const | |||
191 | // ################################################################################################# | 191 | // ################################################################################################# |
192 | 192 | ||
193 | // just like lua_xmove, args are (from, to) | 193 | // just like lua_xmove, args are (from, to) |
194 | static void copy_one_time_settings(Universe* U, Source L, Dest L2) | 194 | static void copy_one_time_settings(Universe* U, Source L1, Dest L2) |
195 | { | 195 | { |
196 | STACK_GROW(L, 2); | 196 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); |
197 | STACK_CHECK_START_REL(L, 0); | 197 | |
198 | STACK_GROW(L1, 2); | ||
199 | STACK_CHECK_START_REL(L1, 0); | ||
198 | STACK_CHECK_START_REL(L2, 0); | 200 | STACK_CHECK_START_REL(L2, 0); |
199 | 201 | ||
200 | DEBUGSPEW_CODE(fprintf( stderr, INDENT_BEGIN "copy_one_time_settings()\n" INDENT_END)); | 202 | DEBUGSPEW_CODE(fprintf( stderr, INDENT_BEGIN "copy_one_time_settings()\n" INDENT_END)); |
201 | DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_add(1, std::memory_order_relaxed)); | ||
202 | 203 | ||
203 | CONFIG_REGKEY.pushValue(L); // config | 204 | CONFIG_REGKEY.pushValue(L1); // config |
204 | // copy settings from from source to destination registry | 205 | // copy settings from from source to destination registry |
205 | if (luaG_inter_move(U, L, L2, 1, LookupMode::LaneBody) != InterCopyResult::Success) // // config | 206 | InterCopyContext c{ U, L2, L1, {}, {}, {}, {}, {} }; |
207 | if (c.inter_move(1) != InterCopyResult::Success) // // config | ||
206 | { | 208 | { |
207 | luaL_error( L, "failed to copy settings when loading lanes.core"); // doesn't return | 209 | luaL_error(L1, "failed to copy settings when loading lanes.core"); // doesn't return |
208 | } | 210 | } |
209 | // set L2:_R[CONFIG_REGKEY] = settings | 211 | // set L2:_R[CONFIG_REGKEY] = settings |
210 | CONFIG_REGKEY.setValue(L2, [](lua_State* L) { lua_insert(L, -2); }); // config | 212 | CONFIG_REGKEY.setValue(L2, [](lua_State* L) { lua_insert(L, -2); }); // config |
211 | STACK_CHECK(L2, 0); | 213 | STACK_CHECK(L2, 0); |
212 | STACK_CHECK(L, 0); | 214 | STACK_CHECK(L1, 0); |
213 | DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_sub(1, std::memory_order_relaxed)); | ||
214 | } | 215 | } |
215 | 216 | ||
216 | // ################################################################################################# | 217 | // ################################################################################################# |
@@ -355,7 +356,7 @@ lua_State* luaG_newstate(Universe* U, Source from_, char const* libs_) | |||
355 | } | 356 | } |
356 | 357 | ||
357 | DEBUGSPEW_CODE(fprintf( stderr, INDENT_BEGIN "luaG_newstate()\n" INDENT_END)); | 358 | DEBUGSPEW_CODE(fprintf( stderr, INDENT_BEGIN "luaG_newstate()\n" INDENT_END)); |
358 | DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_add(1, std::memory_order_relaxed)); | 359 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); |
359 | 360 | ||
360 | // copy settings (for example because it may contain a Lua on_state_create function) | 361 | // copy settings (for example because it may contain a Lua on_state_create function) |
361 | copy_one_time_settings( U, from_, L); | 362 | copy_one_time_settings( U, from_, L); |
@@ -426,24 +427,23 @@ lua_State* luaG_newstate(Universe* U, Source from_, char const* libs_) | |||
426 | STACK_CHECK(L, 1); | 427 | STACK_CHECK(L, 1); |
427 | populate_func_lookup_table(L, -1, nullptr); | 428 | populate_func_lookup_table(L, -1, nullptr); |
428 | 429 | ||
429 | #if 0 && USE_DEBUG_SPEW() | 430 | #if 1 && USE_DEBUG_SPEW() |
430 | // dump the lookup database contents | 431 | // dump the lookup database contents |
431 | lua_getfield(L, LUA_REGISTRYINDEX, LOOKUP_REGKEY); // {} | 432 | LOOKUP_REGKEY.pushValue(L); // {} |
432 | lua_pushnil(L); // {} nil | 433 | lua_pushnil(L); // {} nil |
433 | while (lua_next(L, -2)) // {} k v | 434 | while (lua_next(L, -2)) // {} k v |
434 | { | 435 | { |
435 | lua_getglobal(L, "print"); // {} k v print | 436 | lua_getglobal(L, "print"); // {} k v print |
436 | lua_pushlstring(L, debugspew_indent, U->debugspew_indent_depth.load(std::memory_order_relaxed)); // {} k v print " " | 437 | lua_pushlstring(L, DebugSpewIndentScope::debugspew_indent, U->debugspew_indent_depth.load(std::memory_order_relaxed)); // {} k v print " " |
437 | lua_pushvalue(L, -4); // {} k v print " " k | 438 | lua_pushvalue(L, -4); // {} k v print " " k |
438 | lua_pushvalue(L, -4); // {} k v print " " k v | 439 | lua_pushvalue(L, -4); // {} k v print " " k v |
439 | lua_call(L, 3, 0); // {} k v | 440 | lua_call(L, 3, 0); // {} k v |
440 | lua_pop(L, 1); // {} k | 441 | lua_pop(L, 1); // {} k |
441 | } | 442 | } |
442 | lua_pop(L, 1); // {} | 443 | lua_pop(L, 1); // {} |
443 | #endif // USE_DEBUG_SPEW() | 444 | #endif // USE_DEBUG_SPEW() |
444 | 445 | ||
445 | lua_pop(L, 1); | 446 | lua_pop(L, 1); |
446 | STACK_CHECK(L, 0); | 447 | STACK_CHECK(L, 0); |
447 | DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_sub(1, std::memory_order_relaxed)); | ||
448 | return L; | 448 | return L; |
449 | } | 449 | } |