diff options
Diffstat (limited to 'src/tools.cpp')
-rw-r--r-- | src/tools.cpp | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/tools.cpp b/src/tools.cpp index f4fbf46..c4ce24f 100644 --- a/src/tools.cpp +++ b/src/tools.cpp | |||
@@ -648,14 +648,14 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull }; | |||
648 | lua_getglobal(L2, "decoda_name"); // L1: ... t ... L2: {} t decoda_name | 648 | lua_getglobal(L2, "decoda_name"); // L1: ... t ... L2: {} t decoda_name |
649 | to = lua_tostring(L2, -1); | 649 | to = lua_tostring(L2, -1); |
650 | lua_pop(L2, 1); // L1: ... t ... L2: {} t | 650 | lua_pop(L2, 1); // L1: ... t ... L2: {} t |
651 | // when mode_ == LookupMode::FromKeeper, L is a keeper state and L2 is not, therefore L2 is the state where we want to raise the error | 651 | // when mode_ == LookupMode::FromKeeper, L1 is a keeper state and L2 is not, therefore L2 is the state where we want to raise the error |
652 | raise_luaL_error( | 652 | raise_luaL_error( |
653 | (mode == LookupMode::FromKeeper) ? L2 : L1, | 653 | (mode == LookupMode::FromKeeper) ? L2 : L1, |
654 | "INTERNAL ERROR IN %s: table '%s' not found in %s destination transfer database.", | 654 | "INTERNAL ERROR IN %s: table '%s' not found in %s destination transfer database.", |
655 | from ? from : "main", | 655 | from ? from : "main", |
656 | fqn, | 656 | fqn, |
657 | to ? to : "main"); | 657 | to ? to : "main" |
658 | return false; | 658 | ); |
659 | } | 659 | } |
660 | lua_remove(L2, -2); // L1: ... t ... L2: t | 660 | lua_remove(L2, -2); // L1: ... t ... L2: t |
661 | break; | 661 | break; |
@@ -1025,7 +1025,7 @@ void InterCopyContext::copy_func() const | |||
1025 | 1025 | ||
1026 | // transfer the bytecode, then the upvalues, to create a similar closure | 1026 | // transfer the bytecode, then the upvalues, to create a similar closure |
1027 | { | 1027 | { |
1028 | char const* name = nullptr; | 1028 | char const* fname = nullptr; |
1029 | #define LOG_FUNC_INFO 0 | 1029 | #define LOG_FUNC_INFO 0 |
1030 | #if LOG_FUNC_INFO | 1030 | #if LOG_FUNC_INFO |
1031 | // "To get information about a function you push it onto the | 1031 | // "To get information about a function you push it onto the |
@@ -1034,9 +1034,9 @@ void InterCopyContext::copy_func() const | |||
1034 | { | 1034 | { |
1035 | lua_Debug ar; | 1035 | lua_Debug ar; |
1036 | lua_pushvalue(L1, L1_i); // L1: ... b f | 1036 | lua_pushvalue(L1, L1_i); // L1: ... b f |
1037 | // fills 'name' 'namewhat' and 'linedefined', pops function | 1037 | // fills 'fname' 'namewhat' and 'linedefined', pops function |
1038 | lua_getinfo(L1, ">nS", &ar); // L1: ... b | 1038 | lua_getinfo(L1, ">nS", &ar); // L1: ... b |
1039 | name = ar.namewhat; | 1039 | fname = ar.namewhat; |
1040 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "FNAME: %s @ %d" INDENT_END(U), ar.short_src, ar.linedefined)); // just gives nullptr | 1040 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "FNAME: %s @ %d" INDENT_END(U), ar.short_src, ar.linedefined)); // just gives nullptr |
1041 | } | 1041 | } |
1042 | #endif // LOG_FUNC_INFO | 1042 | #endif // LOG_FUNC_INFO |
@@ -1046,17 +1046,17 @@ void InterCopyContext::copy_func() const | |||
1046 | LUA_ASSERT(L1, s && sz); | 1046 | LUA_ASSERT(L1, s && sz); |
1047 | STACK_GROW(L2, 2); | 1047 | STACK_GROW(L2, 2); |
1048 | // Note: Line numbers seem to be taken precisely from the | 1048 | // Note: Line numbers seem to be taken precisely from the |
1049 | // original function. 'name' is not used since the chunk | 1049 | // original function. 'fname' is not used since the chunk |
1050 | // is precompiled (it seems...). | 1050 | // is precompiled (it seems...). |
1051 | // | 1051 | // |
1052 | // TBD: Can we get the function's original name through, as well? | 1052 | // TBD: Can we get the function's original name through, as well? |
1053 | // | 1053 | // |
1054 | if (luaL_loadbuffer(L2, s, sz, name) != 0) { // L2: ... {cache} ... p function | 1054 | if (luaL_loadbuffer(L2, s, sz, fname) != 0) { // L2: ... {cache} ... p function |
1055 | // chunk is precompiled so only LUA_ERRMEM can happen | 1055 | // chunk is precompiled so only LUA_ERRMEM can happen |
1056 | // "Otherwise, it pushes an error message" | 1056 | // "Otherwise, it pushes an error message" |
1057 | // | 1057 | // |
1058 | STACK_GROW(L1, 1); | 1058 | STACK_GROW(L1, 1); |
1059 | raise_luaL_error(L1, "%s: %s", name, lua_tostring(L2, -1)); | 1059 | raise_luaL_error(L1, "%s: %s", fname, lua_tostring(L2, -1)); |
1060 | } | 1060 | } |
1061 | // remove the dumped string | 1061 | // remove the dumped string |
1062 | lua_pop(L1, 1); // ... | 1062 | lua_pop(L1, 1); // ... |
@@ -1285,8 +1285,8 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
1285 | 1285 | ||
1286 | [[nodiscard]] bool InterCopyContext::tryCopyClonable() const | 1286 | [[nodiscard]] bool InterCopyContext::tryCopyClonable() const |
1287 | { | 1287 | { |
1288 | SourceIndex const L1_i{ lua_absindex(L1, this->L1_i) }; | 1288 | SourceIndex const L1i{ lua_absindex(L1, L1_i) }; |
1289 | void* const source{ lua_touserdata(L1, L1_i) }; | 1289 | void* const source{ lua_touserdata(L1, L1i) }; |
1290 | 1290 | ||
1291 | STACK_CHECK_START_REL(L1, 0); | 1291 | STACK_CHECK_START_REL(L1, 0); |
1292 | STACK_CHECK_START_REL(L2, 0); | 1292 | STACK_CHECK_START_REL(L2, 0); |
@@ -1303,7 +1303,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
1303 | STACK_CHECK(L2, 0); | 1303 | STACK_CHECK(L2, 0); |
1304 | 1304 | ||
1305 | // no metatable? -> not clonable | 1305 | // no metatable? -> not clonable |
1306 | if (!lua_getmetatable(L1, L1_i)) { // L1: ... mt? | 1306 | if (!lua_getmetatable(L1, L1i)) { // L1: ... mt? |
1307 | STACK_CHECK(L1, 0); | 1307 | STACK_CHECK(L1, 0); |
1308 | return false; | 1308 | return false; |
1309 | } | 1309 | } |
@@ -1319,10 +1319,10 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
1319 | // we need to copy over the uservalues of the userdata as well | 1319 | // we need to copy over the uservalues of the userdata as well |
1320 | { | 1320 | { |
1321 | int const mt{ lua_absindex(L1, -2) }; // L1: ... mt __lanesclone | 1321 | int const mt{ lua_absindex(L1, -2) }; // L1: ... mt __lanesclone |
1322 | size_t const userdata_size{ lua_rawlen(L1, L1_i) }; | 1322 | size_t const userdata_size{ lua_rawlen(L1, L1i) }; |
1323 | // extract all the uservalues, but don't transfer them yet | 1323 | // extract all the uservalues, but don't transfer them yet |
1324 | int uvi = 0; | 1324 | int uvi = 0; |
1325 | while (lua_getiuservalue(L1, L1_i, ++uvi) != LUA_TNONE) {} // L1: ... mt __lanesclone [uv]+ nil | 1325 | while (lua_getiuservalue(L1, L1i, ++uvi) != LUA_TNONE) {} // L1: ... mt __lanesclone [uv]+ nil |
1326 | // when lua_getiuservalue() returned LUA_TNONE, it pushed a nil. pop it now | 1326 | // when lua_getiuservalue() returned LUA_TNONE, it pushed a nil. pop it now |
1327 | lua_pop(L1, 1); // L1: ... mt __lanesclone [uv]+ | 1327 | lua_pop(L1, 1); // L1: ... mt __lanesclone [uv]+ |
1328 | --uvi; | 1328 | --uvi; |
@@ -1811,7 +1811,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
1811 | DEBUGSPEW_CODE(DebugSpewIndentScope m_scope); | 1811 | DEBUGSPEW_CODE(DebugSpewIndentScope m_scope); |
1812 | 1812 | ||
1813 | public: | 1813 | public: |
1814 | OnExit(Universe* U_, lua_State* L2_) | 1814 | OnExit(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L2_) |
1815 | : L2{ L2_ } | 1815 | : L2{ L2_ } |
1816 | , top_L2{ lua_gettop(L2) } DEBUGSPEW_COMMA_PARAM(m_scope{ U_ }) | 1816 | , top_L2{ lua_gettop(L2) } DEBUGSPEW_COMMA_PARAM(m_scope{ U_ }) |
1817 | { | 1817 | { |
@@ -1821,7 +1821,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
1821 | { | 1821 | { |
1822 | lua_settop(L2, top_L2); | 1822 | lua_settop(L2, top_L2); |
1823 | } | 1823 | } |
1824 | } onExit{ U, L2 }; | 1824 | } onExit{ DEBUGSPEW_PARAM_COMMA(U) L2 }; |
1825 | 1825 | ||
1826 | STACK_CHECK_START_REL(L1, 0); | 1826 | STACK_CHECK_START_REL(L1, 0); |
1827 | if (lua_type_as_enum(L1, L1_i) != LuaType::TABLE) { | 1827 | if (lua_type_as_enum(L1, L1_i) != LuaType::TABLE) { |