diff options
Diffstat (limited to 'src/intercopycontext.cpp')
-rw-r--r-- | src/intercopycontext.cpp | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index 670b955..aa802d5 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp | |||
@@ -100,7 +100,7 @@ THE SOFTWARE. | |||
100 | lua_pushvalue(L1, L1_i); // L1: ... v ... {} v | 100 | lua_pushvalue(L1, L1_i); // L1: ... v ... {} v |
101 | lua_rawget(L1, -2); // L1: ... v ... {} "f.q.n" | 101 | lua_rawget(L1, -2); // L1: ... v ... {} "f.q.n" |
102 | } | 102 | } |
103 | std::string_view _fqn{ lua_tostringview(L1, -1) }; | 103 | std::string_view _fqn{ luaG_tostringview(L1, -1) }; |
104 | DEBUGSPEW_CODE(DebugSpew(Universe::Get(L1)) << "function [C] " << _fqn << std::endl); | 104 | DEBUGSPEW_CODE(DebugSpew(Universe::Get(L1)) << "function [C] " << _fqn << std::endl); |
105 | // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database | 105 | // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database |
106 | lua_pop(L1, (mode == LookupMode::FromKeeper) ? 1 : 2); // L1: ... v ... | 106 | lua_pop(L1, (mode == LookupMode::FromKeeper) ? 1 : 2); // L1: ... v ... |
@@ -113,7 +113,7 @@ THE SOFTWARE. | |||
113 | lua_pushcfunction(L1, LG_nameof); // L1: ... v ... lane_name LG_nameof | 113 | lua_pushcfunction(L1, LG_nameof); // L1: ... v ... lane_name LG_nameof |
114 | lua_pushvalue(L1, L1_i); // L1: ... v ... lane_name LG_nameof t | 114 | lua_pushvalue(L1, L1_i); // L1: ... v ... lane_name LG_nameof t |
115 | lua_call(L1, 1, 2); // L1: ... v ... lane_name "type" "name"|nil | 115 | lua_call(L1, 1, 2); // L1: ... v ... lane_name "type" "name"|nil |
116 | char const* _typewhat{ (lua_type(L1, -2) == LUA_TSTRING) ? lua_tostring(L1, -2) : luaL_typename(L1, -2) }; | 116 | char const* _typewhat{ (luaG_type(L1, -2) == LuaType::STRING) ? lua_tostring(L1, -2) : luaL_typename(L1, -2) }; |
117 | // second return value can be nil if the table was not found | 117 | // second return value can be nil if the table was not found |
118 | // probable reason: the function was removed from the source Lua state before Lanes was required. | 118 | // probable reason: the function was removed from the source Lua state before Lanes was required. |
119 | char const *_what, *_gotchaA, *_gotchaB; | 119 | char const *_what, *_gotchaA, *_gotchaB; |
@@ -124,7 +124,7 @@ THE SOFTWARE. | |||
124 | } else { | 124 | } else { |
125 | _gotchaA = ""; | 125 | _gotchaA = ""; |
126 | _gotchaB = ""; | 126 | _gotchaB = ""; |
127 | _what = (lua_type(L1, -1) == LUA_TSTRING) ? lua_tostring(L1, -1) : luaL_typename(L1, -1); | 127 | _what = (luaG_type(L1, -1) == LuaType::STRING) ? lua_tostring(L1, -1) : luaL_typename(L1, -1); |
128 | } | 128 | } |
129 | raise_luaL_error(L1, "%s%s '%s' not found in %s origin transfer database.%s", _typewhat, _gotchaA, _what, _from ? _from : "main", _gotchaB); | 129 | raise_luaL_error(L1, "%s%s '%s' not found in %s origin transfer database.%s", _typewhat, _gotchaA, _what, _from ? _from : "main", _gotchaB); |
130 | } | 130 | } |
@@ -196,7 +196,7 @@ void InterCopyContext::copy_func() const | |||
196 | // not sure this could ever fail but for memory shortage reasons | 196 | // not sure this could ever fail but for memory shortage reasons |
197 | // last parameter is Lua 5.4-specific (no stripping) | 197 | // last parameter is Lua 5.4-specific (no stripping) |
198 | luaL_Buffer B{}; | 198 | luaL_Buffer B{}; |
199 | if (lua504_dump(L1, buf_writer, &B, U->stripFunctions) != 0) { | 199 | if (luaG_dump(L1, buf_writer, &B, U->stripFunctions) != 0) { |
200 | raise_luaL_error(getErrL(), "internal error: function dump failed."); | 200 | raise_luaL_error(getErrL(), "internal error: function dump failed."); |
201 | } | 201 | } |
202 | 202 | ||
@@ -224,7 +224,7 @@ void InterCopyContext::copy_func() const | |||
224 | } | 224 | } |
225 | 225 | ||
226 | { | 226 | { |
227 | std::string_view const _bytecode{ lua_tostringview(L1, -1) }; // L1: ... b | 227 | std::string_view const _bytecode{ luaG_tostringview(L1, -1) }; // L1: ... b |
228 | LUA_ASSERT(L1, !_bytecode.empty()); | 228 | LUA_ASSERT(L1, !_bytecode.empty()); |
229 | STACK_GROW(L2, 2); | 229 | STACK_GROW(L2, 2); |
230 | // Note: Line numbers seem to be taken precisely from the | 230 | // Note: Line numbers seem to be taken precisely from the |
@@ -313,7 +313,7 @@ void InterCopyContext::lookup_native_func() const | |||
313 | 313 | ||
314 | case LookupMode::ToKeeper: | 314 | case LookupMode::ToKeeper: |
315 | // push a sentinel closure that holds the lookup name as upvalue | 315 | // push a sentinel closure that holds the lookup name as upvalue |
316 | std::ignore = lua_pushstringview(L2, _fqn); // L1: ... f ... L2: "f.q.n" | 316 | std::ignore = luaG_pushstringview(L2, _fqn); // L1: ... f ... L2: "f.q.n" |
317 | lua_pushcclosure(L2, func_lookup_sentinel, 1); // L1: ... f ... L2: f | 317 | lua_pushcclosure(L2, func_lookup_sentinel, 1); // L1: ... f ... L2: f |
318 | break; | 318 | break; |
319 | 319 | ||
@@ -322,7 +322,7 @@ void InterCopyContext::lookup_native_func() const | |||
322 | kLookupRegKey.pushValue(L2); // L1: ... f ... L2: {} | 322 | kLookupRegKey.pushValue(L2); // L1: ... f ... L2: {} |
323 | STACK_CHECK(L2, 1); | 323 | STACK_CHECK(L2, 1); |
324 | LUA_ASSERT(L1, lua_istable(L2, -1)); | 324 | LUA_ASSERT(L1, lua_istable(L2, -1)); |
325 | std::ignore = lua_pushstringview(L2, _fqn); // L1: ... f ... L2: {} "f.q.n" | 325 | std::ignore = luaG_pushstringview(L2, _fqn); // L1: ... f ... L2: {} "f.q.n" |
326 | lua_rawget(L2, -2); // L1: ... f ... L2: {} f | 326 | lua_rawget(L2, -2); // L1: ... f ... L2: {} f |
327 | // nil means we don't know how to transfer stuff: user should do something | 327 | // nil means we don't know how to transfer stuff: user should do something |
328 | // anything other than function or table should not happen! | 328 | // anything other than function or table should not happen! |
@@ -388,7 +388,7 @@ void InterCopyContext::copy_cached_func() const | |||
388 | // push a light userdata uniquely representing the function | 388 | // push a light userdata uniquely representing the function |
389 | lua_pushlightuserdata(L2, _aspointer); // L2: ... {cache} ... p | 389 | lua_pushlightuserdata(L2, _aspointer); // L2: ... {cache} ... p |
390 | 390 | ||
391 | //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << lua_tostringview(L2, -1) << " >>" << std::endl); | 391 | //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaG_tostringview(L2, -1) << " >>" << std::endl); |
392 | 392 | ||
393 | lua_pushvalue(L2, -1); // L2: ... {cache} ... p p | 393 | lua_pushvalue(L2, -1); // L2: ... {cache} ... p p |
394 | lua_rawget(L2, L2_cache_i); // L2: ... {cache} ... p function|nil|true | 394 | lua_rawget(L2, L2_cache_i); // L2: ... {cache} ... p function|nil|true |
@@ -433,7 +433,7 @@ void InterCopyContext::copy_cached_func() const | |||
433 | 433 | ||
434 | case LookupMode::ToKeeper: | 434 | case LookupMode::ToKeeper: |
435 | // push a sentinel closure that holds the lookup name as upvalue | 435 | // push a sentinel closure that holds the lookup name as upvalue |
436 | std::ignore = lua_pushstringview(L2, _fqn); // L1: ... t ... L2: "f.q.n" | 436 | std::ignore = luaG_pushstringview(L2, _fqn); // L1: ... t ... L2: "f.q.n" |
437 | lua_pushcclosure(L2, table_lookup_sentinel, 1); // L1: ... t ... L2: f | 437 | lua_pushcclosure(L2, table_lookup_sentinel, 1); // L1: ... t ... L2: f |
438 | break; | 438 | break; |
439 | 439 | ||
@@ -442,7 +442,7 @@ void InterCopyContext::copy_cached_func() const | |||
442 | kLookupRegKey.pushValue(L2); // L1: ... t ... L2: {} | 442 | kLookupRegKey.pushValue(L2); // L1: ... t ... L2: {} |
443 | STACK_CHECK(L2, 1); | 443 | STACK_CHECK(L2, 1); |
444 | LUA_ASSERT(L1, lua_istable(L2, -1)); | 444 | LUA_ASSERT(L1, lua_istable(L2, -1)); |
445 | std::ignore = lua_pushstringview(L2, _fqn); // L2: {} "f.q.n" | 445 | std::ignore = luaG_pushstringview(L2, _fqn); // L2: {} "f.q.n" |
446 | lua_rawget(L2, -2); // L2: {} t | 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) | 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) |
448 | // but not when we extract something out of a keeper, as there is nothing to clone! | 448 | // but not when we extract something out of a keeper, as there is nothing to clone! |
@@ -462,7 +462,7 @@ void InterCopyContext::copy_cached_func() const | |||
462 | "%s: source table '%s' found as %s in %s destination transfer database.", | 462 | "%s: source table '%s' found as %s in %s destination transfer database.", |
463 | _from ? _from : "main", | 463 | _from ? _from : "main", |
464 | _fqn, | 464 | _fqn, |
465 | lua_typename(L2, lua_type_as_enum(L2, -1)), | 465 | luaG_typename(L2, luaG_type(L2, -1)), |
466 | _to ? _to : "main"); | 466 | _to ? _to : "main"); |
467 | } | 467 | } |
468 | lua_remove(L2, -2); // L1: ... t ... L2: t | 468 | lua_remove(L2, -2); // L1: ... t ... L2: t |
@@ -491,8 +491,8 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
491 | char* _valPath{ nullptr }; | 491 | char* _valPath{ nullptr }; |
492 | if (U->verboseErrors) { | 492 | if (U->verboseErrors) { |
493 | // for debug purposes, let's try to build a useful name | 493 | // for debug purposes, let's try to build a useful name |
494 | if (lua_type(L1, _key_i) == LUA_TSTRING) { | 494 | if (luaG_type(L1, _key_i) == LuaType::STRING) { |
495 | std::string_view const _key{ lua_tostringview(L1, _key_i) }; | 495 | std::string_view const _key{ luaG_tostringview(L1, _key_i) }; |
496 | size_t const _bufLen{ strlen(name) + _key.size() + 2 }; // +2 for separator dot and terminating 0 | 496 | size_t const _bufLen{ strlen(name) + _key.size() + 2 }; // +2 for separator dot and terminating 0 |
497 | _valPath = static_cast<char*>(alloca(_bufLen)); | 497 | _valPath = static_cast<char*>(alloca(_bufLen)); |
498 | sprintf(_valPath, "%s." STRINGVIEW_FMT, name, (int) _key.size(), _key.data()); | 498 | sprintf(_valPath, "%s." STRINGVIEW_FMT, name, (int) _key.size(), _key.data()); |
@@ -504,15 +504,15 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
504 | sprintf(_valPath, "%s[" LUA_INTEGER_FMT "]", name, key); | 504 | sprintf(_valPath, "%s[" LUA_INTEGER_FMT "]", name, key); |
505 | } | 505 | } |
506 | #endif // defined LUA_LNUM || LUA_VERSION_NUM >= 503 | 506 | #endif // defined LUA_LNUM || LUA_VERSION_NUM >= 503 |
507 | else if (lua_type(L1, _key_i) == LUA_TNUMBER) { | 507 | else if (luaG_type(L1, _key_i) == LuaType::NUMBER) { |
508 | lua_Number const key{ lua_tonumber(L1, _key_i) }; | 508 | lua_Number const key{ lua_tonumber(L1, _key_i) }; |
509 | _valPath = (char*) alloca(strlen(name) + 32 + 3); // +3 for [] and terminating 0 | 509 | _valPath = (char*) alloca(strlen(name) + 32 + 3); // +3 for [] and terminating 0 |
510 | sprintf(_valPath, "%s[" LUA_NUMBER_FMT "]", name, key); | 510 | sprintf(_valPath, "%s[" LUA_NUMBER_FMT "]", name, key); |
511 | } else if (lua_type(L1, _key_i) == LUA_TLIGHTUSERDATA) { | 511 | } else if (luaG_type(L1, _key_i) == LuaType::LIGHTUSERDATA) { |
512 | void* const key{ lua_touserdata(L1, _key_i) }; | 512 | void* const key{ lua_touserdata(L1, _key_i) }; |
513 | _valPath = (char*) alloca(strlen(name) + 16 + 5); // +5 for [U:] and terminating 0 | 513 | _valPath = (char*) alloca(strlen(name) + 16 + 5); // +5 for [U:] and terminating 0 |
514 | sprintf(_valPath, "%s[U:%p]", name, key); | 514 | sprintf(_valPath, "%s[U:%p]", name, key); |
515 | } else if (lua_type(L1, _key_i) == LUA_TBOOLEAN) { | 515 | } else if (luaG_type(L1, _key_i) == LuaType::BOOLEAN) { |
516 | int const key{ lua_toboolean(L1, _key_i) }; | 516 | int const key{ lua_toboolean(L1, _key_i) }; |
517 | _valPath = (char*) alloca(strlen(name) + 8); // +8 for [], 'false' and terminating 0 | 517 | _valPath = (char*) alloca(strlen(name) + 8); // +8 for [], 'false' and terminating 0 |
518 | sprintf(_valPath, "%s[%s]", name, key ? "true" : "false"); | 518 | sprintf(_valPath, "%s[%s]", name, key ? "true" : "false"); |
@@ -597,7 +597,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
597 | // push a light userdata uniquely representing the table | 597 | // push a light userdata uniquely representing the table |
598 | lua_pushlightuserdata(L2, const_cast<void*>(_p)); // L1: ... t ... L2: ... p | 598 | lua_pushlightuserdata(L2, const_cast<void*>(_p)); // L1: ... t ... L2: ... p |
599 | 599 | ||
600 | //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << lua_tostringview(L2, -1) << " >>" << std::endl); | 600 | //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaG_tostringview(L2, -1) << " >>" << std::endl); |
601 | 601 | ||
602 | lua_rawget(L2, L2_cache_i); // L1: ... t ... L2: ... {cached|nil} | 602 | lua_rawget(L2, L2_cache_i); // L1: ... t ... L2: ... {cached|nil} |
603 | bool const _not_found_in_cache{ lua_isnil(L2, -1) }; | 603 | bool const _not_found_in_cache{ lua_isnil(L2, -1) }; |
@@ -940,9 +940,9 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
940 | 940 | ||
941 | [[nodiscard]] bool InterCopyContext::inter_copy_string() const | 941 | [[nodiscard]] bool InterCopyContext::inter_copy_string() const |
942 | { | 942 | { |
943 | std::string_view const _s{ lua_tostringview(L1, L1_i) }; | 943 | std::string_view const _s{ luaG_tostringview(L1, L1_i) }; |
944 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "'" << _s << "'" << std::endl); | 944 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "'" << _s << "'" << std::endl); |
945 | std::ignore = lua_pushstringview(L2, _s); | 945 | std::ignore = luaG_pushstringview(L2, _s); |
946 | return true; | 946 | return true; |
947 | } | 947 | } |
948 | 948 | ||
@@ -1094,7 +1094,7 @@ namespace { | |||
1094 | DEBUGSPEW_CODE(DebugSpew(U) << "inter_copy_one()" << std::endl); | 1094 | DEBUGSPEW_CODE(DebugSpew(U) << "inter_copy_one()" << std::endl); |
1095 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); | 1095 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); |
1096 | 1096 | ||
1097 | LuaType _val_type{ lua_type_as_enum(L1, L1_i) }; | 1097 | LuaType _val_type{ luaG_type(L1, L1_i) }; |
1098 | DEBUGSPEW_CODE(DebugSpew(U) << local::sLuaTypeNames[static_cast<int>(_val_type)] << " " << local::sValueTypeNames[static_cast<int>(vt)] << ": "); | 1098 | DEBUGSPEW_CODE(DebugSpew(U) << local::sLuaTypeNames[static_cast<int>(_val_type)] << " " << local::sValueTypeNames[static_cast<int>(vt)] << ": "); |
1099 | 1099 | ||
1100 | // Non-POD can be skipped if its metatable contains { __lanesignore = true } | 1100 | // Non-POD can be skipped if its metatable contains { __lanesignore = true } |
@@ -1187,7 +1187,7 @@ namespace { | |||
1187 | } const _onExit{ L2 }; | 1187 | } const _onExit{ L2 }; |
1188 | 1188 | ||
1189 | STACK_CHECK_START_REL(L1, 0); | 1189 | STACK_CHECK_START_REL(L1, 0); |
1190 | if (lua_type_as_enum(L1, L1_i) != LuaType::TABLE) { | 1190 | if (luaG_type(L1, L1_i) != LuaType::TABLE) { |
1191 | lua_pushfstring(L1, "expected package as table, got %s", luaL_typename(L1, L1_i)); | 1191 | lua_pushfstring(L1, "expected package as table, got %s", luaL_typename(L1, L1_i)); |
1192 | STACK_CHECK(L1, 1); | 1192 | STACK_CHECK(L1, 1); |
1193 | // raise the error when copying from lane to lane, else just leave it on the stack to be raised later | 1193 | // raise the error when copying from lane to lane, else just leave it on the stack to be raised later |