diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-05-22 18:15:13 +0200 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-05-22 18:15:13 +0200 |
| commit | d468b693d79ddb416c45669e5ca8400cbdc34e85 (patch) | |
| tree | e31876c81dae1e3f8359c129f348ed3511342470 /src/intercopycontext.cpp | |
| parent | 9617dd452e529af3a12b14a98cd2edbfd93ea712 (diff) | |
| download | lanes-d468b693d79ddb416c45669e5ca8400cbdc34e85.tar.gz lanes-d468b693d79ddb416c45669e5ca8400cbdc34e85.tar.bz2 lanes-d468b693d79ddb416c45669e5ca8400cbdc34e85.zip | |
DEBUGSPEW fprintf(stderr) → std::cerr
Diffstat (limited to '')
| -rw-r--r-- | src/intercopycontext.cpp | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index 6ebbbb0..6623b16 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp | |||
| @@ -98,8 +98,7 @@ THE SOFTWARE. | |||
| 98 | lua_rawget(L1, -2); // L1: ... v ... {} "f.q.n" | 98 | lua_rawget(L1, -2); // L1: ... v ... {} "f.q.n" |
| 99 | } | 99 | } |
| 100 | std::string_view _fqn{ lua_tostringview(L1, -1) }; | 100 | std::string_view _fqn{ lua_tostringview(L1, -1) }; |
| 101 | DEBUGSPEW_CODE(Universe* const _U = universe_get(L1)); | 101 | DEBUGSPEW_CODE(DebugSpew(universe_get(L1)) << "function [C] " << _fqn << std::endl); |
| 102 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "function [C] %s \n" INDENT_END(_U), _fqn.data())); | ||
| 103 | // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database | 102 | // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database |
| 104 | lua_pop(L1, (mode == LookupMode::FromKeeper) ? 1 : 2); // L1: ... v ... | 103 | lua_pop(L1, (mode == LookupMode::FromKeeper) ? 1 : 2); // L1: ... v ... |
| 105 | STACK_CHECK(L1, 0); | 104 | STACK_CHECK(L1, 0); |
| @@ -220,7 +219,7 @@ void InterCopyContext::copy_func() const | |||
| 220 | // fills 'fname' 'namewhat' and 'linedefined', pops function | 219 | // fills 'fname' 'namewhat' and 'linedefined', pops function |
| 221 | lua_getinfo(L1, ">nS", &_ar); // L1: ... b | 220 | lua_getinfo(L1, ">nS", &_ar); // L1: ... b |
| 222 | _fname = _ar.namewhat; | 221 | _fname = _ar.namewhat; |
| 223 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "FNAME: %s @ %d" INDENT_END(U), _ar.short_src, _ar.linedefined)); // just gives nullptr | 222 | DEBUGSPEW_CODE(DebugSpew(U) << "FNAME: " << _ar.short_src << " @ " << _ar.linedefined << std::endl); |
| 224 | } | 223 | } |
| 225 | #endif // LOG_FUNC_INFO | 224 | #endif // LOG_FUNC_INFO |
| 226 | { | 225 | { |
| @@ -267,15 +266,15 @@ void InterCopyContext::copy_func() const | |||
| 267 | lua_pushglobaltable(L1); // L1: ... _G | 266 | lua_pushglobaltable(L1); // L1: ... _G |
| 268 | #endif // LUA_VERSION_NUM | 267 | #endif // LUA_VERSION_NUM |
| 269 | for (_n = 0; (_c.name = lua_getupvalue(L1, L1_i, 1 + _n)) != nullptr; ++_n) { // L1: ... _G up[n] | 268 | for (_n = 0; (_c.name = lua_getupvalue(L1, L1_i, 1 + _n)) != nullptr; ++_n) { // L1: ... _G up[n] |
| 270 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "UPNAME[%d]: %s -> " INDENT_END(U), _n, _c.name)); | 269 | DEBUGSPEW_CODE(DebugSpew(U) << "UPNAME[" << _n << "]: " << _c.name << " -> "); |
| 271 | #if LUA_VERSION_NUM >= 502 | 270 | #if LUA_VERSION_NUM >= 502 |
| 272 | if (lua_rawequal(L1, -1, -2)) { // is the upvalue equal to the global table? | 271 | if (lua_rawequal(L1, -1, -2)) { // is the upvalue equal to the global table? |
| 273 | DEBUGSPEW_CODE(fprintf(stderr, "pushing destination global scope\n")); | 272 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "pushing destination global scope" << std::endl); |
| 274 | lua_pushglobaltable(L2); // L2: ... {cache} ... function <upvalues> | 273 | lua_pushglobaltable(L2); // L2: ... {cache} ... function <upvalues> |
| 275 | } else | 274 | } else |
| 276 | #endif // LUA_VERSION_NUM | 275 | #endif // LUA_VERSION_NUM |
| 277 | { | 276 | { |
| 278 | DEBUGSPEW_CODE(fprintf(stderr, "copying value\n")); | 277 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "copying value" << std::endl); |
| 279 | _c.L1_i = SourceIndex{ lua_gettop(L1) }; | 278 | _c.L1_i = SourceIndex{ lua_gettop(L1) }; |
| 280 | if (!_c.inter_copy_one()) { // L2: ... {cache} ... function <upvalues> | 279 | if (!_c.inter_copy_one()) { // L2: ... {cache} ... function <upvalues> |
| 281 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); | 280 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); |
| @@ -323,7 +322,7 @@ void InterCopyContext::lookup_native_func() const | |||
| 323 | 322 | ||
| 324 | case LookupMode::ToKeeper: | 323 | case LookupMode::ToKeeper: |
| 325 | // push a sentinel closure that holds the lookup name as upvalue | 324 | // push a sentinel closure that holds the lookup name as upvalue |
| 326 | lua_pushlstring(L2, _fqn.data(), _fqn.size()); // L1: ... f ... L2: "f.q.n" | 325 | std::ignore = lua_pushstringview(L2, _fqn); // L1: ... f ... L2: "f.q.n" |
| 327 | lua_pushcclosure(L2, func_lookup_sentinel, 1); // L1: ... f ... L2: f | 326 | lua_pushcclosure(L2, func_lookup_sentinel, 1); // L1: ... f ... L2: f |
| 328 | break; | 327 | break; |
| 329 | 328 | ||
| @@ -332,7 +331,7 @@ void InterCopyContext::lookup_native_func() const | |||
| 332 | kLookupRegKey.pushValue(L2); // L1: ... f ... L2: {} | 331 | kLookupRegKey.pushValue(L2); // L1: ... f ... L2: {} |
| 333 | STACK_CHECK(L2, 1); | 332 | STACK_CHECK(L2, 1); |
| 334 | LUA_ASSERT(L1, lua_istable(L2, -1)); | 333 | LUA_ASSERT(L1, lua_istable(L2, -1)); |
| 335 | lua_pushlstring(L2, _fqn.data(), _fqn.size()); // L1: ... f ... L2: {} "f.q.n" | 334 | std::ignore = lua_pushstringview(L2, _fqn); // L1: ... f ... L2: {} "f.q.n" |
| 336 | lua_rawget(L2, -2); // L1: ... f ... L2: {} f | 335 | lua_rawget(L2, -2); // L1: ... f ... L2: {} f |
| 337 | // nil means we don't know how to transfer stuff: user should do something | 336 | // nil means we don't know how to transfer stuff: user should do something |
| 338 | // anything other than function or table should not happen! | 337 | // anything other than function or table should not happen! |
| @@ -342,14 +341,14 @@ void InterCopyContext::lookup_native_func() const | |||
| 342 | lua_pop(L1, 1); // L1: ... f ... | 341 | lua_pop(L1, 1); // L1: ... f ... |
| 343 | lua_getglobal(L2, "decoda_name"); // L1: ... f ... L2: {} f decoda_name | 342 | lua_getglobal(L2, "decoda_name"); // L1: ... f ... L2: {} f decoda_name |
| 344 | char const* const _to{ lua_tostring(L2, -1) }; | 343 | char const* const _to{ lua_tostring(L2, -1) }; |
| 345 | lua_pop(L2, 1); // L2: {} f | 344 | lua_pop(L2, 1); // L2: {} f |
| 346 | // 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 | 345 | // 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 |
| 347 | raise_luaL_error( | 346 | raise_luaL_error( |
| 348 | getErrL(), | 347 | getErrL(), |
| 349 | "%s%s: function '%s' not found in %s destination transfer database.", | 348 | "%s%s: function '" STRINGVIEW_FMT "' not found in %s destination transfer database.", |
| 350 | lua_isnil(L2, -1) ? "" : "INTERNAL ERROR IN ", | 349 | lua_isnil(L2, -1) ? "" : "INTERNAL ERROR IN ", |
| 351 | _from ? _from : "main", | 350 | _from ? _from : "main", |
| 352 | _fqn.data(), | 351 | _fqn.size(), _fqn.data(), |
| 353 | _to ? _to : "main"); | 352 | _to ? _to : "main"); |
| 354 | return; | 353 | return; |
| 355 | } | 354 | } |
| @@ -398,7 +397,7 @@ void InterCopyContext::copy_cached_func() const | |||
| 398 | // push a light userdata uniquely representing the function | 397 | // push a light userdata uniquely representing the function |
| 399 | lua_pushlightuserdata(L2, _aspointer); // L2: ... {cache} ... p | 398 | lua_pushlightuserdata(L2, _aspointer); // L2: ... {cache} ... p |
| 400 | 399 | ||
| 401 | // fprintf( stderr, "<< ID: %s >>\n", lua_tostring( L2, -1)); | 400 | //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << lua_tostringview(L2, -1) << " >>" << std::endl); |
| 402 | 401 | ||
| 403 | lua_pushvalue(L2, -1); // L2: ... {cache} ... p p | 402 | lua_pushvalue(L2, -1); // L2: ... {cache} ... p p |
| 404 | lua_rawget(L2, L2_cache_i); // L2: ... {cache} ... p function|nil|true | 403 | lua_rawget(L2, L2_cache_i); // L2: ... {cache} ... p function|nil|true |
| @@ -443,7 +442,7 @@ void InterCopyContext::copy_cached_func() const | |||
| 443 | 442 | ||
| 444 | case LookupMode::ToKeeper: | 443 | case LookupMode::ToKeeper: |
| 445 | // push a sentinel closure that holds the lookup name as upvalue | 444 | // push a sentinel closure that holds the lookup name as upvalue |
| 446 | lua_pushlstring(L2, _fqn.data(), _fqn.size()); // L1: ... t ... L2: "f.q.n" | 445 | std::ignore = lua_pushstringview(L2, _fqn); // L1: ... t ... L2: "f.q.n" |
| 447 | lua_pushcclosure(L2, table_lookup_sentinel, 1); // L1: ... t ... L2: f | 446 | lua_pushcclosure(L2, table_lookup_sentinel, 1); // L1: ... t ... L2: f |
| 448 | break; | 447 | break; |
| 449 | 448 | ||
| @@ -452,7 +451,7 @@ void InterCopyContext::copy_cached_func() const | |||
| 452 | kLookupRegKey.pushValue(L2); // L1: ... t ... L2: {} | 451 | kLookupRegKey.pushValue(L2); // L1: ... t ... L2: {} |
| 453 | STACK_CHECK(L2, 1); | 452 | STACK_CHECK(L2, 1); |
| 454 | LUA_ASSERT(L1, lua_istable(L2, -1)); | 453 | LUA_ASSERT(L1, lua_istable(L2, -1)); |
| 455 | lua_pushlstring(L2, _fqn.data(), _fqn.size()); // L2: {} "f.q.n" | 454 | std::ignore = lua_pushstringview(L2, _fqn); // L2: {} "f.q.n" |
| 456 | lua_rawget(L2, -2); // L2: {} t | 455 | lua_rawget(L2, -2); // L2: {} t |
| 457 | // we accept destination lookup failures in the case of transfering the Lanes body function (this will result in the source table being cloned instead) | 456 | // we accept destination lookup failures in the case of transfering the Lanes body function (this will result in the source table being cloned instead) |
| 458 | // but not when we extract something out of a keeper, as there is nothing to clone! | 457 | // but not when we extract something out of a keeper, as there is nothing to clone! |
| @@ -505,7 +504,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
| 505 | std::string_view const _key{ lua_tostringview(L1, _key_i) }; | 504 | std::string_view const _key{ lua_tostringview(L1, _key_i) }; |
| 506 | size_t const _bufLen{ strlen(name) + _key.size() + 2 }; // +2 for separator dot and terminating 0 | 505 | size_t const _bufLen{ strlen(name) + _key.size() + 2 }; // +2 for separator dot and terminating 0 |
| 507 | _valPath = static_cast<char*>(alloca(_bufLen)); | 506 | _valPath = static_cast<char*>(alloca(_bufLen)); |
| 508 | sprintf(_valPath, "%s.%*s", name, static_cast<int>(_key.size()), _key.data()); | 507 | sprintf(_valPath, "%s." STRINGVIEW_FMT, name, (int) _key.size(), _key.data()); |
| 509 | } | 508 | } |
| 510 | #if defined LUA_LNUM || LUA_VERSION_NUM >= 503 | 509 | #if defined LUA_LNUM || LUA_VERSION_NUM >= 503 |
| 511 | else if (lua_isinteger(L1, _key_i)) { | 510 | else if (lua_isinteger(L1, _key_i)) { |
| @@ -607,7 +606,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
| 607 | // push a light userdata uniquely representing the table | 606 | // push a light userdata uniquely representing the table |
| 608 | lua_pushlightuserdata(L2, const_cast<void*>(_p)); // L1: ... t ... L2: ... p | 607 | lua_pushlightuserdata(L2, const_cast<void*>(_p)); // L1: ... t ... L2: ... p |
| 609 | 608 | ||
| 610 | // fprintf(stderr, "<< ID: %s >>\n", lua_tostring(L2, -1)); | 609 | //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << lua_tostringview(L2, -1) << " >>" << std::endl); |
| 611 | 610 | ||
| 612 | lua_rawget(L2, L2_cache_i); // L1: ... t ... L2: ... {cached|nil} | 611 | lua_rawget(L2, L2_cache_i); // L1: ... t ... L2: ... {cached|nil} |
| 613 | bool const _not_found_in_cache{ lua_isnil(L2, -1) }; | 612 | bool const _not_found_in_cache{ lua_isnil(L2, -1) }; |
| @@ -783,7 +782,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
| 783 | [[nodiscard]] bool InterCopyContext::inter_copy_boolean() const | 782 | [[nodiscard]] bool InterCopyContext::inter_copy_boolean() const |
| 784 | { | 783 | { |
| 785 | int const _v{ lua_toboolean(L1, L1_i) }; | 784 | int const _v{ lua_toboolean(L1, L1_i) }; |
| 786 | DEBUGSPEW_CODE(fprintf(stderr, "%s\n", _v ? "true" : "false")); | 785 | DEBUGSPEW_CODE(DebugSpew(nullptr) << (_v ? "true" : "false") << std::endl); |
| 787 | lua_pushboolean(L2, _v); | 786 | lua_pushboolean(L2, _v); |
| 788 | return true; | 787 | return true; |
| 789 | } | 788 | } |
| @@ -798,7 +797,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
| 798 | 797 | ||
| 799 | STACK_CHECK_START_REL(L1, 0); | 798 | STACK_CHECK_START_REL(L1, 0); |
| 800 | STACK_CHECK_START_REL(L2, 0); | 799 | STACK_CHECK_START_REL(L2, 0); |
| 801 | DEBUGSPEW_CODE(fprintf(stderr, "FUNCTION %s\n", name)); | 800 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "FUNCTION " << name << std::endl); |
| 802 | 801 | ||
| 803 | if (lua_tocfunction(L1, L1_i) == userdata_clone_sentinel) { // we are actually copying a clonable full userdata from a keeper | 802 | if (lua_tocfunction(L1, L1_i) == userdata_clone_sentinel) { // we are actually copying a clonable full userdata from a keeper |
| 804 | // clone the full userdata again | 803 | // clone the full userdata again |
| @@ -873,9 +872,9 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
| 873 | // clone:__lanesclone(dest, source, size) | 872 | // clone:__lanesclone(dest, source, size) |
| 874 | lua_call(L2, 3, 0); // L2: ... u | 873 | lua_call(L2, 3, 0); // L2: ... u |
| 875 | } else { // regular function | 874 | } else { // regular function |
| 876 | DEBUGSPEW_CODE(fprintf(stderr, "FUNCTION %s\n", name)); | 875 | DEBUGSPEW_CODE(DebugSpew(U) << "FUNCTION " << name << std::endl); |
| 877 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); | 876 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); |
| 878 | copy_cached_func(); // L2: ... f | 877 | copy_cached_func(); // L2: ... f |
| 879 | } | 878 | } |
| 880 | STACK_CHECK(L2, 1); | 879 | STACK_CHECK(L2, 1); |
| 881 | STACK_CHECK(L1, 0); | 880 | STACK_CHECK(L1, 0); |
| @@ -887,7 +886,8 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
| 887 | [[nodiscard]] bool InterCopyContext::inter_copy_lightuserdata() const | 886 | [[nodiscard]] bool InterCopyContext::inter_copy_lightuserdata() const |
| 888 | { | 887 | { |
| 889 | void* const _p{ lua_touserdata(L1, L1_i) }; | 888 | void* const _p{ lua_touserdata(L1, L1_i) }; |
| 890 | DEBUGSPEW_CODE(fprintf(stderr, "%p\n", _p)); | 889 | // TODO: recognize and print known UniqueKey names here |
| 890 | DEBUGSPEW_CODE(DebugSpew(nullptr) << _p << std::endl); | ||
| 891 | // when copying a nil sentinel in a non-keeper, write a nil in the destination | 891 | // when copying a nil sentinel in a non-keeper, write a nil in the destination |
| 892 | if (mode != LookupMode::ToKeeper && kNilSentinel.equals(L1, L1_i)) { | 892 | if (mode != LookupMode::ToKeeper && kNilSentinel.equals(L1, L1_i)) { |
| 893 | lua_pushnil(L2); | 893 | lua_pushnil(L2); |
| @@ -921,13 +921,13 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
| 921 | #if defined LUA_LNUM || LUA_VERSION_NUM >= 503 | 921 | #if defined LUA_LNUM || LUA_VERSION_NUM >= 503 |
| 922 | if (lua_isinteger(L1, L1_i)) { | 922 | if (lua_isinteger(L1, L1_i)) { |
| 923 | lua_Integer const _v{ lua_tointeger(L1, L1_i) }; | 923 | lua_Integer const _v{ lua_tointeger(L1, L1_i) }; |
| 924 | DEBUGSPEW_CODE(fprintf(stderr, LUA_INTEGER_FMT "\n", _v)); | 924 | DEBUGSPEW_CODE(DebugSpew(nullptr) << _v << std::endl); |
| 925 | lua_pushinteger(L2, _v); | 925 | lua_pushinteger(L2, _v); |
| 926 | } else | 926 | } else |
| 927 | #endif // defined LUA_LNUM || LUA_VERSION_NUM >= 503 | 927 | #endif // defined LUA_LNUM || LUA_VERSION_NUM >= 503 |
| 928 | { | 928 | { |
| 929 | lua_Number const _v{ lua_tonumber(L1, L1_i) }; | 929 | lua_Number const _v{ lua_tonumber(L1, L1_i) }; |
| 930 | DEBUGSPEW_CODE(fprintf(stderr, LUA_NUMBER_FMT "\n", _v)); | 930 | DEBUGSPEW_CODE(DebugSpew(nullptr) << _v << std::endl); |
| 931 | lua_pushnumber(L2, _v); | 931 | lua_pushnumber(L2, _v); |
| 932 | } | 932 | } |
| 933 | return true; | 933 | return true; |
| @@ -938,8 +938,8 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
| 938 | [[nodiscard]] bool InterCopyContext::inter_copy_string() const | 938 | [[nodiscard]] bool InterCopyContext::inter_copy_string() const |
| 939 | { | 939 | { |
| 940 | std::string_view const _s{ lua_tostringview(L1, L1_i) }; | 940 | std::string_view const _s{ lua_tostringview(L1, L1_i) }; |
| 941 | DEBUGSPEW_CODE(fprintf(stderr, "'%s'\n", _s.data())); | 941 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "'" << _s << "'" << std::endl); |
| 942 | lua_pushlstring(L2, _s.data(), _s.size()); | 942 | std::ignore = lua_pushstringview(L2, _s); |
| 943 | return true; | 943 | return true; |
| 944 | } | 944 | } |
| 945 | 945 | ||
| @@ -953,7 +953,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
| 953 | 953 | ||
| 954 | STACK_CHECK_START_REL(L1, 0); | 954 | STACK_CHECK_START_REL(L1, 0); |
| 955 | STACK_CHECK_START_REL(L2, 0); | 955 | STACK_CHECK_START_REL(L2, 0); |
| 956 | DEBUGSPEW_CODE(fprintf(stderr, "TABLE %s\n", name)); | 956 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "TABLE " << name << std::endl); |
| 957 | 957 | ||
| 958 | /* | 958 | /* |
| 959 | * First, let's try to see if this table is special (aka is it some table that we registered in our lookup databases during module registration?) | 959 | * First, let's try to see if this table is special (aka is it some table that we registered in our lookup databases during module registration?) |
| @@ -1021,7 +1021,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
| 1021 | STACK_CHECK(L2, 0); | 1021 | STACK_CHECK(L2, 0); |
| 1022 | 1022 | ||
| 1023 | // Allow only deep userdata entities to be copied across | 1023 | // Allow only deep userdata entities to be copied across |
| 1024 | DEBUGSPEW_CODE(fprintf(stderr, "USERDATA\n")); | 1024 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "USERDATA" << std::endl); |
| 1025 | if (tryCopyDeep()) { | 1025 | if (tryCopyDeep()) { |
| 1026 | STACK_CHECK(L1, 0); | 1026 | STACK_CHECK(L1, 0); |
| 1027 | STACK_CHECK(L2, 1); | 1027 | STACK_CHECK(L2, 1); |
| @@ -1084,18 +1084,18 @@ static char const* vt_names[] = { | |||
| 1084 | STACK_CHECK_START_REL(L1, 0); | 1084 | STACK_CHECK_START_REL(L1, 0); |
| 1085 | STACK_CHECK_START_REL(L2, 0); | 1085 | STACK_CHECK_START_REL(L2, 0); |
| 1086 | 1086 | ||
| 1087 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "inter_copy_one()\n" INDENT_END(U))); | 1087 | DEBUGSPEW_CODE(DebugSpew(U) << "inter_copy_one()" << std::endl); |
| 1088 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); | 1088 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); |
| 1089 | 1089 | ||
| 1090 | LuaType _val_type{ lua_type_as_enum(L1, L1_i) }; | 1090 | LuaType _val_type{ lua_type_as_enum(L1, L1_i) }; |
| 1091 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%s %s: " INDENT_END(U), lua_type_names[static_cast<int>(_val_type)], vt_names[static_cast<int>(vt)])); | 1091 | DEBUGSPEW_CODE(DebugSpew(U) << lua_type_names[static_cast<int>(_val_type)] << " " << vt_names[static_cast<int>(vt)] << ": "); |
| 1092 | 1092 | ||
| 1093 | // Non-POD can be skipped if its metatable contains { __lanesignore = true } | 1093 | // Non-POD can be skipped if its metatable contains { __lanesignore = true } |
| 1094 | if (((1 << static_cast<int>(_val_type)) & kPODmask) == 0) { | 1094 | if (((1 << static_cast<int>(_val_type)) & kPODmask) == 0) { |
| 1095 | if (lua_getmetatable(L1, L1_i)) { // L1: ... mt | 1095 | if (lua_getmetatable(L1, L1_i)) { // L1: ... mt |
| 1096 | LuaType const _type{ luaG_getfield(L1, -1, "__lanesignore") }; // L1: ... mt ignore? | 1096 | LuaType const _type{ luaG_getfield(L1, -1, "__lanesignore") }; // L1: ... mt ignore? |
| 1097 | if (_type == LuaType::BOOLEAN && lua_toboolean(L1, -1)) { | 1097 | if (_type == LuaType::BOOLEAN && lua_toboolean(L1, -1)) { |
| 1098 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "__lanesignore -> LUA_TNIL\n" INDENT_END(U))); | 1098 | DEBUGSPEW_CODE(DebugSpew(U) << "__lanesignore -> LUA_TNIL" << std::endl); |
| 1099 | _val_type = LuaType::NIL; | 1099 | _val_type = LuaType::NIL; |
| 1100 | } | 1100 | } |
| 1101 | lua_pop(L1, 2); // L1: ... | 1101 | lua_pop(L1, 2); // L1: ... |
| @@ -1155,7 +1155,7 @@ static char const* vt_names[] = { | |||
| 1155 | // else raise an error in whichever state is not a keeper | 1155 | // else raise an error in whichever state is not a keeper |
| 1156 | [[nodiscard]] InterCopyResult InterCopyContext::inter_copy_package() const | 1156 | [[nodiscard]] InterCopyResult InterCopyContext::inter_copy_package() const |
| 1157 | { | 1157 | { |
| 1158 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "InterCopyContext::inter_copy_package()\n" INDENT_END(U))); | 1158 | DEBUGSPEW_CODE(DebugSpew(U) << "InterCopyContext::inter_copy_package()" << std::endl); |
| 1159 | 1159 | ||
| 1160 | class OnExit | 1160 | class OnExit |
| 1161 | { | 1161 | { |
| @@ -1189,7 +1189,7 @@ static char const* vt_names[] = { | |||
| 1189 | return InterCopyResult::Error; | 1189 | return InterCopyResult::Error; |
| 1190 | } | 1190 | } |
| 1191 | if (luaG_getmodule(L2, LUA_LOADLIBNAME) == LuaType::NIL) { // package library not loaded: do nothing | 1191 | if (luaG_getmodule(L2, LUA_LOADLIBNAME) == LuaType::NIL) { // package library not loaded: do nothing |
| 1192 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "'package' not loaded, nothing to do\n" INDENT_END(U))); | 1192 | DEBUGSPEW_CODE(DebugSpew(U) << "'package' not loaded, nothing to do" << std::endl); |
| 1193 | STACK_CHECK(L1, 0); | 1193 | STACK_CHECK(L1, 0); |
| 1194 | return InterCopyResult::Success; | 1194 | return InterCopyResult::Success; |
| 1195 | } | 1195 | } |
| @@ -1204,7 +1204,7 @@ static char const* vt_names[] = { | |||
| 1204 | if (!_entry) { | 1204 | if (!_entry) { |
| 1205 | continue; | 1205 | continue; |
| 1206 | } | 1206 | } |
| 1207 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "package.%s\n" INDENT_END(U), _entry)); | 1207 | DEBUGSPEW_CODE(DebugSpew(U) << "package." << _entry << std::endl); |
| 1208 | if (luaG_getfield(L1, L1_i, _entry) == LuaType::NIL) { | 1208 | if (luaG_getfield(L1, L1_i, _entry) == LuaType::NIL) { |
| 1209 | lua_pop(L1, 1); | 1209 | lua_pop(L1, 1); |
| 1210 | } else { | 1210 | } else { |
| @@ -1238,13 +1238,13 @@ static char const* vt_names[] = { | |||
| 1238 | { | 1238 | { |
| 1239 | LUA_ASSERT(L1, vt == VT::NORMAL); | 1239 | LUA_ASSERT(L1, vt == VT::NORMAL); |
| 1240 | 1240 | ||
| 1241 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "InterCopyContext::inter_copy()\n" INDENT_END(U))); | 1241 | DEBUGSPEW_CODE(DebugSpew(U) << "InterCopyContext::inter_copy()" << std::endl); |
| 1242 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); | 1242 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); |
| 1243 | 1243 | ||
| 1244 | int const _top_L1{ lua_gettop(L1) }; | 1244 | int const _top_L1{ lua_gettop(L1) }; |
| 1245 | if (n_ > _top_L1) { | 1245 | if (n_ > _top_L1) { |
| 1246 | // requesting to copy more than is available? | 1246 | // requesting to copy more than is available? |
| 1247 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "nothing to copy()\n" INDENT_END(U))); | 1247 | DEBUGSPEW_CODE(DebugSpew(U) << "nothing to copy" << std::endl); |
| 1248 | return InterCopyResult::NotEnoughValues; | 1248 | return InterCopyResult::NotEnoughValues; |
| 1249 | } | 1249 | } |
| 1250 | 1250 | ||
