aboutsummaryrefslogtreecommitdiff
path: root/src/intercopycontext.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/intercopycontext.cpp28
1 files changed, 9 insertions, 19 deletions
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp
index da4340e..d6716a3 100644
--- a/src/intercopycontext.cpp
+++ b/src/intercopycontext.cpp
@@ -337,10 +337,9 @@ void InterCopyContext::lookupNativeFunction() const
337 STACK_CHECK(L2, 1); 337 STACK_CHECK(L2, 1);
338 LUA_ASSERT(L1, lua_istable(L2, -1)); 338 LUA_ASSERT(L1, lua_istable(L2, -1));
339 luaG_pushstring(L2, _fqn); // L1: ... f ... L2: {} "f.q.n" 339 luaG_pushstring(L2, _fqn); // L1: ... f ... L2: {} "f.q.n"
340 lua_rawget(L2, -2); // L1: ... f ... L2: {} f 340 LuaType const _objType{ luaG_rawget(L2, StackIndex{ -2 }) }; // L1: ... f ... L2: {} f
341 // nil means we don't know how to transfer stuff: user should do something 341 // nil means we don't know how to transfer stuff: user should do something
342 // anything other than function or table should not happen! 342 // anything other than function or table should not happen!
343 LuaType const _objType{ luaG_type(L2, kIdxTop) };
344 if (_objType != LuaType::FUNCTION && _objType != LuaType::TABLE && _objType != LuaType::USERDATA) { 343 if (_objType != LuaType::FUNCTION && _objType != LuaType::TABLE && _objType != LuaType::USERDATA) {
345 kLaneNameRegKey.pushValue(L1); // L1: ... f ... lane_name 344 kLaneNameRegKey.pushValue(L1); // L1: ... f ... lane_name
346 std::string_view const _from{ luaG_tostring(L1, kIdxTop) }; 345 std::string_view const _from{ luaG_tostring(L1, kIdxTop) };
@@ -390,9 +389,7 @@ void InterCopyContext::copyCachedFunction() const
390 //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaG_tostring(L2, -1) << " >>" << std::endl); 389 //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaG_tostring(L2, -1) << " >>" << std::endl);
391 390
392 lua_pushvalue(L2, -1); // L2: ... {cache} ... p p 391 lua_pushvalue(L2, -1); // L2: ... {cache} ... p p
393 lua_rawget(L2, L2_cache_i); // L2: ... {cache} ... p function|nil|true 392 if (luaG_rawget(L2, L2_cache_i) == LuaType::NIL) { // function is unknown // L2: ... {cache} ... p function|nil|true
394
395 if (lua_isnil(L2, -1)) { // function is unknown
396 lua_pop(L2, 1); // L2: ... {cache} ... p 393 lua_pop(L2, 1); // L2: ... {cache} ... p
397 394
398 // Set to 'true' for the duration of creation; need to find self-references 395 // Set to 'true' for the duration of creation; need to find self-references
@@ -443,10 +440,9 @@ bool InterCopyContext::lookupTable() const
443 STACK_CHECK(L2, 1); 440 STACK_CHECK(L2, 1);
444 LUA_ASSERT(L1, lua_istable(L2, -1)); 441 LUA_ASSERT(L1, lua_istable(L2, -1));
445 luaG_pushstring(L2, _fqn); // L2: {} "f.q.n" 442 luaG_pushstring(L2, _fqn); // L2: {} "f.q.n"
446 lua_rawget(L2, -2); // L2: {} t
447 // we accept destination lookup failures in the case of transfering the Lanes body function (this will result in the source table being cloned instead) 443 // we accept destination lookup failures in the case of transfering the Lanes body function (this will result in the source table being cloned instead)
448 // but not when we extract something out of a keeper, as there is nothing to clone! 444 // but not when we extract something out of a keeper, as there is nothing to clone!
449 if (lua_isnil(L2, -1) && mode == LookupMode::LaneBody) { 445 if (luaG_rawget(L2, StackIndex{ -2 }) == LuaType::NIL && mode == LookupMode::LaneBody) { // L2: {} t
450 lua_pop(L2, 2); // L1: ... t ... L2: 446 lua_pop(L2, 2); // L1: ... t ... L2:
451 STACK_CHECK(L2, 0); 447 STACK_CHECK(L2, 0);
452 return false; 448 return false;
@@ -619,10 +615,7 @@ bool InterCopyContext::pushCachedMetatable() const
619 // do we already know this metatable? 615 // do we already know this metatable?
620 std::ignore = kMtIdRegKey.getSubTable(L2, NArr{ 0 }, NRec{ 0 }); // L2: _R[kMtIdRegKey] 616 std::ignore = kMtIdRegKey.getSubTable(L2, NArr{ 0 }, NRec{ 0 }); // L2: _R[kMtIdRegKey]
621 lua_pushinteger(L2, _mt_id); // L2: _R[kMtIdRegKey] id 617 lua_pushinteger(L2, _mt_id); // L2: _R[kMtIdRegKey] id
622 lua_rawget(L2, -2); // L2: _R[kMtIdRegKey] mt|nil 618 if (luaG_rawget(L2, StackIndex{ -2 }) == LuaType::NIL) { // L2 did not know the metatable // L2: _R[kMtIdRegKey] mt|nil
623 STACK_CHECK(L2, 2);
624
625 if (lua_isnil(L2, -1)) { // L2 did not know the metatable
626 lua_pop(L2, 1); // L2: _R[kMtIdRegKey] 619 lua_pop(L2, 1); // L2: _R[kMtIdRegKey]
627 InterCopyContext const _c{ U, L2, L1, L2_cache_i, SourceIndex{ lua_gettop(L1) }, VT::METATABLE, mode, name }; 620 InterCopyContext const _c{ U, L2, L1, L2_cache_i, SourceIndex{ lua_gettop(L1) }, VT::METATABLE, mode, name };
628 if (_c.interCopyOne() != InterCopyResult::Success) { // L2: _R[kMtIdRegKey] mt? 621 if (_c.interCopyOne() != InterCopyResult::Success) { // L2: _R[kMtIdRegKey] mt?
@@ -671,8 +664,7 @@ bool InterCopyContext::pushCachedTable() const
671 664
672 //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaG_tostring(L2, -1) << " >>" << std::endl); 665 //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaG_tostring(L2, -1) << " >>" << std::endl);
673 666
674 lua_rawget(L2, L2_cache_i); // L1: ... t ... L2: ... {cached|nil} 667 bool const _not_found_in_cache{ luaG_rawget(L2, L2_cache_i) == LuaType::NIL }; // L1: ... t ... L2: ... {cached|nil}
675 bool const _not_found_in_cache{ lua_isnil(L2, -1) };
676 if (_not_found_in_cache) { 668 if (_not_found_in_cache) {
677 // create a new entry in the cache 669 // create a new entry in the cache
678 lua_pop(L2, 1); // L1: ... t ... L2: ... 670 lua_pop(L2, 1); // L1: ... t ... L2: ...
@@ -714,10 +706,10 @@ bool InterCopyContext::lookupUserdata() const
714 STACK_CHECK(L2, 1); 706 STACK_CHECK(L2, 1);
715 LUA_ASSERT(L1, lua_istable(L2, -1)); 707 LUA_ASSERT(L1, lua_istable(L2, -1));
716 luaG_pushstring(L2, _fqn); // L1: ... f ... L2: {} "f.q.n" 708 luaG_pushstring(L2, _fqn); // L1: ... f ... L2: {} "f.q.n"
717 lua_rawget(L2, -2); // L1: ... f ... L2: {} f 709 LuaType const _type{ luaG_rawget(L2, StackIndex{ -2 }) }; // L1: ... f ... L2: {} f
718 // nil means we don't know how to transfer stuff: user should do something 710 // nil means we don't know how to transfer stuff: user should do something
719 // anything other than function or table should not happen! 711 // anything other than function or table should not happen!
720 if (!lua_isfunction(L2, -1) && !lua_istable(L2, -1)) { 712 if (_type != LuaType::FUNCTION && _type != LuaType::TABLE) {
721 kLaneNameRegKey.pushValue(L1); // L1: ... f ... lane_name 713 kLaneNameRegKey.pushValue(L1); // L1: ... f ... lane_name
722 std::string_view const _from{ luaG_tostring(L1, kIdxTop) }; 714 std::string_view const _from{ luaG_tostring(L1, kIdxTop) };
723 lua_pop(L1, 1); // L1: ... f ... 715 lua_pop(L1, 1); // L1: ... f ...
@@ -752,8 +744,7 @@ bool InterCopyContext::tryCopyClonable() const
752 744
753 // Check if the source was already cloned during this copy 745 // Check if the source was already cloned during this copy
754 lua_pushlightuserdata(L2, _source); // L2: ... source 746 lua_pushlightuserdata(L2, _source); // L2: ... source
755 lua_rawget(L2, L2_cache_i); // L2: ... clone? 747 if (luaG_rawget(L2, L2_cache_i) != LuaType::NIL) { // L2: ... clone?
756 if (!lua_isnil(L2, -1)) {
757 STACK_CHECK(L2, 1); 748 STACK_CHECK(L2, 1);
758 return true; 749 return true;
759 } else { 750 } else {
@@ -920,8 +911,7 @@ bool InterCopyContext::interCopyFunction() const
920 lua_getupvalue(L1, L1_i, 2); // L1: ... u 911 lua_getupvalue(L1, L1_i, 2); // L1: ... u
921 void* _source{ lua_touserdata(L1, -1) }; 912 void* _source{ lua_touserdata(L1, -1) };
922 lua_pushlightuserdata(L2, _source); // L2: ... source 913 lua_pushlightuserdata(L2, _source); // L2: ... source
923 lua_rawget(L2, L2_cache_i); // L2: ... u? 914 if (luaG_rawget(L2, L2_cache_i) != LuaType::NIL) { // L2: ... u?
924 if (!lua_isnil(L2, -1)) {
925 lua_pop(L1, 1); // L1: ... 915 lua_pop(L1, 1); // L1: ...
926 STACK_CHECK(L1, 0); 916 STACK_CHECK(L1, 0);
927 STACK_CHECK(L2, 1); 917 STACK_CHECK(L2, 1);