aboutsummaryrefslogtreecommitdiff
path: root/src/intercopycontext.cpp
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2025-07-04 13:50:53 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2025-07-04 13:50:53 +0200
commit042055968ab0c48faec607889814e38c50c09efa (patch)
tree4ec067a03ffcb720d8bf38968d5f84ccec8230d0 /src/intercopycontext.cpp
parent963afcbb3d9dac47b84552ed11e53a0641ad924d (diff)
downloadlanes-042055968ab0c48faec607889814e38c50c09efa.tar.gz
lanes-042055968ab0c48faec607889814e38c50c09efa.tar.bz2
lanes-042055968ab0c48faec607889814e38c50c09efa.zip
Changed lua wrapper prefixes from luaG_ to luaW_ (w as in wrapper!)
Diffstat (limited to 'src/intercopycontext.cpp')
-rw-r--r--src/intercopycontext.cpp142
1 files changed, 71 insertions, 71 deletions
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp
index a93615b..7be1326 100644
--- a/src/intercopycontext.cpp
+++ b/src/intercopycontext.cpp
@@ -93,7 +93,7 @@ static int userdata_lookup_sentinel(lua_State* const L_)
93[[nodiscard]] 93[[nodiscard]]
94std::string_view InterCopyContext::findLookupName() const 94std::string_view InterCopyContext::findLookupName() const
95{ 95{
96 LUA_ASSERT(L1, lua_isfunction(L1, L1_i) || lua_istable(L1, L1_i) || luaG_type(L1, L1_i) == LuaType::USERDATA); 96 LUA_ASSERT(L1, lua_isfunction(L1, L1_i) || lua_istable(L1, L1_i) || luaW_type(L1, L1_i) == LuaType::USERDATA);
97 STACK_CHECK_START_REL(L1, 0); // L1: ... v ... 97 STACK_CHECK_START_REL(L1, 0); // L1: ... v ...
98 STACK_GROW(L1, 3); // up to 3 slots are necessary on error 98 STACK_GROW(L1, 3); // up to 3 slots are necessary on error
99 if (mode == LookupMode::FromKeeper) { 99 if (mode == LookupMode::FromKeeper) {
@@ -114,7 +114,7 @@ std::string_view InterCopyContext::findLookupName() const
114 lua_pushvalue(L1, L1_i); // L1: ... v ... {} v 114 lua_pushvalue(L1, L1_i); // L1: ... v ... {} v
115 lua_rawget(L1, -2); // L1: ... v ... {} "f.q.n" 115 lua_rawget(L1, -2); // L1: ... v ... {} "f.q.n"
116 } 116 }
117 std::string_view _fqn{ luaG_tostring(L1, kIdxTop) }; 117 std::string_view _fqn{ luaW_tostring(L1, kIdxTop) };
118 DEBUGSPEW_CODE(DebugSpew(U) << "function [C] " << _fqn << std::endl); 118 DEBUGSPEW_CODE(DebugSpew(U) << "function [C] " << _fqn << std::endl);
119 // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database 119 // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database
120 lua_pop(L1, (mode == LookupMode::FromKeeper) ? 1 : 2); // L1: ... v ... 120 lua_pop(L1, (mode == LookupMode::FromKeeper) ? 1 : 2); // L1: ... v ...
@@ -122,12 +122,12 @@ std::string_view InterCopyContext::findLookupName() const
122 if (_fqn.empty() && !lua_istable(L1, L1_i)) { // raise an error if we try to send an unknown function/userdata (but not for tables) 122 if (_fqn.empty() && !lua_istable(L1, L1_i)) { // raise an error if we try to send an unknown function/userdata (but not for tables)
123 // try to discover the name of the function/userdata we want to send 123 // try to discover the name of the function/userdata we want to send
124 kLaneNameRegKey.pushValue(L1); // L1: ... v ... lane_name 124 kLaneNameRegKey.pushValue(L1); // L1: ... v ... lane_name
125 std::string_view const _from{ luaG_tostring(L1, kIdxTop) }; 125 std::string_view const _from{ luaW_tostring(L1, kIdxTop) };
126 lua_pushcfunction(L1, LG_nameof); // L1: ... v ... lane_name LG_nameof 126 lua_pushcfunction(L1, LG_nameof); // L1: ... v ... lane_name LG_nameof
127 lua_pushvalue(L1, L1_i); // L1: ... v ... lane_name LG_nameof t 127 lua_pushvalue(L1, L1_i); // L1: ... v ... lane_name LG_nameof t
128 lua_call(L1, 1, 2); // L1: ... v ... lane_name "type" "name"|nil 128 lua_call(L1, 1, 2); // L1: ... v ... lane_name "type" "name"|nil
129 StackIndex const _indexTypeWhat{ -2 }; 129 StackIndex const _indexTypeWhat{ -2 };
130 std::string_view const _typewhat{ (luaG_type(L1, _indexTypeWhat) == LuaType::STRING) ? luaG_tostring(L1, _indexTypeWhat) : luaG_typename(L1, _indexTypeWhat) }; 130 std::string_view const _typewhat{ (luaW_type(L1, _indexTypeWhat) == LuaType::STRING) ? luaW_tostring(L1, _indexTypeWhat) : luaW_typename(L1, _indexTypeWhat) };
131 // second return value can be nil if the table was not found 131 // second return value can be nil if the table was not found
132 // probable reason: the function was removed from the source Lua state before Lanes was required. 132 // probable reason: the function was removed from the source Lua state before Lanes was required.
133 std::string_view _what, _gotchaA, _gotchaB; 133 std::string_view _what, _gotchaA, _gotchaB;
@@ -139,7 +139,7 @@ std::string_view InterCopyContext::findLookupName() const
139 _gotchaA = ""; 139 _gotchaA = "";
140 _gotchaB = ""; 140 _gotchaB = "";
141 StackIndex const _indexWhat{ kIdxTop }; 141 StackIndex const _indexWhat{ kIdxTop };
142 _what = (luaG_type(L1, _indexWhat) == LuaType::STRING) ? luaG_tostring(L1, _indexWhat) : luaG_typename(L1, _indexWhat); 142 _what = (luaW_type(L1, _indexWhat) == LuaType::STRING) ? luaW_tostring(L1, _indexWhat) : luaW_typename(L1, _indexWhat);
143 } 143 }
144 raise_luaL_error(L1, "%s%s '%s' not found in %s origin transfer database.%s", _typewhat.data(), _gotchaA.data(), _what.data(), _from.empty() ? "main" : _from.data(), _gotchaB.data()); 144 raise_luaL_error(L1, "%s%s '%s' not found in %s origin transfer database.%s", _typewhat.data(), _gotchaA.data(), _what.data(), _from.empty() ? "main" : _from.data(), _gotchaB.data());
145 } 145 }
@@ -158,7 +158,7 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull };
158[[nodiscard]] 158[[nodiscard]]
159static lua_Integer get_mt_id(Universe* const U_, lua_State* const L_, StackIndex const idx_) 159static lua_Integer get_mt_id(Universe* const U_, lua_State* const L_, StackIndex const idx_)
160{ 160{
161 StackIndex const _absidx{ luaG_absindex(L_, idx_) }; 161 StackIndex const _absidx{ luaW_absindex(L_, idx_) };
162 162
163 STACK_GROW(L_, 3); 163 STACK_GROW(L_, 3);
164 164
@@ -199,7 +199,7 @@ void InterCopyContext::copyFunction() const
199 STACK_GROW(L1, 2); 199 STACK_GROW(L1, 2);
200 STACK_CHECK_START_REL(L1, 0); 200 STACK_CHECK_START_REL(L1, 0);
201 201
202 // 'luaG_dump()' needs the function at top of stack 202 // 'luaW_dump()' needs the function at top of stack
203 // if already on top of the stack, no need to push again 203 // if already on top of the stack, no need to push again
204 bool const _needToPush{ L1_i != lua_gettop(L1) }; 204 bool const _needToPush{ L1_i != lua_gettop(L1) };
205 if (_needToPush) { 205 if (_needToPush) {
@@ -212,7 +212,7 @@ void InterCopyContext::copyFunction() const
212 // not sure this could ever fail but for memory shortage reasons 212 // not sure this could ever fail but for memory shortage reasons
213 // last argument is Lua 5.4-specific (no stripping) 213 // last argument is Lua 5.4-specific (no stripping)
214 luaL_Buffer B{}; 214 luaL_Buffer B{};
215 if (luaG_dump(L1, buf_writer, &B, U->stripFunctions) != 0) { 215 if (luaW_dump(L1, buf_writer, &B, U->stripFunctions) != 0) {
216 raise_luaL_error(getErrL(), "internal error: function dump failed."); 216 raise_luaL_error(getErrL(), "internal error: function dump failed.");
217 } 217 }
218 218
@@ -240,7 +240,7 @@ void InterCopyContext::copyFunction() const
240 } 240 }
241 241
242 { 242 {
243 std::string_view const _bytecode{ luaG_tostring(L1, kIdxTop) }; // L1: ... b 243 std::string_view const _bytecode{ luaW_tostring(L1, kIdxTop) }; // L1: ... b
244 LUA_ASSERT(L1, !_bytecode.empty()); 244 LUA_ASSERT(L1, !_bytecode.empty());
245 STACK_GROW(L2, 2); 245 STACK_GROW(L2, 2);
246 // Note: Line numbers seem to be taken precisely from the 246 // Note: Line numbers seem to be taken precisely from the
@@ -278,12 +278,12 @@ void InterCopyContext::copyFunction() const
278 { 278 {
279 InterCopyContext _c{ U, L2, L1, L2_cache_i, {}, VT::NORMAL, mode, {} }; 279 InterCopyContext _c{ U, L2, L1, L2_cache_i, {}, VT::NORMAL, mode, {} };
280 // if we encounter an upvalue equal to the global table in the source, bind it to the destination's global table 280 // if we encounter an upvalue equal to the global table in the source, bind it to the destination's global table
281 luaG_pushglobaltable(L1); // L1: ... _G 281 luaW_pushglobaltable(L1); // L1: ... _G
282 for (char const* _upname{}; (_upname = lua_getupvalue(L1, L1_i, 1 + _n)); ++_n) { // L1: ... _G up[n] 282 for (char const* _upname{}; (_upname = lua_getupvalue(L1, L1_i, 1 + _n)); ++_n) { // L1: ... _G up[n]
283 DEBUGSPEW_CODE(DebugSpew(U) << "UPNAME[" << _n << "]: " << _c.name << " -> "); 283 DEBUGSPEW_CODE(DebugSpew(U) << "UPNAME[" << _n << "]: " << _c.name << " -> ");
284 if (lua_rawequal(L1, -1, -2)) { // is the upvalue equal to the global table? 284 if (lua_rawequal(L1, -1, -2)) { // is the upvalue equal to the global table?
285 DEBUGSPEW_CODE(DebugSpew(nullptr) << "pushing destination global scope" << std::endl); 285 DEBUGSPEW_CODE(DebugSpew(nullptr) << "pushing destination global scope" << std::endl);
286 luaG_pushglobaltable(L2); // L2: ... {cache} ... function <upvalues> 286 luaW_pushglobaltable(L2); // L2: ... {cache} ... function <upvalues>
287 } else { 287 } else {
288 DEBUGSPEW_CODE(DebugSpew(nullptr) << "copying value" << std::endl); 288 DEBUGSPEW_CODE(DebugSpew(nullptr) << "copying value" << std::endl);
289 _c.name = _upname; 289 _c.name = _upname;
@@ -327,7 +327,7 @@ void InterCopyContext::lookupNativeFunction() const
327 327
328 case LookupMode::ToKeeper: 328 case LookupMode::ToKeeper:
329 // push a sentinel closure that holds the lookup name as upvalue 329 // push a sentinel closure that holds the lookup name as upvalue
330 luaG_pushstring(L2, _fqn); // L1: ... f ... L2: "f.q.n" 330 luaW_pushstring(L2, _fqn); // L1: ... f ... L2: "f.q.n"
331 lua_pushcclosure(L2, func_lookup_sentinel, 1); // L1: ... f ... L2: f 331 lua_pushcclosure(L2, func_lookup_sentinel, 1); // L1: ... f ... L2: f
332 break; 332 break;
333 333
@@ -336,16 +336,16 @@ void InterCopyContext::lookupNativeFunction() const
336 kLookupRegKey.pushValue(L2); // L1: ... f ... L2: {} 336 kLookupRegKey.pushValue(L2); // L1: ... f ... L2: {}
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 luaW_pushstring(L2, _fqn); // L1: ... f ... L2: {} "f.q.n"
340 LuaType const _objType{ luaG_rawget(L2, StackIndex{ -2 }) }; // L1: ... f ... L2: {} f 340 LuaType const _objType{ luaW_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 if (_objType != LuaType::FUNCTION && _objType != LuaType::TABLE && _objType != LuaType::USERDATA) { 343 if (_objType != LuaType::FUNCTION && _objType != LuaType::TABLE && _objType != LuaType::USERDATA) {
344 kLaneNameRegKey.pushValue(L1); // L1: ... f ... lane_name 344 kLaneNameRegKey.pushValue(L1); // L1: ... f ... lane_name
345 std::string_view const _from{ luaG_tostring(L1, kIdxTop) }; 345 std::string_view const _from{ luaW_tostring(L1, kIdxTop) };
346 lua_pop(L1, 1); // L1: ... f ... 346 lua_pop(L1, 1); // L1: ... f ...
347 kLaneNameRegKey.pushValue(L2); // L1: ... f ... L2: {} f lane_name 347 kLaneNameRegKey.pushValue(L2); // L1: ... f ... L2: {} f lane_name
348 std::string_view const _to{ luaG_tostring(L2, kIdxTop) }; 348 std::string_view const _to{ luaW_tostring(L2, kIdxTop) };
349 lua_pop(L2, 1); // L2: {} f 349 lua_pop(L2, 1); // L2: {} f
350 raise_luaL_error( 350 raise_luaL_error(
351 getErrL(), 351 getErrL(),
@@ -368,7 +368,7 @@ void InterCopyContext::lookupNativeFunction() const
368// Always pushes a function to 'L2'. 368// Always pushes a function to 'L2'.
369void InterCopyContext::copyCachedFunction() const 369void InterCopyContext::copyCachedFunction() const
370{ 370{
371 FuncSubType const _funcSubType{ luaG_getfuncsubtype(L1, L1_i) }; 371 FuncSubType const _funcSubType{ luaW_getfuncsubtype(L1, L1_i) };
372 if (_funcSubType == FuncSubType::Bytecode) { 372 if (_funcSubType == FuncSubType::Bytecode) {
373 void* const _aspointer{ const_cast<void*>(lua_topointer(L1, L1_i)) }; 373 void* const _aspointer{ const_cast<void*>(lua_topointer(L1, L1_i)) };
374 // TODO: Merge this and same code for tables 374 // TODO: Merge this and same code for tables
@@ -386,10 +386,10 @@ void InterCopyContext::copyCachedFunction() const
386 // push a light userdata uniquely representing the function 386 // push a light userdata uniquely representing the function
387 lua_pushlightuserdata(L2, _aspointer); // L2: ... {cache} ... p 387 lua_pushlightuserdata(L2, _aspointer); // L2: ... {cache} ... p
388 388
389 //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaG_tostring(L2, -1) << " >>" << std::endl); 389 //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaW_tostring(L2, -1) << " >>" << std::endl);
390 390
391 lua_pushvalue(L2, -1); // L2: ... {cache} ... p p 391 lua_pushvalue(L2, -1); // L2: ... {cache} ... p p
392 if (luaG_rawget(L2, L2_cache_i) == LuaType::NIL) { // function is unknown // L2: ... {cache} ... p function|nil|true 392 if (luaW_rawget(L2, L2_cache_i) == LuaType::NIL) { // function is unknown // L2: ... {cache} ... p function|nil|true
393 lua_pop(L2, 1); // L2: ... {cache} ... p 393 lua_pop(L2, 1); // L2: ... {cache} ... p
394 394
395 // 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
@@ -405,7 +405,7 @@ void InterCopyContext::copyCachedFunction() const
405 } else { // function is native/LuaJIT: no need to cache 405 } else { // function is native/LuaJIT: no need to cache
406 lookupNativeFunction(); // L2: ... {cache} ... function 406 lookupNativeFunction(); // L2: ... {cache} ... function
407 // if the function was in fact a lookup sentinel, we can either get a function, table or full userdata here 407 // if the function was in fact a lookup sentinel, we can either get a function, table or full userdata here
408 LUA_ASSERT(L1, lua_isfunction(L2, kIdxTop) || lua_istable(L2, kIdxTop) || luaG_type(L2, kIdxTop) == LuaType::USERDATA); 408 LUA_ASSERT(L1, lua_isfunction(L2, kIdxTop) || lua_istable(L2, kIdxTop) || luaW_type(L2, kIdxTop) == LuaType::USERDATA);
409 } 409 }
410} 410}
411 411
@@ -430,7 +430,7 @@ bool InterCopyContext::lookupTable() const
430 430
431 case LookupMode::ToKeeper: 431 case LookupMode::ToKeeper:
432 // push a sentinel closure that holds the lookup name as upvalue 432 // push a sentinel closure that holds the lookup name as upvalue
433 luaG_pushstring(L2, _fqn); // L1: ... t ... L2: "f.q.n" 433 luaW_pushstring(L2, _fqn); // L1: ... t ... L2: "f.q.n"
434 lua_pushcclosure(L2, table_lookup_sentinel, 1); // L1: ... t ... L2: f 434 lua_pushcclosure(L2, table_lookup_sentinel, 1); // L1: ... t ... L2: f
435 break; 435 break;
436 436
@@ -439,26 +439,26 @@ bool InterCopyContext::lookupTable() const
439 kLookupRegKey.pushValue(L2); // L1: ... t ... L2: {} 439 kLookupRegKey.pushValue(L2); // L1: ... t ... L2: {}
440 STACK_CHECK(L2, 1); 440 STACK_CHECK(L2, 1);
441 LUA_ASSERT(L1, lua_istable(L2, -1)); 441 LUA_ASSERT(L1, lua_istable(L2, -1));
442 luaG_pushstring(L2, _fqn); // L2: {} "f.q.n" 442 luaW_pushstring(L2, _fqn); // L2: {} "f.q.n"
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) 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)
444 // 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!
445 if (luaG_rawget(L2, StackIndex{ -2 }) == LuaType::NIL && mode == LookupMode::LaneBody) { // L2: {} t 445 if (luaW_rawget(L2, StackIndex{ -2 }) == LuaType::NIL && mode == LookupMode::LaneBody) { // L2: {} t
446 lua_pop(L2, 2); // L1: ... t ... L2: 446 lua_pop(L2, 2); // L1: ... t ... L2:
447 STACK_CHECK(L2, 0); 447 STACK_CHECK(L2, 0);
448 return false; 448 return false;
449 } else if (!lua_istable(L2, -1)) { // this can happen if someone decides to replace same already registered item (for a example a standard lib function) with a table 449 } else if (!lua_istable(L2, -1)) { // this can happen if someone decides to replace same already registered item (for a example a standard lib function) with a table
450 kLaneNameRegKey.pushValue(L1); // L1: ... t ... lane_name 450 kLaneNameRegKey.pushValue(L1); // L1: ... t ... lane_name
451 std::string_view const _from{ luaG_tostring(L1, kIdxTop) }; 451 std::string_view const _from{ luaW_tostring(L1, kIdxTop) };
452 lua_pop(L1, 1); // L1: ... t ... 452 lua_pop(L1, 1); // L1: ... t ...
453 kLaneNameRegKey.pushValue(L2); // L1: ... t ... L2: {} t lane_name 453 kLaneNameRegKey.pushValue(L2); // L1: ... t ... L2: {} t lane_name
454 std::string_view const _to{ luaG_tostring(L2, kIdxTop) }; 454 std::string_view const _to{ luaW_tostring(L2, kIdxTop) };
455 lua_pop(L2, 1); // L1: ... t ... L2: {} t 455 lua_pop(L2, 1); // L1: ... t ... L2: {} t
456 raise_luaL_error( 456 raise_luaL_error(
457 getErrL(), 457 getErrL(),
458 "%s: source table '%s' found as %s in %s destination transfer database.", 458 "%s: source table '%s' found as %s in %s destination transfer database.",
459 _from.empty() ? "main" : _from.data(), 459 _from.empty() ? "main" : _from.data(),
460 _fqn.data(), 460 _fqn.data(),
461 luaG_typename(L2, kIdxTop).data(), 461 luaW_typename(L2, kIdxTop).data(),
462 _to.empty() ? "main" : _to.data()); 462 _to.empty() ? "main" : _to.data());
463 } 463 }
464 lua_remove(L2, -2); // L1: ... t ... L2: t 464 lua_remove(L2, -2); // L1: ... t ... L2: t
@@ -487,8 +487,8 @@ void InterCopyContext::interCopyKeyValuePair() const
487 char* _valPath{ nullptr }; 487 char* _valPath{ nullptr };
488 if (U->verboseErrors) { 488 if (U->verboseErrors) {
489 // for debug purposes, let's try to build a useful name 489 // for debug purposes, let's try to build a useful name
490 if (luaG_type(L1, _key_i) == LuaType::STRING) { 490 if (luaW_type(L1, _key_i) == LuaType::STRING) {
491 std::string_view const _key{ luaG_tostring(L1, _key_i) }; 491 std::string_view const _key{ luaW_tostring(L1, _key_i) };
492 size_t const _bufLen{ name.size() + _key.size() + 2 }; // +2 for separator dot and terminating 0 492 size_t const _bufLen{ name.size() + _key.size() + 2 }; // +2 for separator dot and terminating 0
493 _valPath = static_cast<char*>(alloca(_bufLen)); 493 _valPath = static_cast<char*>(alloca(_bufLen));
494 sprintf(_valPath, "%s." STRINGVIEW_FMT, name.data(), (int) _key.size(), _key.data()); 494 sprintf(_valPath, "%s." STRINGVIEW_FMT, name.data(), (int) _key.size(), _key.data());
@@ -500,15 +500,15 @@ void InterCopyContext::interCopyKeyValuePair() const
500 sprintf(_valPath, "%s[" LUA_INTEGER_FMT "]", name.data(), key); 500 sprintf(_valPath, "%s[" LUA_INTEGER_FMT "]", name.data(), key);
501 } 501 }
502#endif // defined LUA_LNUM || LUA_VERSION_NUM >= 503 502#endif // defined LUA_LNUM || LUA_VERSION_NUM >= 503
503 else if (luaG_type(L1, _key_i) == LuaType::NUMBER) { 503 else if (luaW_type(L1, _key_i) == LuaType::NUMBER) {
504 lua_Number const key{ lua_tonumber(L1, _key_i) }; 504 lua_Number const key{ lua_tonumber(L1, _key_i) };
505 _valPath = (char*) alloca(name.size() + 32 + 3); // +3 for [] and terminating 0 505 _valPath = (char*) alloca(name.size() + 32 + 3); // +3 for [] and terminating 0
506 sprintf(_valPath, "%s[" LUA_NUMBER_FMT "]", name.data(), key); 506 sprintf(_valPath, "%s[" LUA_NUMBER_FMT "]", name.data(), key);
507 } else if (luaG_type(L1, _key_i) == LuaType::LIGHTUSERDATA) { 507 } else if (luaW_type(L1, _key_i) == LuaType::LIGHTUSERDATA) {
508 void* const _key{ lua_touserdata(L1, _key_i) }; 508 void* const _key{ lua_touserdata(L1, _key_i) };
509 _valPath = (char*) alloca(name.size() + 16 + 5); // +5 for [U:] and terminating 0 509 _valPath = (char*) alloca(name.size() + 16 + 5); // +5 for [U:] and terminating 0
510 sprintf(_valPath, "%s[U:%p]", name.data(), _key); 510 sprintf(_valPath, "%s[U:%p]", name.data(), _key);
511 } else if (luaG_type(L1, _key_i) == LuaType::BOOLEAN) { 511 } else if (luaW_type(L1, _key_i) == LuaType::BOOLEAN) {
512 int const _key{ lua_toboolean(L1, _key_i) }; 512 int const _key{ lua_toboolean(L1, _key_i) };
513 _valPath = (char*) alloca(name.size() + 8); // +8 for [], 'false' and terminating 0 513 _valPath = (char*) alloca(name.size() + 8); // +8 for [], 'false' and terminating 0
514 sprintf(_valPath, "%s[%s]", name.data(), _key ? "true" : "false"); 514 sprintf(_valPath, "%s[%s]", name.data(), _key ? "true" : "false");
@@ -532,7 +532,7 @@ LuaType InterCopyContext::processConversion() const
532{ 532{
533 static constexpr int kPODmask = (1 << LUA_TNIL) | (1 << LUA_TBOOLEAN) | (1 << LUA_TLIGHTUSERDATA) | (1 << LUA_TNUMBER) | (1 << LUA_TSTRING); 533 static constexpr int kPODmask = (1 << LUA_TNIL) | (1 << LUA_TBOOLEAN) | (1 << LUA_TLIGHTUSERDATA) | (1 << LUA_TNUMBER) | (1 << LUA_TSTRING);
534 534
535 LuaType _val_type{ luaG_type(L1, L1_i) }; 535 LuaType _val_type{ luaW_type(L1, L1_i) };
536 536
537 STACK_CHECK_START_REL(L1, 0); 537 STACK_CHECK_START_REL(L1, 0);
538 538
@@ -548,7 +548,7 @@ LuaType InterCopyContext::processConversion() const
548 } 548 }
549 // we have a metatable // L1: ... mt 549 // we have a metatable // L1: ... mt
550 static constexpr std::string_view kConvertField{ "__lanesconvert" }; 550 static constexpr std::string_view kConvertField{ "__lanesconvert" };
551 LuaType const _converterType{ luaG_getfield(L1, kIdxTop, kConvertField) }; // L1: ... mt kConvertField 551 LuaType const _converterType{ luaW_getfield(L1, kIdxTop, kConvertField) }; // L1: ... mt kConvertField
552 switch (_converterType) { 552 switch (_converterType) {
553 case LuaType::NIL: 553 case LuaType::NIL:
554 // no __lanesconvert, nothing to do 554 // no __lanesconvert, nothing to do
@@ -557,18 +557,18 @@ LuaType InterCopyContext::processConversion() const
557 557
558 case LuaType::LIGHTUSERDATA: 558 case LuaType::LIGHTUSERDATA:
559 if (kNilSentinel.equals(L1, kIdxTop)) { 559 if (kNilSentinel.equals(L1, kIdxTop)) {
560 DEBUGSPEW_CODE(DebugSpew(U) << "converted " << luaG_typename(L1, _val_type) << " to nil" << std::endl); 560 DEBUGSPEW_CODE(DebugSpew(U) << "converted " << luaW_typename(L1, _val_type) << " to nil" << std::endl);
561 lua_replace(L1, L1_i); // L1: ... mt 561 lua_replace(L1, L1_i); // L1: ... mt
562 lua_pop(L1, 1); // L1: ... 562 lua_pop(L1, 1); // L1: ...
563 _val_type = _converterType; 563 _val_type = _converterType;
564 } else { 564 } else {
565 raise_luaL_error(getErrL(), "Invalid %s type %s", kConvertField.data(), luaG_typename(L1, _converterType).data()); 565 raise_luaL_error(getErrL(), "Invalid %s type %s", kConvertField.data(), luaW_typename(L1, _converterType).data());
566 } 566 }
567 break; 567 break;
568 568
569 case LuaType::STRING: 569 case LuaType::STRING:
570 // kConvertField == "decay" -> replace source value with it's pointer 570 // kConvertField == "decay" -> replace source value with it's pointer
571 if (std::string_view const _mode{ luaG_tostring(L1, kIdxTop) }; _mode == "decay") { 571 if (std::string_view const _mode{ luaW_tostring(L1, kIdxTop) }; _mode == "decay") {
572 lua_pop(L1, 1); // L1: ... mt 572 lua_pop(L1, 1); // L1: ... mt
573 lua_pushlightuserdata(L1, const_cast<void*>(lua_topointer(L1, L1_i))); // L1: ... mt decayed 573 lua_pushlightuserdata(L1, const_cast<void*>(lua_topointer(L1, L1_i))); // L1: ... mt decayed
574 lua_replace(L1, L1_i); // L1: ... mt 574 lua_replace(L1, L1_i); // L1: ... mt
@@ -581,18 +581,18 @@ LuaType InterCopyContext::processConversion() const
581 581
582 case LuaType::FUNCTION: 582 case LuaType::FUNCTION:
583 lua_pushvalue(L1, L1_i); // L1: ... mt kConvertField val 583 lua_pushvalue(L1, L1_i); // L1: ... mt kConvertField val
584 luaG_pushstring(L1, mode == LookupMode::ToKeeper ? "keeper" : "regular"); // L1: ... mt kConvertField val string 584 luaW_pushstring(L1, mode == LookupMode::ToKeeper ? "keeper" : "regular"); // L1: ... mt kConvertField val string
585 lua_call(L1, 2, 1); // val:kConvertField(str) -> result // L1: ... mt kConvertField converted 585 lua_call(L1, 2, 1); // val:kConvertField(str) -> result // L1: ... mt kConvertField converted
586 lua_replace(L1, L1_i); // L1: ... mt 586 lua_replace(L1, L1_i); // L1: ... mt
587 lua_pop(L1, 1); // L1: ... mt 587 lua_pop(L1, 1); // L1: ... mt
588 _val_type = luaG_type(L1, L1_i); 588 _val_type = luaW_type(L1, L1_i);
589 break; 589 break;
590 590
591 default: 591 default:
592 raise_luaL_error(getErrL(), "Invalid %s type %s", kConvertField.data(), luaG_typename(L1, _converterType).data()); 592 raise_luaL_error(getErrL(), "Invalid %s type %s", kConvertField.data(), luaW_typename(L1, _converterType).data());
593 } 593 }
594 STACK_CHECK(L1, 0); 594 STACK_CHECK(L1, 0);
595 LUA_ASSERT(getErrL(), luaG_type(L1, L1_i) == _val_type); 595 LUA_ASSERT(getErrL(), luaW_type(L1, L1_i) == _val_type);
596 return _val_type; 596 return _val_type;
597} 597}
598 598
@@ -615,7 +615,7 @@ bool InterCopyContext::pushCachedMetatable() const
615 // do we already know this metatable? 615 // do we already know this metatable?
616 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]
617 lua_pushinteger(L2, _mt_id); // L2: _R[kMtIdRegKey] id 617 lua_pushinteger(L2, _mt_id); // L2: _R[kMtIdRegKey] id
618 if (luaG_rawget(L2, StackIndex{ -2 }) == LuaType::NIL) { // L2 did not know the metatable // L2: _R[kMtIdRegKey] mt|nil 618 if (luaW_rawget(L2, StackIndex{ -2 }) == LuaType::NIL) { // L2 did not know the metatable // L2: _R[kMtIdRegKey] mt|nil
619 lua_pop(L2, 1); // L2: _R[kMtIdRegKey] 619 lua_pop(L2, 1); // L2: _R[kMtIdRegKey]
620 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 };
621 if (_c.interCopyOne() != InterCopyResult::Success) { // L2: _R[kMtIdRegKey] mt? 621 if (_c.interCopyOne() != InterCopyResult::Success) { // L2: _R[kMtIdRegKey] mt?
@@ -662,9 +662,9 @@ bool InterCopyContext::pushCachedTable() const
662 // push a light userdata uniquely representing the table 662 // push a light userdata uniquely representing the table
663 lua_pushlightuserdata(L2, const_cast<void*>(_p)); // L1: ... t ... L2: ... p 663 lua_pushlightuserdata(L2, const_cast<void*>(_p)); // L1: ... t ... L2: ... p
664 664
665 //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaG_tostring(L2, -1) << " >>" << std::endl); 665 //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaW_tostring(L2, -1) << " >>" << std::endl);
666 666
667 bool const _not_found_in_cache{ luaG_rawget(L2, L2_cache_i) == LuaType::NIL }; // L1: ... t ... L2: ... {cached|nil} 667 bool const _not_found_in_cache{ luaW_rawget(L2, L2_cache_i) == LuaType::NIL }; // L1: ... t ... L2: ... {cached|nil}
668 if (_not_found_in_cache) { 668 if (_not_found_in_cache) {
669 // create a new entry in the cache 669 // create a new entry in the cache
670 lua_pop(L2, 1); // L1: ... t ... L2: ... 670 lua_pop(L2, 1); // L1: ... t ... L2: ...
@@ -696,7 +696,7 @@ bool InterCopyContext::lookupUserdata() const
696 696
697 case LookupMode::ToKeeper: 697 case LookupMode::ToKeeper:
698 // push a sentinel closure that holds the lookup name as upvalue 698 // push a sentinel closure that holds the lookup name as upvalue
699 luaG_pushstring(L2, _fqn); // L1: ... f ... L2: "f.q.n" 699 luaW_pushstring(L2, _fqn); // L1: ... f ... L2: "f.q.n"
700 lua_pushcclosure(L2, userdata_lookup_sentinel, 1); // L1: ... f ... L2: f 700 lua_pushcclosure(L2, userdata_lookup_sentinel, 1); // L1: ... f ... L2: f
701 break; 701 break;
702 702
@@ -705,16 +705,16 @@ bool InterCopyContext::lookupUserdata() const
705 kLookupRegKey.pushValue(L2); // L1: ... f ... L2: {} 705 kLookupRegKey.pushValue(L2); // L1: ... f ... L2: {}
706 STACK_CHECK(L2, 1); 706 STACK_CHECK(L2, 1);
707 LUA_ASSERT(L1, lua_istable(L2, -1)); 707 LUA_ASSERT(L1, lua_istable(L2, -1));
708 luaG_pushstring(L2, _fqn); // L1: ... f ... L2: {} "f.q.n" 708 luaW_pushstring(L2, _fqn); // L1: ... f ... L2: {} "f.q.n"
709 LuaType const _type{ luaG_rawget(L2, StackIndex{ -2 }) }; // L1: ... f ... L2: {} f 709 LuaType const _type{ luaW_rawget(L2, StackIndex{ -2 }) }; // L1: ... f ... L2: {} f
710 // 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
711 // anything other than function or table should not happen! 711 // anything other than function or table should not happen!
712 if (_type != LuaType::FUNCTION && _type != LuaType::TABLE) { 712 if (_type != LuaType::FUNCTION && _type != LuaType::TABLE) {
713 kLaneNameRegKey.pushValue(L1); // L1: ... f ... lane_name 713 kLaneNameRegKey.pushValue(L1); // L1: ... f ... lane_name
714 std::string_view const _from{ luaG_tostring(L1, kIdxTop) }; 714 std::string_view const _from{ luaW_tostring(L1, kIdxTop) };
715 lua_pop(L1, 1); // L1: ... f ... 715 lua_pop(L1, 1); // L1: ... f ...
716 kLaneNameRegKey.pushValue(L2); // L1: ... f ... L2: {} f lane_name 716 kLaneNameRegKey.pushValue(L2); // L1: ... f ... L2: {} f lane_name
717 std::string_view const _to{ luaG_tostring(L2, kIdxTop) }; 717 std::string_view const _to{ luaW_tostring(L2, kIdxTop) };
718 lua_pop(L2, 1); // L2: {} f 718 lua_pop(L2, 1); // L2: {} f
719 raise_luaL_error( 719 raise_luaL_error(
720 getErrL(), 720 getErrL(),
@@ -736,7 +736,7 @@ bool InterCopyContext::lookupUserdata() const
736[[nodiscard]] 736[[nodiscard]]
737bool InterCopyContext::tryCopyClonable() const 737bool InterCopyContext::tryCopyClonable() const
738{ 738{
739 SourceIndex const _L1_i{ luaG_absindex(L1, L1_i).value() }; 739 SourceIndex const _L1_i{ luaW_absindex(L1, L1_i).value() };
740 void* const _source{ lua_touserdata(L1, _L1_i) }; 740 void* const _source{ lua_touserdata(L1, _L1_i) };
741 741
742 STACK_CHECK_START_REL(L1, 0); 742 STACK_CHECK_START_REL(L1, 0);
@@ -744,7 +744,7 @@ bool InterCopyContext::tryCopyClonable() const
744 744
745 // Check if the source was already cloned during this copy 745 // Check if the source was already cloned during this copy
746 lua_pushlightuserdata(L2, _source); // L2: ... source 746 lua_pushlightuserdata(L2, _source); // L2: ... source
747 if (luaG_rawget(L2, L2_cache_i) != LuaType::NIL) { // L2: ... clone? 747 if (luaW_rawget(L2, L2_cache_i) != LuaType::NIL) { // L2: ... clone?
748 STACK_CHECK(L2, 1); 748 STACK_CHECK(L2, 1);
749 return true; 749 return true;
750 } else { 750 } else {
@@ -759,7 +759,7 @@ bool InterCopyContext::tryCopyClonable() const
759 } 759 }
760 760
761 // no __lanesclone? -> not clonable 761 // no __lanesclone? -> not clonable
762 if (luaG_getfield(L1, kIdxTop, "__lanesclone") == LuaType::NIL) { // L1: ... mt nil 762 if (luaW_getfield(L1, kIdxTop, "__lanesclone") == LuaType::NIL) { // L1: ... mt nil
763 lua_pop(L1, 2); // L1: ... 763 lua_pop(L1, 2); // L1: ...
764 STACK_CHECK(L1, 0); 764 STACK_CHECK(L1, 0);
765 return false; 765 return false;
@@ -769,10 +769,10 @@ bool InterCopyContext::tryCopyClonable() const
769 769
770 // we need to copy over the uservalues of the userdata as well 770 // we need to copy over the uservalues of the userdata as well
771 { 771 {
772 StackIndex const _mt{ luaG_absindex(L1, StackIndex{ -2 }) }; // L1: ... mt __lanesclone 772 StackIndex const _mt{ luaW_absindex(L1, StackIndex{ -2 }) }; // L1: ... mt __lanesclone
773 auto const userdata_size{ static_cast<size_t>(lua_rawlen(L1, _L1_i)) }; // make 32-bits builds happy 773 auto const userdata_size{ static_cast<size_t>(lua_rawlen(L1, _L1_i)) }; // make 32-bits builds happy
774 // extract all the uservalues, but don't transfer them yet 774 // extract all the uservalues, but don't transfer them yet
775 UserValueCount const _nuv{ luaG_getalluservalues(L1, _L1_i) }; // L1: ... mt __lanesclone [uv]* 775 UserValueCount const _nuv{ luaW_getalluservalues(L1, _L1_i) }; // L1: ... mt __lanesclone [uv]*
776 // create the clone userdata with the required number of uservalue slots 776 // create the clone userdata with the required number of uservalue slots
777 void* const _clone{ lua_newuserdatauv(L2, userdata_size, _nuv) }; // L2: ... u 777 void* const _clone{ lua_newuserdatauv(L2, userdata_size, _nuv) }; // L2: ... u
778 // copy the metatable in the target state, and give it to the clone we put there 778 // copy the metatable in the target state, and give it to the clone we put there
@@ -804,7 +804,7 @@ bool InterCopyContext::tryCopyClonable() const
804 // assign uservalues 804 // assign uservalues
805 UserValueIndex _uvi{ _nuv.value() }; 805 UserValueIndex _uvi{ _nuv.value() };
806 while (_uvi > 0) { 806 while (_uvi > 0) {
807 _c.L1_i = SourceIndex{ luaG_absindex(L1, kIdxTop).value() }; 807 _c.L1_i = SourceIndex{ luaW_absindex(L1, kIdxTop).value() };
808 if (_c.interCopyOne() != InterCopyResult::Success) { // L2: ... u uv 808 if (_c.interCopyOne() != InterCopyResult::Success) { // L2: ... u uv
809 raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); 809 raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1));
810 } 810 }
@@ -850,10 +850,10 @@ bool InterCopyContext::tryCopyDeep() const
850 STACK_CHECK_START_REL(L2, 0); 850 STACK_CHECK_START_REL(L2, 0);
851 851
852 // extract all uservalues of the source. unfortunately, the only way to know their count is to iterate until we fail 852 // extract all uservalues of the source. unfortunately, the only way to know their count is to iterate until we fail
853 UserValueCount const _nuv{ luaG_getalluservalues(L1, L1_i) }; // L1: ... deep ... [uv]* 853 UserValueCount const _nuv{ luaW_getalluservalues(L1, L1_i) }; // L1: ... deep ... [uv]*
854 STACK_CHECK(L1, _nuv); 854 STACK_CHECK(L1, _nuv);
855 855
856 DeepPrelude* const _deep{ *luaG_tofulluserdata<DeepPrelude*>(L1, L1_i) }; 856 DeepPrelude* const _deep{ *luaW_tofulluserdata<DeepPrelude*>(L1, L1_i) };
857 DeepFactory::PushDeepProxy(L2, _deep, _nuv, mode, getErrL()); // L1: ... deep ... [uv]* L2: deep 857 DeepFactory::PushDeepProxy(L2, _deep, _nuv, mode, getErrL()); // L1: ... deep ... [uv]* L2: deep
858 858
859 // transfer all uservalues of the source in the destination 859 // transfer all uservalues of the source in the destination
@@ -863,7 +863,7 @@ bool InterCopyContext::tryCopyDeep() const
863 STACK_GROW(L2, _nuv); 863 STACK_GROW(L2, _nuv);
864 UserValueIndex _uvi{ _nuv.value() }; 864 UserValueIndex _uvi{ _nuv.value() };
865 while (_uvi) { 865 while (_uvi) {
866 _c.L1_i = SourceIndex{ luaG_absindex(L1, kIdxTop).value() }; 866 _c.L1_i = SourceIndex{ luaW_absindex(L1, kIdxTop).value() };
867 if (_c.interCopyOne() != InterCopyResult::Success) { // L1: ... deep ... [uv]* L2: deep uv 867 if (_c.interCopyOne() != InterCopyResult::Success) { // L1: ... deep ... [uv]* L2: deep uv
868 raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); 868 raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1));
869 } 869 }
@@ -911,7 +911,7 @@ bool InterCopyContext::interCopyFunction() const
911 lua_getupvalue(L1, L1_i, 2); // L1: ... u 911 lua_getupvalue(L1, L1_i, 2); // L1: ... u
912 void* _source{ lua_touserdata(L1, -1) }; 912 void* _source{ lua_touserdata(L1, -1) };
913 lua_pushlightuserdata(L2, _source); // L2: ... source 913 lua_pushlightuserdata(L2, _source); // L2: ... source
914 if (luaG_rawget(L2, L2_cache_i) != LuaType::NIL) { // L2: ... u? 914 if (luaW_rawget(L2, L2_cache_i) != LuaType::NIL) { // L2: ... u?
915 lua_pop(L1, 1); // L1: ... 915 lua_pop(L1, 1); // L1: ...
916 STACK_CHECK(L1, 0); 916 STACK_CHECK(L1, 0);
917 STACK_CHECK(L2, 1); 917 STACK_CHECK(L2, 1);
@@ -933,7 +933,7 @@ bool InterCopyContext::interCopyFunction() const
933 auto const _userdata_size{ static_cast<size_t>(lua_rawlen(L1, kIdxTop)) }; // make 32-bits builds happy 933 auto const _userdata_size{ static_cast<size_t>(lua_rawlen(L1, kIdxTop)) }; // make 32-bits builds happy
934 { 934 {
935 // extract uservalues (don't transfer them yet) 935 // extract uservalues (don't transfer them yet)
936 UserValueCount const _nuv{ luaG_getalluservalues(L1, source_i) }; // L1: ... u [uv]* 936 UserValueCount const _nuv{ luaW_getalluservalues(L1, source_i) }; // L1: ... u [uv]*
937 STACK_CHECK(L1, _nuv + 1); 937 STACK_CHECK(L1, _nuv + 1);
938 // create the clone userdata with the required number of uservalue slots 938 // create the clone userdata with the required number of uservalue slots
939 _clone = lua_newuserdatauv(L2, _userdata_size, _nuv); // L2: ... mt u 939 _clone = lua_newuserdatauv(L2, _userdata_size, _nuv); // L2: ... mt u
@@ -948,7 +948,7 @@ bool InterCopyContext::interCopyFunction() const
948 InterCopyContext _c{ *this }; 948 InterCopyContext _c{ *this };
949 UserValueIndex _uvi{ _nuv.value() }; 949 UserValueIndex _uvi{ _nuv.value() };
950 while (_uvi > 0) { 950 while (_uvi > 0) {
951 _c.L1_i = SourceIndex{ luaG_absindex(L1, kIdxTop).value() }; 951 _c.L1_i = SourceIndex{ luaW_absindex(L1, kIdxTop).value() };
952 if (_c.interCopyOne() != InterCopyResult::Success) { // L2: ... mt u uv 952 if (_c.interCopyOne() != InterCopyResult::Success) { // L2: ... mt u uv
953 raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); 953 raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1));
954 } 954 }
@@ -965,9 +965,9 @@ bool InterCopyContext::interCopyFunction() const
965 // perform the custom cloning part 965 // perform the custom cloning part
966 lua_insert(L2, -2); // L2: ... u mt 966 lua_insert(L2, -2); // L2: ... u mt
967 // __lanesclone should always exist because we wouldn't be restoring data from a userdata_clone_sentinel closure to begin with 967 // __lanesclone should always exist because we wouldn't be restoring data from a userdata_clone_sentinel closure to begin with
968 LuaType const _funcType{ luaG_getfield(L2, kIdxTop, "__lanesclone") }; // L2: ... u mt __lanesclone 968 LuaType const _funcType{ luaW_getfield(L2, kIdxTop, "__lanesclone") }; // L2: ... u mt __lanesclone
969 if (_funcType != LuaType::FUNCTION) { 969 if (_funcType != LuaType::FUNCTION) {
970 raise_luaL_error(getErrL(), "INTERNAL ERROR: __lanesclone is a %s, not a function", luaG_typename(L2, _funcType).data()); 970 raise_luaL_error(getErrL(), "INTERNAL ERROR: __lanesclone is a %s, not a function", luaW_typename(L2, _funcType).data());
971 } 971 }
972 lua_remove(L2, -2); // L2: ... u __lanesclone 972 lua_remove(L2, -2); // L2: ... u __lanesclone
973 lua_pushlightuserdata(L2, _clone); // L2: ... u __lanesclone clone 973 lua_pushlightuserdata(L2, _clone); // L2: ... u __lanesclone clone
@@ -1060,9 +1060,9 @@ bool InterCopyContext::interCopyNumber() const
1060[[nodiscard]] 1060[[nodiscard]]
1061bool InterCopyContext::interCopyString() const 1061bool InterCopyContext::interCopyString() const
1062{ 1062{
1063 std::string_view const _s{ luaG_tostring(L1, L1_i) }; 1063 std::string_view const _s{ luaW_tostring(L1, L1_i) };
1064 DEBUGSPEW_CODE(DebugSpew(nullptr) << "'" << _s << "'" << std::endl); 1064 DEBUGSPEW_CODE(DebugSpew(nullptr) << "'" << _s << "'" << std::endl);
1065 luaG_pushstring(L2, _s); 1065 luaW_pushstring(L2, _s);
1066 return true; 1066 return true;
1067} 1067}
1068 1068
@@ -1154,7 +1154,7 @@ bool InterCopyContext::interCopyUserdata() const
1154 1154
1155 // Last, let's try to see if this userdata is special (aka is it some userdata that we registered in our lookup databases during module registration?) 1155 // Last, let's try to see if this userdata is special (aka is it some userdata that we registered in our lookup databases during module registration?)
1156 if (lookupUserdata()) { 1156 if (lookupUserdata()) {
1157 LUA_ASSERT(L1, luaG_type(L2, kIdxTop) == LuaType::USERDATA || (lua_tocfunction(L2, kIdxTop) == userdata_lookup_sentinel)); // from lookup data. can also be userdata_lookup_sentinel if this is a userdata we know 1157 LUA_ASSERT(L1, luaW_type(L2, kIdxTop) == LuaType::USERDATA || (lua_tocfunction(L2, kIdxTop) == userdata_lookup_sentinel)); // from lookup data. can also be userdata_lookup_sentinel if this is a userdata we know
1158 return true; 1158 return true;
1159 } 1159 }
1160 1160
@@ -1291,8 +1291,8 @@ InterCopyResult InterCopyContext::interCopyPackage() const
1291 } const _onExit{ L2 }; 1291 } const _onExit{ L2 };
1292 1292
1293 STACK_CHECK_START_REL(L1, 0); 1293 STACK_CHECK_START_REL(L1, 0);
1294 if (luaG_type(L1, L1_i) != LuaType::TABLE) { 1294 if (luaW_type(L1, L1_i) != LuaType::TABLE) {
1295 std::string_view const _msg{ luaG_pushstring(L1, "expected package as table, got a %s", luaL_typename(L1, L1_i)) }; 1295 std::string_view const _msg{ luaW_pushstring(L1, "expected package as table, got a %s", luaL_typename(L1, L1_i)) };
1296 STACK_CHECK(L1, 1); 1296 STACK_CHECK(L1, 1);
1297 // raise the error when copying from lane to lane, else just leave it on the stack to be raised later 1297 // raise the error when copying from lane to lane, else just leave it on the stack to be raised later
1298 if (mode == LookupMode::LaneBody) { 1298 if (mode == LookupMode::LaneBody) {
@@ -1300,7 +1300,7 @@ InterCopyResult InterCopyContext::interCopyPackage() const
1300 } 1300 }
1301 return InterCopyResult::Error; 1301 return InterCopyResult::Error;
1302 } 1302 }
1303 if (luaG_getmodule(L2, LUA_LOADLIBNAME) == LuaType::NIL) { // package library not loaded: do nothing 1303 if (luaW_getmodule(L2, LUA_LOADLIBNAME) == LuaType::NIL) { // package library not loaded: do nothing
1304 DEBUGSPEW_CODE(DebugSpew(U) << "'package' not loaded, nothing to do" << std::endl); 1304 DEBUGSPEW_CODE(DebugSpew(U) << "'package' not loaded, nothing to do" << std::endl);
1305 STACK_CHECK(L1, 0); 1305 STACK_CHECK(L1, 0);
1306 return InterCopyResult::Success; 1306 return InterCopyResult::Success;
@@ -1317,7 +1317,7 @@ InterCopyResult InterCopyContext::interCopyPackage() const
1317 continue; 1317 continue;
1318 } 1318 }
1319 DEBUGSPEW_CODE(DebugSpew(U) << "package." << _entry << std::endl); 1319 DEBUGSPEW_CODE(DebugSpew(U) << "package." << _entry << std::endl);
1320 if (luaG_getfield(L1, L1_i, _entry) == LuaType::NIL) { 1320 if (luaW_getfield(L1, L1_i, _entry) == LuaType::NIL) {
1321 lua_pop(L1, 1); 1321 lua_pop(L1, 1);
1322 } else { 1322 } else {
1323 { 1323 {
@@ -1328,9 +1328,9 @@ InterCopyResult InterCopyContext::interCopyPackage() const
1328 STACK_CHECK(L1, 0); 1328 STACK_CHECK(L1, 0);
1329 } 1329 }
1330 if (_result == InterCopyResult::Success) { 1330 if (_result == InterCopyResult::Success) {
1331 luaG_setfield(L2, StackIndex{ -2 }, _entry); // set package[entry] 1331 luaW_setfield(L2, StackIndex{ -2 }, _entry); // set package[entry]
1332 } else { 1332 } else {
1333 std::string_view const _msg{ luaG_pushstring(L1, "failed to copy package.%s", _entry.data()) }; 1333 std::string_view const _msg{ luaW_pushstring(L1, "failed to copy package.%s", _entry.data()) };
1334 // raise the error when copying from lane to lane, else just leave it on the stack to be raised later 1334 // raise the error when copying from lane to lane, else just leave it on the stack to be raised later
1335 if (mode == LookupMode::LaneBody) { 1335 if (mode == LookupMode::LaneBody) {
1336 raise_luaL_error(getErrL(), _msg); 1336 raise_luaL_error(getErrL(), _msg);