aboutsummaryrefslogtreecommitdiff
path: root/src/state.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/state.cpp')
-rw-r--r--src/state.cpp45
1 files changed, 28 insertions, 17 deletions
diff --git a/src/state.cpp b/src/state.cpp
index 73c94f0..68569bd 100644
--- a/src/state.cpp
+++ b/src/state.cpp
@@ -39,6 +39,8 @@ THE SOFTWARE.
39#include "tools.h" 39#include "tools.h"
40#include "universe.h" 40#include "universe.h"
41 41
42#include <source_location>
43
42// ################################################################################################# 44// #################################################################################################
43 45
44/*---=== Serialize require ===--- 46/*---=== Serialize require ===---
@@ -402,27 +404,36 @@ lua_State* luaG_newstate(Universe* U_, SourceState from_, char const* libs_)
402 404
403 STACK_CHECK(_L, 0); 405 STACK_CHECK(_L, 0);
404 // after all this, register everything we find in our name<->function database 406 // after all this, register everything we find in our name<->function database
405 lua_pushglobaltable(_L); // Lua 5.2 no longer has LUA_GLOBALSINDEX: we must push globals table on the stack 407 lua_pushglobaltable(_L); // L: _G
406 STACK_CHECK(_L, 1);
407 populate_func_lookup_table(_L, -1, {}); 408 populate_func_lookup_table(_L, -1, {});
409 lua_pop(_L, 1); // L:
410 STACK_CHECK(_L, 0);
408 411
409#if 1 && USE_DEBUG_SPEW() 412 if constexpr (USE_DEBUG_SPEW()) {
410 // dump the lookup database contents 413 DEBUGSPEW_CODE(DebugSpew(U_) << std::source_location::current().function_name() << " LOOKUP DB CONTENTS" << std::endl);
411 kLookupRegKey.pushValue(_L); // L: {} 414 DEBUGSPEW_CODE(DebugSpewIndentScope _scope2{ U_ });
412 lua_pushnil(_L); // L: {} nil 415 // dump the lookup database contents
413 while (lua_next(_L, -2)) { // L: {} k v 416 kLookupRegKey.pushValue(_L); // L: {}
414 lua_getglobal(_L, "print"); // L: {} k v print 417 lua_pushnil(_L); // L: {} nil
415 int const indent{ U_->debugspewIndentDepth.load(std::memory_order_relaxed) }; 418 while (lua_next(_L, -2)) { // L: {} k v
416 lua_pushlstring(_L, DebugSpewIndentScope::debugspew_indent, indent); // L: {} k v print " " 419 std::ignore = lua_pushstringview(_L, "["); // L: {} k v "["
417 lua_pushvalue(_L, -4); // L: {} k v print " " k 420
418 lua_pushvalue(_L, -4); // L: {} k v print " " k v 421 lua_getglobal(_L, "tostring"); // L: {} k v "[" tostring
419 lua_call(_L, 3, 0); // L: {} k v 422 lua_pushvalue(_L, -4); // L: {} k v "[" tostring k
420 lua_pop(_L, 1); // L: {} k 423 lua_call(_L, 1, 1); // L: {} k v "[" 'k'
424
425 std::ignore = lua_pushstringview(_L, "] = "); // L: {} k v "[" 'k' "] = "
426
427 lua_getglobal(_L, "tostring"); // L: {} k v "[" 'k' "] = " tostring
428 lua_pushvalue(_L, -5); // L: {} k v "[" 'k' "] = " tostring v
429 lua_call(_L, 1, 1); // L: {} k v "[" 'k' "] = " 'v'
430 lua_concat(_L, 4); // L: {} k v "[k] = v"
431 DEBUGSPEW_CODE(DebugSpew(U_) << lua_tostringview(_L, -1) << std::endl);
432 lua_pop(_L, 2); // L: {} k
433 } // lua_next() // L: {}
434 lua_pop(_L, 1); // L:
421 } 435 }
422 lua_pop(_L, 1); // L: {}
423#endif // USE_DEBUG_SPEW()
424 436
425 lua_pop(_L, 1);
426 STACK_CHECK(_L, 0); 437 STACK_CHECK(_L, 0);
427 return _L; 438 return _L;
428} 439}