diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-11 16:53:51 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-11 16:53:51 +0200 |
commit | f832d198579998dbc56d56944e0a69ff5e4ec307 (patch) | |
tree | 05c0bdc2060ddb627f693a81e04416703b06f27e /src | |
parent | fcc9a37e2e389ff1c58cbab4afd76eacc502d834 (diff) | |
download | lanes-f832d198579998dbc56d56944e0a69ff5e4ec307.tar.gz lanes-f832d198579998dbc56d56944e0a69ff5e4ec307.tar.bz2 lanes-f832d198579998dbc56d56944e0a69ff5e4ec307.zip |
More application of the coding rules
Diffstat (limited to 'src')
-rw-r--r-- | src/intercopycontext.cpp | 146 | ||||
-rw-r--r-- | src/intercopycontext.h | 40 | ||||
-rw-r--r-- | src/keeper.cpp | 14 | ||||
-rw-r--r-- | src/lane.cpp | 4 | ||||
-rw-r--r-- | src/lanes.cpp | 14 | ||||
-rw-r--r-- | src/state.cpp | 2 |
6 files changed, 112 insertions, 108 deletions
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index 5be4304..8c9a026 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp | |||
@@ -177,7 +177,7 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull }; | |||
177 | 177 | ||
178 | // Copy a function over, which has not been found in the cache. | 178 | // Copy a function over, which has not been found in the cache. |
179 | // L2 has the cache key for this function at the top of the stack | 179 | // L2 has the cache key for this function at the top of the stack |
180 | void InterCopyContext::copy_func() const | 180 | void InterCopyContext::copyFunction() const |
181 | { | 181 | { |
182 | LUA_ASSERT(L1, L2_cache_i != 0); // L2: ... {cache} ... p | 182 | LUA_ASSERT(L1, L2_cache_i != 0); // L2: ... {cache} ... p |
183 | STACK_GROW(L1, 2); | 183 | STACK_GROW(L1, 2); |
@@ -271,7 +271,7 @@ void InterCopyContext::copy_func() const | |||
271 | } else { | 271 | } else { |
272 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "copying value" << std::endl); | 272 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "copying value" << std::endl); |
273 | _c.L1_i = SourceIndex{ lua_gettop(L1) }; | 273 | _c.L1_i = SourceIndex{ lua_gettop(L1) }; |
274 | if (!_c.inter_copy_one()) { // L2: ... {cache} ... function <upvalues> | 274 | if (_c.interCopyOne() != InterCopyResult::Success) { // L2: ... {cache} ... function <upvalues> |
275 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); | 275 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); |
276 | } | 276 | } |
277 | } | 277 | } |
@@ -299,7 +299,7 @@ void InterCopyContext::copy_func() const | |||
299 | // ################################################################################################# | 299 | // ################################################################################################# |
300 | 300 | ||
301 | // Push a looked-up native/LuaJIT function. | 301 | // Push a looked-up native/LuaJIT function. |
302 | void InterCopyContext::lookup_native_func() const | 302 | void InterCopyContext::lookupNativeFunction() const |
303 | { | 303 | { |
304 | // get the name of the function we want to send | 304 | // get the name of the function we want to send |
305 | std::string_view const _fqn{ findLookupName() }; | 305 | std::string_view const _fqn{ findLookupName() }; |
@@ -368,7 +368,7 @@ void InterCopyContext::lookup_native_func() const | |||
368 | 368 | ||
369 | // Check if we've already copied the same function from 'L1', and reuse the old copy. | 369 | // Check if we've already copied the same function from 'L1', and reuse the old copy. |
370 | // Always pushes a function to 'L2'. | 370 | // Always pushes a function to 'L2'. |
371 | void InterCopyContext::copy_cached_func() const | 371 | void InterCopyContext::copyCachedFunction() const |
372 | { | 372 | { |
373 | FuncSubType const _funcSubType{ luaG_getfuncsubtype(L1, L1_i) }; | 373 | FuncSubType const _funcSubType{ luaG_getfuncsubtype(L1, L1_i) }; |
374 | if (_funcSubType == FuncSubType::Bytecode) { | 374 | if (_funcSubType == FuncSubType::Bytecode) { |
@@ -400,14 +400,14 @@ void InterCopyContext::copy_cached_func() const | |||
400 | // via upvalues | 400 | // via upvalues |
401 | // | 401 | // |
402 | // pushes a copy of the func, stores a reference in the cache | 402 | // pushes a copy of the func, stores a reference in the cache |
403 | copy_func(); // L2: ... {cache} ... function | 403 | copyFunction(); // L2: ... {cache} ... function |
404 | } else { // found function in the cache | 404 | } else { // found function in the cache |
405 | lua_remove(L2, -2); // L2: ... {cache} ... function | 405 | lua_remove(L2, -2); // L2: ... {cache} ... function |
406 | } | 406 | } |
407 | STACK_CHECK(L2, 1); | 407 | STACK_CHECK(L2, 1); |
408 | LUA_ASSERT(L1, lua_isfunction(L2, -1)); | 408 | LUA_ASSERT(L1, lua_isfunction(L2, -1)); |
409 | } else { // function is native/LuaJIT: no need to cache | 409 | } else { // function is native/LuaJIT: no need to cache |
410 | lookup_native_func(); // L2: ... {cache} ... function | 410 | lookupNativeFunction(); // L2: ... {cache} ... function |
411 | // if the function was in fact a lookup sentinel, we can either get a function or a table here | 411 | // if the function was in fact a lookup sentinel, we can either get a function or a table here |
412 | LUA_ASSERT(L1, lua_isfunction(L2, -1) || lua_istable(L2, -1)); | 412 | LUA_ASSERT(L1, lua_isfunction(L2, -1) || lua_istable(L2, -1)); |
413 | } | 413 | } |
@@ -416,7 +416,7 @@ void InterCopyContext::copy_cached_func() const | |||
416 | // ################################################################################################# | 416 | // ################################################################################################# |
417 | 417 | ||
418 | // Push a looked-up table, or nothing if we found nothing | 418 | // Push a looked-up table, or nothing if we found nothing |
419 | [[nodiscard]] bool InterCopyContext::lookup_table() const | 419 | [[nodiscard]] bool InterCopyContext::lookupTable() const |
420 | { | 420 | { |
421 | // get the name of the table we want to send | 421 | // get the name of the table we want to send |
422 | std::string_view const _fqn{ findLookupName() }; | 422 | std::string_view const _fqn{ findLookupName() }; |
@@ -474,14 +474,14 @@ void InterCopyContext::copy_cached_func() const | |||
474 | 474 | ||
475 | // ################################################################################################# | 475 | // ################################################################################################# |
476 | 476 | ||
477 | void InterCopyContext::inter_copy_keyvaluepair() const | 477 | void InterCopyContext::interCopyKeyValuePair() const |
478 | { | 478 | { |
479 | SourceIndex const _val_i{ lua_gettop(L1) }; | 479 | SourceIndex const _val_i{ lua_gettop(L1) }; |
480 | SourceIndex const _key_i{ _val_i - 1 }; | 480 | SourceIndex const _key_i{ _val_i - 1 }; |
481 | 481 | ||
482 | // For the key, only basic key types are copied over. others ignored | 482 | // For the key, only basic key types are copied over. others ignored |
483 | InterCopyContext _c{ U, L2, L1, L2_cache_i, _key_i, VT::KEY, mode, name }; | 483 | InterCopyContext _c{ U, L2, L1, L2_cache_i, _key_i, VT::KEY, mode, name }; |
484 | if (!_c.inter_copy_one()) { | 484 | if (_c.interCopyOne() != InterCopyResult::Success) { |
485 | return; | 485 | return; |
486 | // we could raise an error instead of ignoring the table entry, like so: | 486 | // we could raise an error instead of ignoring the table entry, like so: |
487 | // raise_luaL_error(L1, "Unable to copy %s key '%s' because of value is of type '%s'", (vt == VT::NORMAL) ? "table" : "metatable", name, luaL_typename(L1, key_i)); | 487 | // raise_luaL_error(L1, "Unable to copy %s key '%s' because of value is of type '%s'", (vt == VT::NORMAL) ? "table" : "metatable", name, luaL_typename(L1, key_i)); |
@@ -518,16 +518,16 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
518 | sprintf(_valPath, "%s[%s]", name, key ? "true" : "false"); | 518 | sprintf(_valPath, "%s[%s]", name, key ? "true" : "false"); |
519 | } | 519 | } |
520 | } | 520 | } |
521 | |||
521 | _c.L1_i = SourceIndex{ _val_i }; | 522 | _c.L1_i = SourceIndex{ _val_i }; |
522 | // Contents of metatables are copied with cache checking. important to detect loops. | 523 | // Contents of metatables are copied with cache checking. important to detect loops. |
523 | _c.vt = VT::NORMAL; | 524 | _c.vt = VT::NORMAL; |
524 | _c.name = _valPath ? _valPath : name; | 525 | _c.name = _valPath ? _valPath : name; |
525 | if (_c.inter_copy_one()) { | 526 | if (_c.interCopyOne() != InterCopyResult::Success) { |
526 | LUA_ASSERT(L1, lua_istable(L2, -3)); | ||
527 | lua_rawset(L2, -3); // add to table (pops key & val) | ||
528 | } else { | ||
529 | raise_luaL_error(getErrL(), "Unable to copy %s entry '%s' because of value is of type '%s'", (vt == VT::NORMAL) ? "table" : "metatable", _valPath, luaL_typename(L1, _val_i)); | 527 | raise_luaL_error(getErrL(), "Unable to copy %s entry '%s' because of value is of type '%s'", (vt == VT::NORMAL) ? "table" : "metatable", _valPath, luaL_typename(L1, _val_i)); |
530 | } | 528 | } |
529 | LUA_ASSERT(L1, lua_istable(L2, -3)); | ||
530 | lua_rawset(L2, -3); // add to table (pops key & val) | ||
531 | } | 531 | } |
532 | 532 | ||
533 | // ################################################################################################# | 533 | // ################################################################################################# |
@@ -602,7 +602,7 @@ LuaType InterCopyContext::processConversion() const | |||
602 | 602 | ||
603 | // ################################################################################################# | 603 | // ################################################################################################# |
604 | 604 | ||
605 | [[nodiscard]] bool InterCopyContext::push_cached_metatable() const | 605 | [[nodiscard]] bool InterCopyContext::pushCachedMetatable() const |
606 | { | 606 | { |
607 | STACK_CHECK_START_REL(L1, 0); | 607 | STACK_CHECK_START_REL(L1, 0); |
608 | if (!lua_getmetatable(L1, L1_i)) { // L1: ... mt | 608 | if (!lua_getmetatable(L1, L1_i)) { // L1: ... mt |
@@ -623,8 +623,8 @@ LuaType InterCopyContext::processConversion() const | |||
623 | 623 | ||
624 | if (lua_isnil(L2, -1)) { // L2 did not know the metatable | 624 | if (lua_isnil(L2, -1)) { // L2 did not know the metatable |
625 | lua_pop(L2, 1); // L2: _R[kMtIdRegKey] | 625 | lua_pop(L2, 1); // L2: _R[kMtIdRegKey] |
626 | InterCopyContext const c{ U, L2, L1, L2_cache_i, SourceIndex{ lua_gettop(L1) }, VT::METATABLE, mode, name }; | 626 | InterCopyContext const _c{ U, L2, L1, L2_cache_i, SourceIndex{ lua_gettop(L1) }, VT::METATABLE, mode, name }; |
627 | if (!c.inter_copy_one()) { // L2: _R[kMtIdRegKey] mt? | 627 | if (_c.interCopyOne() != InterCopyResult::Success) { // L2: _R[kMtIdRegKey] mt? |
628 | raise_luaL_error(getErrL(), "Error copying a metatable"); | 628 | raise_luaL_error(getErrL(), "Error copying a metatable"); |
629 | } | 629 | } |
630 | 630 | ||
@@ -654,7 +654,7 @@ LuaType InterCopyContext::processConversion() const | |||
654 | // local functions to point to the same table, also in the target. | 654 | // local functions to point to the same table, also in the target. |
655 | // Always pushes a table to 'L2'. | 655 | // Always pushes a table to 'L2'. |
656 | // Returns true if the table was cached (no need to fill it!); false if it's a virgin. | 656 | // Returns true if the table was cached (no need to fill it!); false if it's a virgin. |
657 | [[nodiscard]] bool InterCopyContext::push_cached_table() const | 657 | [[nodiscard]] bool InterCopyContext::pushCachedTable() const |
658 | { | 658 | { |
659 | void const* const _p{ lua_topointer(L1, L1_i) }; | 659 | void const* const _p{ lua_topointer(L1, L1_i) }; |
660 | 660 | ||
@@ -730,22 +730,22 @@ LuaType InterCopyContext::processConversion() const | |||
730 | void* const _clone{ lua_newuserdatauv(L2, userdata_size, _nuv) }; // L2: ... u | 730 | void* const _clone{ lua_newuserdatauv(L2, userdata_size, _nuv) }; // L2: ... u |
731 | // copy the metatable in the target state, and give it to the clone we put there | 731 | // copy the metatable in the target state, and give it to the clone we put there |
732 | InterCopyContext _c{ U, L2, L1, L2_cache_i, SourceIndex{ _mt }, VT::NORMAL, mode, name }; | 732 | InterCopyContext _c{ U, L2, L1, L2_cache_i, SourceIndex{ _mt }, VT::NORMAL, mode, name }; |
733 | if (_c.inter_copy_one()) { // L2: ... u mt|sentinel | 733 | if (_c.interCopyOne() != InterCopyResult::Success) { // L2: ... u mt|sentinel |
734 | if (LookupMode::ToKeeper == mode) { // L2: ... u sentinel | ||
735 | LUA_ASSERT(L1, lua_tocfunction(L2, -1) == table_lookup_sentinel); | ||
736 | // we want to create a new closure with a 'clone sentinel' function, where the upvalues are the userdata and the metatable fqn | ||
737 | lua_getupvalue(L2, -1, 1); // L2: ... u sentinel fqn | ||
738 | lua_remove(L2, -2); // L2: ... u fqn | ||
739 | lua_insert(L2, -2); // L2: ... fqn u | ||
740 | lua_pushcclosure(L2, userdata_clone_sentinel, 2); // L2: ... userdata_clone_sentinel | ||
741 | } else { // from keeper or direct // L2: ... u mt | ||
742 | LUA_ASSERT(L1, lua_istable(L2, -1)); | ||
743 | lua_setmetatable(L2, -2); // L2: ... u | ||
744 | } | ||
745 | STACK_CHECK(L2, 1); | ||
746 | } else { | ||
747 | raise_luaL_error(getErrL(), "Error copying a metatable"); | 734 | raise_luaL_error(getErrL(), "Error copying a metatable"); |
748 | } | 735 | } |
736 | |||
737 | if (LookupMode::ToKeeper == mode) { // L2: ... u sentinel | ||
738 | LUA_ASSERT(L1, lua_tocfunction(L2, -1) == table_lookup_sentinel); | ||
739 | // we want to create a new closure with a 'clone sentinel' function, where the upvalues are the userdata and the metatable fqn | ||
740 | lua_getupvalue(L2, -1, 1); // L2: ... u sentinel fqn | ||
741 | lua_remove(L2, -2); // L2: ... u fqn | ||
742 | lua_insert(L2, -2); // L2: ... fqn u | ||
743 | lua_pushcclosure(L2, userdata_clone_sentinel, 2); // L2: ... userdata_clone_sentinel | ||
744 | } else { // from keeper or direct // L2: ... u mt | ||
745 | LUA_ASSERT(L1, lua_istable(L2, -1)); | ||
746 | lua_setmetatable(L2, -2); // L2: ... u | ||
747 | } | ||
748 | STACK_CHECK(L2, 1); | ||
749 | // first, add the entry in the cache (at this point it is either the actual userdata or the keeper sentinel | 749 | // first, add the entry in the cache (at this point it is either the actual userdata or the keeper sentinel |
750 | lua_pushlightuserdata(L2, _source); // L2: ... u source | 750 | lua_pushlightuserdata(L2, _source); // L2: ... u source |
751 | lua_pushvalue(L2, -2); // L2: ... u source u | 751 | lua_pushvalue(L2, -2); // L2: ... u source u |
@@ -758,7 +758,7 @@ LuaType InterCopyContext::processConversion() const | |||
758 | int _uvi{ _nuv }; | 758 | int _uvi{ _nuv }; |
759 | while (_uvi > 0) { | 759 | while (_uvi > 0) { |
760 | _c.L1_i = SourceIndex{ luaG_absindex(L1, -1) }; | 760 | _c.L1_i = SourceIndex{ luaG_absindex(L1, -1) }; |
761 | if (!_c.inter_copy_one()) { // L2: ... u uv | 761 | if (_c.interCopyOne() != InterCopyResult::Success) { // L2: ... u uv |
762 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); | 762 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); |
763 | } | 763 | } |
764 | lua_pop(L1, 1); // L1: ... mt __lanesclone [uv]* | 764 | lua_pop(L1, 1); // L1: ... mt __lanesclone [uv]* |
@@ -816,7 +816,7 @@ LuaType InterCopyContext::processConversion() const | |||
816 | int _uvi{ _nuv }; | 816 | int _uvi{ _nuv }; |
817 | while (_uvi) { | 817 | while (_uvi) { |
818 | _c.L1_i = SourceIndex{ luaG_absindex(L1, -1) }; | 818 | _c.L1_i = SourceIndex{ luaG_absindex(L1, -1) }; |
819 | if (!_c.inter_copy_one()) { // L1: ... deep ... [uv]* L2: deep uv | 819 | if (_c.interCopyOne() != InterCopyResult::Success) { // L1: ... deep ... [uv]* L2: deep uv |
820 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); | 820 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); |
821 | } | 821 | } |
822 | lua_pop(L1, 1); // L1: ... deep ... [uv]* | 822 | lua_pop(L1, 1); // L1: ... deep ... [uv]* |
@@ -834,7 +834,7 @@ LuaType InterCopyContext::processConversion() const | |||
834 | 834 | ||
835 | // ################################################################################################# | 835 | // ################################################################################################# |
836 | 836 | ||
837 | [[nodiscard]] bool InterCopyContext::inter_copy_boolean() const | 837 | [[nodiscard]] bool InterCopyContext::interCopyBoolean() const |
838 | { | 838 | { |
839 | int const _v{ lua_toboolean(L1, L1_i) }; | 839 | int const _v{ lua_toboolean(L1, L1_i) }; |
840 | DEBUGSPEW_CODE(DebugSpew(nullptr) << (_v ? "true" : "false") << std::endl); | 840 | DEBUGSPEW_CODE(DebugSpew(nullptr) << (_v ? "true" : "false") << std::endl); |
@@ -844,7 +844,7 @@ LuaType InterCopyContext::processConversion() const | |||
844 | 844 | ||
845 | // ################################################################################################# | 845 | // ################################################################################################# |
846 | 846 | ||
847 | [[nodiscard]] bool InterCopyContext::inter_copy_function() const | 847 | [[nodiscard]] bool InterCopyContext::interCopyFunction() const |
848 | { | 848 | { |
849 | if (vt == VT::KEY) { | 849 | if (vt == VT::KEY) { |
850 | return false; | 850 | return false; |
@@ -871,8 +871,8 @@ LuaType InterCopyContext::processConversion() const | |||
871 | lua_pop(L2, 1); // L2: ... | 871 | lua_pop(L2, 1); // L2: ... |
872 | 872 | ||
873 | // userdata_clone_sentinel has 2 upvalues: the fqn of its metatable, and the userdata itself | 873 | // userdata_clone_sentinel has 2 upvalues: the fqn of its metatable, and the userdata itself |
874 | bool const found{ lookup_table() }; // L2: ... mt? | 874 | bool const _found{ lookupTable() }; // L2: ... mt? |
875 | if (!found) { | 875 | if (!_found) { |
876 | STACK_CHECK(L2, 0); | 876 | STACK_CHECK(L2, 0); |
877 | return false; | 877 | return false; |
878 | } | 878 | } |
@@ -896,11 +896,11 @@ LuaType InterCopyContext::processConversion() const | |||
896 | lua_pushvalue(L2, -2); // L2: ... mt u mt | 896 | lua_pushvalue(L2, -2); // L2: ... mt u mt |
897 | lua_setmetatable(L2, -2); // L2: ... mt u | 897 | lua_setmetatable(L2, -2); // L2: ... mt u |
898 | // transfer and assign uservalues | 898 | // transfer and assign uservalues |
899 | InterCopyContext c{ *this }; | 899 | InterCopyContext _c{ *this }; |
900 | int _uvi{ _nuv }; | 900 | int _uvi{ _nuv }; |
901 | while (_uvi > 0) { | 901 | while (_uvi > 0) { |
902 | c.L1_i = SourceIndex{ luaG_absindex(L1, -1) }; | 902 | _c.L1_i = SourceIndex{ luaG_absindex(L1, -1) }; |
903 | if (!c.inter_copy_one()) { // L2: ... mt u uv | 903 | if (_c.interCopyOne() != InterCopyResult::Success) { // L2: ... mt u uv |
904 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); | 904 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); |
905 | } | 905 | } |
906 | lua_pop(L1, 1); // L1: ... u [uv]* | 906 | lua_pop(L1, 1); // L1: ... u [uv]* |
@@ -926,7 +926,7 @@ LuaType InterCopyContext::processConversion() const | |||
926 | } else { // regular function | 926 | } else { // regular function |
927 | DEBUGSPEW_CODE(DebugSpew(U) << "FUNCTION " << name << std::endl); | 927 | DEBUGSPEW_CODE(DebugSpew(U) << "FUNCTION " << name << std::endl); |
928 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); | 928 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); |
929 | copy_cached_func(); // L2: ... f | 929 | copyCachedFunction(); // L2: ... f |
930 | } | 930 | } |
931 | STACK_CHECK(L2, 1); | 931 | STACK_CHECK(L2, 1); |
932 | STACK_CHECK(L1, 0); | 932 | STACK_CHECK(L1, 0); |
@@ -935,7 +935,7 @@ LuaType InterCopyContext::processConversion() const | |||
935 | 935 | ||
936 | // ################################################################################################# | 936 | // ################################################################################################# |
937 | 937 | ||
938 | [[nodiscard]] bool InterCopyContext::inter_copy_lightuserdata() const | 938 | [[nodiscard]] bool InterCopyContext::interCopyLightuserdata() const |
939 | { | 939 | { |
940 | void* const _p{ lua_touserdata(L1, L1_i) }; | 940 | void* const _p{ lua_touserdata(L1, L1_i) }; |
941 | // recognize and print known UniqueKey names here | 941 | // recognize and print known UniqueKey names here |
@@ -966,7 +966,7 @@ LuaType InterCopyContext::processConversion() const | |||
966 | 966 | ||
967 | // ################################################################################################# | 967 | // ################################################################################################# |
968 | 968 | ||
969 | [[nodiscard]] bool InterCopyContext::inter_copy_nil() const | 969 | [[nodiscard]] bool InterCopyContext::interCopyNil() const |
970 | { | 970 | { |
971 | if (vt == VT::KEY) { | 971 | if (vt == VT::KEY) { |
972 | return false; | 972 | return false; |
@@ -982,7 +982,7 @@ LuaType InterCopyContext::processConversion() const | |||
982 | 982 | ||
983 | // ################################################################################################# | 983 | // ################################################################################################# |
984 | 984 | ||
985 | [[nodiscard]] bool InterCopyContext::inter_copy_number() const | 985 | [[nodiscard]] bool InterCopyContext::interCopyNumber() const |
986 | { | 986 | { |
987 | // LNUM patch support (keeping integer accuracy) | 987 | // LNUM patch support (keeping integer accuracy) |
988 | #if defined LUA_LNUM || LUA_VERSION_NUM >= 503 | 988 | #if defined LUA_LNUM || LUA_VERSION_NUM >= 503 |
@@ -1002,7 +1002,7 @@ LuaType InterCopyContext::processConversion() const | |||
1002 | 1002 | ||
1003 | // ################################################################################################# | 1003 | // ################################################################################################# |
1004 | 1004 | ||
1005 | [[nodiscard]] bool InterCopyContext::inter_copy_string() const | 1005 | [[nodiscard]] bool InterCopyContext::interCopyString() const |
1006 | { | 1006 | { |
1007 | std::string_view const _s{ luaG_tostring(L1, L1_i) }; | 1007 | std::string_view const _s{ luaG_tostring(L1, L1_i) }; |
1008 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "'" << _s << "'" << std::endl); | 1008 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "'" << _s << "'" << std::endl); |
@@ -1012,7 +1012,7 @@ LuaType InterCopyContext::processConversion() const | |||
1012 | 1012 | ||
1013 | // ################################################################################################# | 1013 | // ################################################################################################# |
1014 | 1014 | ||
1015 | [[nodiscard]] bool InterCopyContext::inter_copy_table() const | 1015 | [[nodiscard]] bool InterCopyContext::interCopyTable() const |
1016 | { | 1016 | { |
1017 | if (vt == VT::KEY) { | 1017 | if (vt == VT::KEY) { |
1018 | return false; | 1018 | return false; |
@@ -1026,7 +1026,7 @@ LuaType InterCopyContext::processConversion() const | |||
1026 | * 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?) | 1026 | * 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?) |
1027 | * Note that this table CAN be a module table, but we just didn't register it, in which case we'll send it through the table cloning mechanism | 1027 | * Note that this table CAN be a module table, but we just didn't register it, in which case we'll send it through the table cloning mechanism |
1028 | */ | 1028 | */ |
1029 | if (lookup_table()) { | 1029 | if (lookupTable()) { |
1030 | LUA_ASSERT(L1, lua_istable(L2, -1) || (lua_tocfunction(L2, -1) == table_lookup_sentinel)); // from lookup data. can also be table_lookup_sentinel if this is a table we know | 1030 | LUA_ASSERT(L1, lua_istable(L2, -1) || (lua_tocfunction(L2, -1) == table_lookup_sentinel)); // from lookup data. can also be table_lookup_sentinel if this is a table we know |
1031 | return true; | 1031 | return true; |
1032 | } | 1032 | } |
@@ -1040,7 +1040,7 @@ LuaType InterCopyContext::processConversion() const | |||
1040 | * Note: Even metatables need to go through this test; to detect | 1040 | * Note: Even metatables need to go through this test; to detect |
1041 | * loops such as those in required module tables (getmetatable(lanes).lanes == lanes) | 1041 | * loops such as those in required module tables (getmetatable(lanes).lanes == lanes) |
1042 | */ | 1042 | */ |
1043 | if (push_cached_table()) { | 1043 | if (pushCachedTable()) { // L2: ... t |
1044 | LUA_ASSERT(L1, lua_istable(L2, -1)); // from cache | 1044 | LUA_ASSERT(L1, lua_istable(L2, -1)); // from cache |
1045 | return true; | 1045 | return true; |
1046 | } | 1046 | } |
@@ -1052,14 +1052,14 @@ LuaType InterCopyContext::processConversion() const | |||
1052 | lua_pushnil(L1); // start iteration | 1052 | lua_pushnil(L1); // start iteration |
1053 | while (lua_next(L1, L1_i)) { | 1053 | while (lua_next(L1, L1_i)) { |
1054 | // need a function to prevent overflowing the stack with verboseErrors-induced alloca() | 1054 | // need a function to prevent overflowing the stack with verboseErrors-induced alloca() |
1055 | inter_copy_keyvaluepair(); | 1055 | interCopyKeyValuePair(); |
1056 | lua_pop(L1, 1); // pop value (next round) | 1056 | lua_pop(L1, 1); // pop value (next round) |
1057 | } | 1057 | } |
1058 | STACK_CHECK(L1, 0); | 1058 | STACK_CHECK(L1, 0); |
1059 | STACK_CHECK(L2, 1); | 1059 | STACK_CHECK(L2, 1); |
1060 | 1060 | ||
1061 | // Metatables are expected to be immutable, and copied only once. | 1061 | // Metatables are expected to be immutable, and copied only once. |
1062 | if (push_cached_metatable()) { // L2: ... t mt? | 1062 | if (pushCachedMetatable()) { // L2: ... t mt? |
1063 | lua_setmetatable(L2, -2); // L2: ... t | 1063 | lua_setmetatable(L2, -2); // L2: ... t |
1064 | } | 1064 | } |
1065 | STACK_CHECK(L2, 1); | 1065 | STACK_CHECK(L2, 1); |
@@ -1069,7 +1069,7 @@ LuaType InterCopyContext::processConversion() const | |||
1069 | 1069 | ||
1070 | // ################################################################################################# | 1070 | // ################################################################################################# |
1071 | 1071 | ||
1072 | [[nodiscard]] bool InterCopyContext::inter_copy_userdata() const | 1072 | [[nodiscard]] bool InterCopyContext::interCopyUserdata() const |
1073 | { | 1073 | { |
1074 | STACK_CHECK_START_REL(L1, 0); | 1074 | STACK_CHECK_START_REL(L1, 0); |
1075 | STACK_CHECK_START_REL(L2, 0); | 1075 | STACK_CHECK_START_REL(L2, 0); |
@@ -1134,14 +1134,14 @@ namespace { | |||
1134 | * | 1134 | * |
1135 | * Returns true if value was pushed, false if its type is non-supported. | 1135 | * Returns true if value was pushed, false if its type is non-supported. |
1136 | */ | 1136 | */ |
1137 | [[nodiscard]] bool InterCopyContext::inter_copy_one() const | 1137 | [[nodiscard]] InterCopyResult InterCopyContext::interCopyOne() const |
1138 | { | 1138 | { |
1139 | static constexpr int kPODmask = (1 << LUA_TNIL) | (1 << LUA_TBOOLEAN) | (1 << LUA_TLIGHTUSERDATA) | (1 << LUA_TNUMBER) | (1 << LUA_TSTRING); | 1139 | static constexpr int kPODmask = (1 << LUA_TNIL) | (1 << LUA_TBOOLEAN) | (1 << LUA_TLIGHTUSERDATA) | (1 << LUA_TNUMBER) | (1 << LUA_TSTRING); |
1140 | STACK_GROW(L2, 1); | 1140 | STACK_GROW(L2, 1); |
1141 | STACK_CHECK_START_REL(L1, 0); | 1141 | STACK_CHECK_START_REL(L1, 0); |
1142 | STACK_CHECK_START_REL(L2, 0); | 1142 | STACK_CHECK_START_REL(L2, 0); |
1143 | 1143 | ||
1144 | DEBUGSPEW_CODE(DebugSpew(U) << "inter_copy_one()" << std::endl); | 1144 | DEBUGSPEW_CODE(DebugSpew(U) << "interCopyOne()" << std::endl); |
1145 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); | 1145 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); |
1146 | 1146 | ||
1147 | // replace the value at L1_i with the result of a conversion if required | 1147 | // replace the value at L1_i with the result of a conversion if required |
@@ -1154,30 +1154,30 @@ namespace { | |||
1154 | switch (_val_type) { | 1154 | switch (_val_type) { |
1155 | // Basic types allowed both as values, and as table keys | 1155 | // Basic types allowed both as values, and as table keys |
1156 | case LuaType::BOOLEAN: | 1156 | case LuaType::BOOLEAN: |
1157 | _ret = inter_copy_boolean(); | 1157 | _ret = interCopyBoolean(); |
1158 | break; | 1158 | break; |
1159 | case LuaType::NUMBER: | 1159 | case LuaType::NUMBER: |
1160 | _ret = inter_copy_number(); | 1160 | _ret = interCopyNumber(); |
1161 | break; | 1161 | break; |
1162 | case LuaType::STRING: | 1162 | case LuaType::STRING: |
1163 | _ret = inter_copy_string(); | 1163 | _ret = interCopyString(); |
1164 | break; | 1164 | break; |
1165 | case LuaType::LIGHTUSERDATA: | 1165 | case LuaType::LIGHTUSERDATA: |
1166 | _ret = inter_copy_lightuserdata(); | 1166 | _ret = interCopyLightuserdata(); |
1167 | break; | 1167 | break; |
1168 | 1168 | ||
1169 | // The following types are not allowed as table keys | 1169 | // The following types are not allowed as table keys |
1170 | case LuaType::USERDATA: | 1170 | case LuaType::USERDATA: |
1171 | _ret = inter_copy_userdata(); | 1171 | _ret = interCopyUserdata(); |
1172 | break; | 1172 | break; |
1173 | case LuaType::NIL: | 1173 | case LuaType::NIL: |
1174 | _ret = inter_copy_nil(); | 1174 | _ret = interCopyNil(); |
1175 | break; | 1175 | break; |
1176 | case LuaType::FUNCTION: | 1176 | case LuaType::FUNCTION: |
1177 | _ret = inter_copy_function(); | 1177 | _ret = interCopyFunction(); |
1178 | break; | 1178 | break; |
1179 | case LuaType::TABLE: | 1179 | case LuaType::TABLE: |
1180 | _ret = inter_copy_table(); | 1180 | _ret = interCopyTable(); |
1181 | break; | 1181 | break; |
1182 | 1182 | ||
1183 | // The following types cannot be copied | 1183 | // The following types cannot be copied |
@@ -1191,7 +1191,7 @@ namespace { | |||
1191 | 1191 | ||
1192 | STACK_CHECK(L2, _ret ? 1 : 0); | 1192 | STACK_CHECK(L2, _ret ? 1 : 0); |
1193 | STACK_CHECK(L1, 0); | 1193 | STACK_CHECK(L1, 0); |
1194 | return _ret; | 1194 | return _ret ? InterCopyResult::Success : InterCopyResult::Error; |
1195 | } | 1195 | } |
1196 | 1196 | ||
1197 | // ################################################################################################# | 1197 | // ################################################################################################# |
@@ -1200,9 +1200,9 @@ namespace { | |||
1200 | // returns InterCopyResult::Success if everything is fine | 1200 | // returns InterCopyResult::Success if everything is fine |
1201 | // returns InterCopyResult::Error if pushed an error message in L1 | 1201 | // returns InterCopyResult::Error if pushed an error message in L1 |
1202 | // else raise an error in whichever state is not a keeper | 1202 | // else raise an error in whichever state is not a keeper |
1203 | [[nodiscard]] InterCopyResult InterCopyContext::inter_copy_package() const | 1203 | [[nodiscard]] InterCopyResult InterCopyContext::interCopyPackage() const |
1204 | { | 1204 | { |
1205 | DEBUGSPEW_CODE(DebugSpew(U) << "InterCopyContext::inter_copy_package()" << std::endl); | 1205 | DEBUGSPEW_CODE(DebugSpew(U) << "InterCopyContext::interCopyPackage()" << std::endl); |
1206 | 1206 | ||
1207 | class OnExit | 1207 | class OnExit |
1208 | { | 1208 | { |
@@ -1257,7 +1257,7 @@ namespace { | |||
1257 | } else { | 1257 | } else { |
1258 | { | 1258 | { |
1259 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); | 1259 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); |
1260 | _result = inter_move(1); // moves the entry to L2 | 1260 | _result = interMove(1); // moves the entry to L2 |
1261 | STACK_CHECK(L1, 0); | 1261 | STACK_CHECK(L1, 0); |
1262 | } | 1262 | } |
1263 | if (_result == InterCopyResult::Success) { | 1263 | if (_result == InterCopyResult::Success) { |
@@ -1281,11 +1281,11 @@ namespace { | |||
1281 | 1281 | ||
1282 | // Akin to 'lua_xmove' but copies values between _any_ Lua states. | 1282 | // Akin to 'lua_xmove' but copies values between _any_ Lua states. |
1283 | // NOTE: Both the states must be solely in the current OS thread's possession. | 1283 | // NOTE: Both the states must be solely in the current OS thread's possession. |
1284 | [[nodiscard]] InterCopyResult InterCopyContext::inter_copy(int n_) const | 1284 | [[nodiscard]] InterCopyResult InterCopyContext::interCopy(int const n_) const |
1285 | { | 1285 | { |
1286 | LUA_ASSERT(L1, vt == VT::NORMAL); | 1286 | LUA_ASSERT(L1, vt == VT::NORMAL); |
1287 | 1287 | ||
1288 | DEBUGSPEW_CODE(DebugSpew(U) << "InterCopyContext::inter_copy()" << std::endl); | 1288 | DEBUGSPEW_CODE(DebugSpew(U) << "InterCopyContext::interCopy()" << std::endl); |
1289 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); | 1289 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); |
1290 | 1290 | ||
1291 | int const _top_L1{ lua_gettop(L1) }; | 1291 | int const _top_L1{ lua_gettop(L1) }; |
@@ -1309,21 +1309,21 @@ namespace { | |||
1309 | char _tmpBuf[16]; | 1309 | char _tmpBuf[16]; |
1310 | char const* const _pBuf{ U->verboseErrors ? _tmpBuf : "?" }; | 1310 | char const* const _pBuf{ U->verboseErrors ? _tmpBuf : "?" }; |
1311 | InterCopyContext _c{ U, L2, L1, CacheIndex{ _top_L2 + 1 }, {}, VT::NORMAL, mode, _pBuf }; | 1311 | InterCopyContext _c{ U, L2, L1, CacheIndex{ _top_L2 + 1 }, {}, VT::NORMAL, mode, _pBuf }; |
1312 | bool _copyok{ true }; | 1312 | InterCopyResult _copyok{ InterCopyResult::Success }; |
1313 | STACK_CHECK_START_REL(L1, 0); | 1313 | STACK_CHECK_START_REL(L1, 0); |
1314 | for (int _i{ _top_L1 - n_ + 1 }, _j{ 1 }; _i <= _top_L1; ++_i, ++_j) { | 1314 | for (int _i{ _top_L1 - n_ + 1 }, _j{ 1 }; _i <= _top_L1; ++_i, ++_j) { |
1315 | if (U->verboseErrors) { | 1315 | if (U->verboseErrors) { |
1316 | sprintf(_tmpBuf, "arg_%d", _j); | 1316 | sprintf(_tmpBuf, "arg_%d", _j); |
1317 | } | 1317 | } |
1318 | _c.L1_i = SourceIndex{ _i }; | 1318 | _c.L1_i = SourceIndex{ _i }; |
1319 | _copyok = _c.inter_copy_one(); // L2: ... cache {}n | 1319 | _copyok = _c.interCopyOne(); // L2: ... cache {}n |
1320 | if (!_copyok) { | 1320 | if (_copyok != InterCopyResult::Success) { |
1321 | break; | 1321 | break; |
1322 | } | 1322 | } |
1323 | } | 1323 | } |
1324 | STACK_CHECK(L1, 0); | 1324 | STACK_CHECK(L1, 0); |
1325 | 1325 | ||
1326 | if (_copyok) { | 1326 | if (_copyok == InterCopyResult::Success) { |
1327 | STACK_CHECK(L2, n_ + 1); | 1327 | STACK_CHECK(L2, n_ + 1); |
1328 | // Remove the cache table. Persistent caching would cause i.e. multiple | 1328 | // Remove the cache table. Persistent caching would cause i.e. multiple |
1329 | // messages passed in the same table to use the same table also in receiving end. | 1329 | // messages passed in the same table to use the same table also in receiving end. |
@@ -1339,9 +1339,9 @@ namespace { | |||
1339 | 1339 | ||
1340 | // ################################################################################################# | 1340 | // ################################################################################################# |
1341 | 1341 | ||
1342 | [[nodiscard]] InterCopyResult InterCopyContext::inter_move(int n_) const | 1342 | [[nodiscard]] InterCopyResult InterCopyContext::interMove(int const n_) const |
1343 | { | 1343 | { |
1344 | InterCopyResult const _ret{ inter_copy(n_) }; | 1344 | InterCopyResult const _ret{ interCopy(n_) }; |
1345 | lua_pop(L1, n_); | 1345 | lua_pop(L1, n_); |
1346 | return _ret; | 1346 | return _ret; |
1347 | } | 1347 | } |
diff --git a/src/intercopycontext.h b/src/intercopycontext.h index 459551e..8615842 100644 --- a/src/intercopycontext.h +++ b/src/intercopycontext.h | |||
@@ -44,36 +44,36 @@ class InterCopyContext | |||
44 | lua_State* getErrL() const { return (mode == LookupMode::FromKeeper) ? L2 : L1; } | 44 | lua_State* getErrL() const { return (mode == LookupMode::FromKeeper) ? L2 : L1; } |
45 | [[nodiscard]] LuaType processConversion() const; | 45 | [[nodiscard]] LuaType processConversion() const; |
46 | 46 | ||
47 | // for use in copy_cached_func | 47 | // for use in copyCachedFunction |
48 | void copy_func() const; | 48 | void copyFunction() const; |
49 | void lookup_native_func() const; | 49 | void lookupNativeFunction() const; |
50 | 50 | ||
51 | // for use in inter_copy_function | 51 | // for use in inter_copy_function |
52 | void copy_cached_func() const; | 52 | void copyCachedFunction() const; |
53 | [[nodiscard]] bool lookup_table() const; | 53 | [[nodiscard]] bool lookupTable() const; |
54 | 54 | ||
55 | // for use in inter_copy_table | 55 | // for use in inter_copy_table |
56 | void inter_copy_keyvaluepair() const; | 56 | void interCopyKeyValuePair() const; |
57 | [[nodiscard]] bool push_cached_metatable() const; | 57 | [[nodiscard]] bool pushCachedMetatable() const; |
58 | [[nodiscard]] bool push_cached_table() const; | 58 | [[nodiscard]] bool pushCachedTable() const; |
59 | 59 | ||
60 | // for use in inter_copy_userdata | 60 | // for use in inter_copy_userdata |
61 | [[nodiscard]] bool tryCopyClonable() const; | 61 | [[nodiscard]] bool tryCopyClonable() const; |
62 | [[nodiscard]] bool tryCopyDeep() const; | 62 | [[nodiscard]] bool tryCopyDeep() const; |
63 | 63 | ||
64 | // copying a single Lua stack item | 64 | // copying a single Lua stack item |
65 | [[nodiscard]] bool inter_copy_boolean() const; | 65 | [[nodiscard]] bool interCopyBoolean() const; |
66 | [[nodiscard]] bool inter_copy_function() const; | 66 | [[nodiscard]] bool interCopyFunction() const; |
67 | [[nodiscard]] bool inter_copy_lightuserdata() const; | 67 | [[nodiscard]] bool interCopyLightuserdata() const; |
68 | [[nodiscard]] bool inter_copy_nil() const; | 68 | [[nodiscard]] bool interCopyNil() const; |
69 | [[nodiscard]] bool inter_copy_number() const; | 69 | [[nodiscard]] bool interCopyNumber() const; |
70 | [[nodiscard]] bool inter_copy_string() const; | 70 | [[nodiscard]] bool interCopyString() const; |
71 | [[nodiscard]] bool inter_copy_table() const; | 71 | [[nodiscard]] bool interCopyTable() const; |
72 | [[nodiscard]] bool inter_copy_userdata() const; | 72 | [[nodiscard]] bool interCopyUserdata() const; |
73 | 73 | ||
74 | public: | 74 | public: |
75 | [[nodiscard]] bool inter_copy_one() const; | 75 | [[nodiscard]] InterCopyResult interCopy(int n_) const; |
76 | [[nodiscard]] InterCopyResult inter_copy_package() const; | 76 | [[nodiscard]] InterCopyResult interCopyOne() const; |
77 | [[nodiscard]] InterCopyResult inter_copy(int n_) const; | 77 | [[nodiscard]] InterCopyResult interCopyPackage() const; |
78 | [[nodiscard]] InterCopyResult inter_move(int n_) const; | 78 | [[nodiscard]] InterCopyResult interMove(int n_) const; |
79 | }; | 79 | }; |
diff --git a/src/keeper.cpp b/src/keeper.cpp index acb8619..7000372 100644 --- a/src/keeper.cpp +++ b/src/keeper.cpp | |||
@@ -298,10 +298,14 @@ int keeper_push_linda_storage(Linda& linda_, DestState L_) | |||
298 | KeyUD* const _key{ KeyUD::GetPtr(_K, -1) }; | 298 | KeyUD* const _key{ KeyUD::GetPtr(_K, -1) }; |
299 | _key->prepareAccess(_K, -1); // _K: KeysDB key fifo L_: out | 299 | _key->prepareAccess(_K, -1); // _K: KeysDB key fifo L_: out |
300 | lua_pushvalue(_K, -2); // _K: KeysDB key fifo key L_: out | 300 | lua_pushvalue(_K, -2); // _K: KeysDB key fifo key L_: out |
301 | std::ignore = _c.inter_move(1); // _K: KeysDB key fifo L_: out key | 301 | if (_c.interMove(1) != InterCopyResult::Success) { // _K: KeysDB key fifo L_: out key |
302 | raise_luaL_error(L_, "Internal error reading Keeper contents"); | ||
303 | } | ||
302 | STACK_CHECK(L_, 2); | 304 | STACK_CHECK(L_, 2); |
303 | lua_newtable(L_); // _K: KeysDB key fifo L_: out key keyout | 305 | lua_newtable(L_); // _K: KeysDB key fifo L_: out key keyout |
304 | std::ignore = _c.inter_move(1); // _K: KeysDB key L_: out key keyout fifo | 306 | if (_c.interMove(1) != InterCopyResult::Success) { // _K: KeysDB key L_: out key keyout fifo |
307 | raise_luaL_error(L_, "Internal error reading Keeper contents"); | ||
308 | } | ||
305 | // keyout.first | 309 | // keyout.first |
306 | lua_pushinteger(L_, _key->first); // _K: KeysDB key L_: out key keyout fifo first | 310 | lua_pushinteger(L_, _key->first); // _K: KeysDB key L_: out key keyout fifo first |
307 | STACK_CHECK(L_, 5); | 311 | STACK_CHECK(L_, 5); |
@@ -642,7 +646,7 @@ KeeperCallResult keeper_call(KeeperState K_, keeper_api_t func_, lua_State* L_, | |||
642 | lua_pushlightuserdata(K_, linda_); // L: ... args... K_: func_ linda | 646 | lua_pushlightuserdata(K_, linda_); // L: ... args... K_: func_ linda |
643 | if ( | 647 | if ( |
644 | (_args == 0) || | 648 | (_args == 0) || |
645 | (InterCopyContext{ linda_->U, DestState{ K_ }, SourceState{ L_ }, {}, {}, {}, LookupMode::ToKeeper, {} }.inter_copy(_args) == InterCopyResult::Success) | 649 | (InterCopyContext{ linda_->U, DestState{ K_ }, SourceState{ L_ }, {}, {}, {}, LookupMode::ToKeeper, {} }.interCopy(_args) == InterCopyResult::Success) |
646 | ) { // L: ... args... K_: func_ linda args... | 650 | ) { // L: ... args... K_: func_ linda args... |
647 | lua_call(K_, 1 + _args, LUA_MULTRET); // L: ... args... K_: result... | 651 | lua_call(K_, 1 + _args, LUA_MULTRET); // L: ... args... K_: result... |
648 | int const _retvals{ lua_gettop(K_) - _top_K }; | 652 | int const _retvals{ lua_gettop(K_) - _top_K }; |
@@ -652,7 +656,7 @@ KeeperCallResult keeper_call(KeeperState K_, keeper_api_t func_, lua_State* L_, | |||
652 | // when attempting to grab the mutex again (WINVER <= 0x400 does this, but locks just fine, I don't know about pthread) | 656 | // when attempting to grab the mutex again (WINVER <= 0x400 does this, but locks just fine, I don't know about pthread) |
653 | if ( | 657 | if ( |
654 | (_retvals == 0) || | 658 | (_retvals == 0) || |
655 | (InterCopyContext{ linda_->U, DestState{ L_ }, SourceState{ K_ }, {}, {}, {}, LookupMode::FromKeeper, {} }.inter_move(_retvals) == InterCopyResult::Success) | 659 | (InterCopyContext{ linda_->U, DestState{ L_ }, SourceState{ K_ }, {}, {}, {}, LookupMode::FromKeeper, {} }.interMove(_retvals) == InterCopyResult::Success) |
656 | ) { // L: ... args... result... K_: result... | 660 | ) { // L: ... args... result... K_: result... |
657 | _result.emplace(_retvals); | 661 | _result.emplace(_retvals); |
658 | } | 662 | } |
@@ -848,7 +852,7 @@ void Keepers::initialize(Universe& U_, lua_State* L_, int const nbKeepers_, int | |||
848 | if (luaG_getmodule(L, LUA_LOADLIBNAME) != LuaType::NIL) { // L_: settings package _K: | 852 | if (luaG_getmodule(L, LUA_LOADLIBNAME) != LuaType::NIL) { // L_: settings package _K: |
849 | // when copying with mode LookupMode::ToKeeper, error message is pushed at the top of the stack, not raised immediately | 853 | // when copying with mode LookupMode::ToKeeper, error message is pushed at the top of the stack, not raised immediately |
850 | InterCopyContext _c{ U, DestState{ _K }, SourceState{ L }, {}, SourceIndex{ luaG_absindex(L, -1) }, {}, LookupMode::ToKeeper, {} }; | 854 | InterCopyContext _c{ U, DestState{ _K }, SourceState{ L }, {}, SourceIndex{ luaG_absindex(L, -1) }, {}, LookupMode::ToKeeper, {} }; |
851 | if (_c.inter_copy_package() != InterCopyResult::Success) { // L_: settings ... error_msg _K: | 855 | if (_c.interCopyPackage() != InterCopyResult::Success) { // L_: settings ... error_msg _K: |
852 | // if something went wrong, the error message is at the top of the stack | 856 | // if something went wrong, the error message is at the top of the stack |
853 | lua_remove(L, -2); // L_: settings error_msg | 857 | lua_remove(L, -2); // L_: settings error_msg |
854 | raise_lua_error(L); | 858 | raise_lua_error(L); |
diff --git a/src/lane.cpp b/src/lane.cpp index 1a01a24..5e018a4 100644 --- a/src/lane.cpp +++ b/src/lane.cpp | |||
@@ -142,7 +142,7 @@ static LUAG_FUNC(thread_join) | |||
142 | } | 142 | } |
143 | if ( | 143 | if ( |
144 | (_n > 0) && | 144 | (_n > 0) && |
145 | (InterCopyContext{ _lane->U, DestState{ L_ }, SourceState{ _L2 }, {}, {}, {}, {}, {} }.inter_move(_n) != InterCopyResult::Success) | 145 | (InterCopyContext{ _lane->U, DestState{ L_ }, SourceState{ _L2 }, {}, {}, {}, {}, {} }.interMove(_n) != InterCopyResult::Success) |
146 | ) { // L_: lane results L2: | 146 | ) { // L_: lane results L2: |
147 | raise_luaL_error(L_, "tried to copy unsupported types"); | 147 | raise_luaL_error(L_, "tried to copy unsupported types"); |
148 | } | 148 | } |
@@ -157,7 +157,7 @@ static LUAG_FUNC(thread_join) | |||
157 | lua_pushnil(L_); // L_: lane nil | 157 | lua_pushnil(L_); // L_: lane nil |
158 | // even when _lane->errorTraceLevel != Minimal, if the error is not LUA_ERRRUN, the handler wasn't called, and we only have 1 error message on the stack ... | 158 | // even when _lane->errorTraceLevel != Minimal, if the error is not LUA_ERRRUN, the handler wasn't called, and we only have 1 error message on the stack ... |
159 | InterCopyContext _c{ _lane->U, DestState{ L_ }, SourceState{ _L2 }, {}, {}, {}, {}, {} }; | 159 | InterCopyContext _c{ _lane->U, DestState{ L_ }, SourceState{ _L2 }, {}, {}, {}, {}, {} }; |
160 | if (_c.inter_move(_n) != InterCopyResult::Success) { // L_: lane nil "err" [trace] L2: | 160 | if (_c.interMove(_n) != InterCopyResult::Success) { // L_: lane nil "err" [trace] L2: |
161 | raise_luaL_error(L_, "tried to copy unsupported types: %s", lua_tostring(L_, -_n)); | 161 | raise_luaL_error(L_, "tried to copy unsupported types: %s", lua_tostring(L_, -_n)); |
162 | } | 162 | } |
163 | _ret = 1 + _n; | 163 | _ret = 1 + _n; |
diff --git a/src/lanes.cpp b/src/lanes.cpp index 5d40ed4..8b693c3 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp | |||
@@ -400,9 +400,9 @@ LUAG_FUNC(lane_new) | |||
400 | if (_package_idx != 0) { | 400 | if (_package_idx != 0) { |
401 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: update 'package'" << std::endl); | 401 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: update 'package'" << std::endl); |
402 | // when copying with mode LookupMode::LaneBody, should raise an error in case of problem, not leave it one the stack | 402 | // when copying with mode LookupMode::LaneBody, should raise an error in case of problem, not leave it one the stack |
403 | InterCopyContext c{ _U, DestState{ _L2 }, SourceState{ L_ }, {}, SourceIndex{ _package_idx }, {}, {}, {} }; | 403 | InterCopyContext _c{ _U, DestState{ _L2 }, SourceState{ L_ }, {}, SourceIndex{ _package_idx }, {}, {}, {} }; |
404 | [[maybe_unused]] InterCopyResult const ret{ c.inter_copy_package() }; | 404 | [[maybe_unused]] InterCopyResult const _ret{ _c.interCopyPackage() }; |
405 | LUA_ASSERT(L_, ret == InterCopyResult::Success); // either all went well, or we should not even get here | 405 | LUA_ASSERT(L_, _ret == InterCopyResult::Success); // either all went well, or we should not even get here |
406 | } | 406 | } |
407 | 407 | ||
408 | // modules to require in the target lane *before* the function is transfered! | 408 | // modules to require in the target lane *before* the function is transfered! |
@@ -436,7 +436,7 @@ LUAG_FUNC(lane_new) | |||
436 | if (_rc != LuaError::OK) { | 436 | if (_rc != LuaError::OK) { |
437 | // propagate error to main state if any | 437 | // propagate error to main state if any |
438 | InterCopyContext _c{ _U, DestState{ L_ }, SourceState{ _L2 }, {}, {}, {}, {}, {} }; | 438 | InterCopyContext _c{ _U, DestState{ L_ }, SourceState{ _L2 }, {}, {}, {}, {}, {} }; |
439 | std::ignore = _c.inter_move(1); // L_: [fixed] args... n "modname" error L2: | 439 | std::ignore = _c.interMove(1); // L_: [fixed] args... n "modname" error L2: |
440 | raise_lua_error(L_); | 440 | raise_lua_error(L_); |
441 | } | 441 | } |
442 | // here the module was successfully required // L_: [fixed] args... n "modname" L2: ret | 442 | // here the module was successfully required // L_: [fixed] args... n "modname" L2: ret |
@@ -468,7 +468,7 @@ LUAG_FUNC(lane_new) | |||
468 | InterCopyContext _c{ _U, DestState{ _L2 }, SourceState{ L_ }, {}, {}, {}, {}, {} }; | 468 | InterCopyContext _c{ _U, DestState{ _L2 }, SourceState{ L_ }, {}, {}, {}, {}, {} }; |
469 | luaG_pushglobaltable(_L2); // L_: [fixed] args... nil L2: _G | 469 | luaG_pushglobaltable(_L2); // L_: [fixed] args... nil L2: _G |
470 | while (lua_next(L_, _globals_idx)) { // L_: [fixed] args... k v L2: _G | 470 | while (lua_next(L_, _globals_idx)) { // L_: [fixed] args... k v L2: _G |
471 | std::ignore = _c.inter_copy(2); // L_: [fixed] args... k v L2: _G k v | 471 | std::ignore = _c.interCopy(2); // L_: [fixed] args... k v L2: _G k v |
472 | // assign it in L2's globals table | 472 | // assign it in L2's globals table |
473 | lua_rawset(_L2, -3); // L_: [fixed] args... k v L2: _G | 473 | lua_rawset(_L2, -3); // L_: [fixed] args... k v L2: _G |
474 | lua_pop(L_, 1); // L_: [fixed] args... k | 474 | lua_pop(L_, 1); // L_: [fixed] args... k |
@@ -486,7 +486,7 @@ LUAG_FUNC(lane_new) | |||
486 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); | 486 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); |
487 | lua_pushvalue(L_, kFuncIdx); // L_: [fixed] args... func L2: eh? | 487 | lua_pushvalue(L_, kFuncIdx); // L_: [fixed] args... func L2: eh? |
488 | InterCopyContext _c{ _U, DestState{ _L2 }, SourceState{ L_ }, {}, {}, {}, {}, {} }; | 488 | InterCopyContext _c{ _U, DestState{ _L2 }, SourceState{ L_ }, {}, {}, {}, {}, {} }; |
489 | InterCopyResult const _res{ _c.inter_move(1) }; // L_: [fixed] args... L2: eh? func | 489 | InterCopyResult const _res{ _c.interMove(1) }; // L_: [fixed] args... L2: eh? func |
490 | if (_res != InterCopyResult::Success) { | 490 | if (_res != InterCopyResult::Success) { |
491 | raise_luaL_error(L_, "tried to copy unsupported types"); | 491 | raise_luaL_error(L_, "tried to copy unsupported types"); |
492 | } | 492 | } |
@@ -508,7 +508,7 @@ LUAG_FUNC(lane_new) | |||
508 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: transfer lane arguments" << std::endl); | 508 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: transfer lane arguments" << std::endl); |
509 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); | 509 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); |
510 | InterCopyContext _c{ _U, DestState{ _L2 }, SourceState{ L_ }, {}, {}, {}, {}, {} }; | 510 | InterCopyContext _c{ _U, DestState{ _L2 }, SourceState{ L_ }, {}, {}, {}, {}, {} }; |
511 | InterCopyResult const res{ _c.inter_move(_nargs) }; // L_: [fixed] L2: eh? func args... | 511 | InterCopyResult const res{ _c.interMove(_nargs) }; // L_: [fixed] L2: eh? func args... |
512 | if (res != InterCopyResult::Success) { | 512 | if (res != InterCopyResult::Success) { |
513 | raise_luaL_error(L_, "tried to copy unsupported types"); | 513 | raise_luaL_error(L_, "tried to copy unsupported types"); |
514 | } | 514 | } |
diff --git a/src/state.cpp b/src/state.cpp index 50981a6..96f7268 100644 --- a/src/state.cpp +++ b/src/state.cpp | |||
@@ -136,7 +136,7 @@ namespace { | |||
136 | kConfigRegKey.pushValue(L1_); // L1_: config | 136 | kConfigRegKey.pushValue(L1_); // L1_: config |
137 | // copy settings from from source to destination registry | 137 | // copy settings from from source to destination registry |
138 | InterCopyContext _c{ U_, L2_, L1_, {}, {}, {}, {}, {} }; | 138 | InterCopyContext _c{ U_, L2_, L1_, {}, {}, {}, {}, {} }; |
139 | if (_c.inter_move(1) != InterCopyResult::Success) { // L1_: L2_: config | 139 | if (_c.interMove(1) != InterCopyResult::Success) { // L1_: L2_: config |
140 | raise_luaL_error(L1_, "failed to copy settings when loading " kLanesCoreLibName); | 140 | raise_luaL_error(L1_, "failed to copy settings when loading " kLanesCoreLibName); |
141 | } | 141 | } |
142 | // set L2:_R[kConfigRegKey] = settings | 142 | // set L2:_R[kConfigRegKey] = settings |