diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2025-03-06 15:14:21 +0100 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2025-03-06 15:14:21 +0100 |
commit | b92dbd75b1c9988dcc83e5876e1ce2815145fa30 (patch) | |
tree | 81c0937808f43907ef1adad6c596755194ea6ee3 /src | |
parent | 8b33e3022f0dd882a8aa11634cabdf7b5a2054fc (diff) | |
download | lanes-b92dbd75b1c9988dcc83e5876e1ce2815145fa30.tar.gz lanes-b92dbd75b1c9988dcc83e5876e1ce2815145fa30.tar.bz2 lanes-b92dbd75b1c9988dcc83e5876e1ce2815145fa30.zip |
New compatibility helper luaG_rawget
Diffstat (limited to 'src')
-rw-r--r-- | src/compat.hpp | 35 | ||||
-rw-r--r-- | src/deep.cpp | 3 | ||||
-rw-r--r-- | src/intercopycontext.cpp | 28 | ||||
-rw-r--r-- | src/keeper.cpp | 14 | ||||
-rw-r--r-- | src/lane.cpp | 12 | ||||
-rw-r--r-- | src/linda.cpp | 3 |
6 files changed, 55 insertions, 40 deletions
diff --git a/src/compat.hpp b/src/compat.hpp index d864ae9..9a8dedf 100644 --- a/src/compat.hpp +++ b/src/compat.hpp | |||
@@ -271,6 +271,7 @@ static inline int WrapLuaGetField(LUA_GETFIELD f_, lua_State* const L_, StackInd | |||
271 | 271 | ||
272 | // ------------------------------------------------------------------------------------------------- | 272 | // ------------------------------------------------------------------------------------------------- |
273 | 273 | ||
274 | [[nodiscard]] | ||
274 | static inline LuaType luaG_getfield(lua_State* const L_, StackIndex const idx_, std::string_view const& name_) | 275 | static inline LuaType luaG_getfield(lua_State* const L_, StackIndex const idx_, std::string_view const& name_) |
275 | { | 276 | { |
276 | return static_cast<LuaType>(WrapLuaGetField(lua_getfield, L_, idx_, name_)); | 277 | return static_cast<LuaType>(WrapLuaGetField(lua_getfield, L_, idx_, name_)); |
@@ -278,6 +279,7 @@ static inline LuaType luaG_getfield(lua_State* const L_, StackIndex const idx_, | |||
278 | 279 | ||
279 | // ################################################################################################# | 280 | // ################################################################################################# |
280 | 281 | ||
282 | [[nodiscard]] | ||
281 | LuaType luaG_getmodule(lua_State* L_, std::string_view const& name_); | 283 | LuaType luaG_getmodule(lua_State* L_, std::string_view const& name_); |
282 | 284 | ||
283 | // ################################################################################################# | 285 | // ################################################################################################# |
@@ -350,6 +352,7 @@ static inline int WrapLuaResume(LUA_RESUME const lua_resume_, lua_State* const L | |||
350 | 352 | ||
351 | // ------------------------------------------------------------------------------------------------- | 353 | // ------------------------------------------------------------------------------------------------- |
352 | 354 | ||
355 | [[nodiscard]] | ||
353 | static inline LuaError luaG_resume(lua_State* const L_, lua_State* const from_, int const nargs_, int* const nresults_) | 356 | static inline LuaError luaG_resume(lua_State* const L_, lua_State* const from_, int const nargs_, int* const nresults_) |
354 | { | 357 | { |
355 | return ToLuaError(WrapLuaResume(lua_resume, L_, from_, nargs_, nresults_)); | 358 | return ToLuaError(WrapLuaResume(lua_resume, L_, from_, nargs_, nresults_)); |
@@ -357,6 +360,38 @@ static inline LuaError luaG_resume(lua_State* const L_, lua_State* const from_, | |||
357 | 360 | ||
358 | // ################################################################################################# | 361 | // ################################################################################################# |
359 | 362 | ||
363 | template <typename LUA_RAWGET> | ||
364 | concept RequiresOldLuaRawget = requires(LUA_RAWGET f_) { { f_(nullptr, 0) } -> std::same_as<void>; }; | ||
365 | |||
366 | template <RequiresOldLuaRawget LUA_RAWGET> | ||
367 | static inline LuaType WrapLuaRawget(LUA_RAWGET lua_rawget_, lua_State* const L_, StackIndex const idx_) | ||
368 | { | ||
369 | // until Lua 5.3, lua_rawget -> void | ||
370 | lua_rawget_(L_, idx_); | ||
371 | return luaG_type(L_, kIdxTop); | ||
372 | } | ||
373 | |||
374 | // ------------------------------------------------------------------------------------------------- | ||
375 | |||
376 | template <typename LUA_RAWGET> | ||
377 | concept RequiresNewLuaRawget = requires(LUA_RAWGET f_) { { f_(nullptr, 0) } -> std::same_as<int>; }; | ||
378 | |||
379 | template <RequiresNewLuaRawget LUA_RAWGET> | ||
380 | static inline LuaType WrapLuaRawget(LUA_RAWGET lua_rawget_, lua_State* const L_, StackIndex const idx_) | ||
381 | { | ||
382 | // starting with Lua 5.3, lua_rawget -> int (the type of the extracted value) | ||
383 | return static_cast<LuaType>(lua_rawget_(L_, idx_)); | ||
384 | } | ||
385 | |||
386 | // ------------------------------------------------------------------------------------------------- | ||
387 | |||
388 | static inline LuaType luaG_rawget(lua_State* const L_, StackIndex const idx_) | ||
389 | { | ||
390 | return WrapLuaRawget(lua_rawget, L_, idx_); | ||
391 | } | ||
392 | |||
393 | // ################################################################################################# | ||
394 | |||
360 | static inline LuaType luaG_rawgetfield(lua_State* const L_, StackIndex const idx_, std::string_view const& name_) | 395 | static inline LuaType luaG_rawgetfield(lua_State* const L_, StackIndex const idx_, std::string_view const& name_) |
361 | { | 396 | { |
362 | auto const _absIdx{ luaG_absindex(L_, idx_) }; | 397 | auto const _absIdx{ luaG_absindex(L_, idx_) }; |
diff --git a/src/deep.cpp b/src/deep.cpp index c1ef30e..82f1214 100644 --- a/src/deep.cpp +++ b/src/deep.cpp | |||
@@ -190,8 +190,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
190 | 190 | ||
191 | // Check if a proxy already exists | 191 | // Check if a proxy already exists |
192 | lua_pushlightuserdata(L_, prelude_); // L_: DPC deep | 192 | lua_pushlightuserdata(L_, prelude_); // L_: DPC deep |
193 | lua_rawget(L_, -2); // L_: DPC proxy | 193 | if (luaG_rawget(L_, StackIndex{ -2 }) != LuaType::NIL) { // L_: DPC proxy |
194 | if (!lua_isnil(L_, -1)) { | ||
195 | lua_remove(L_, -2); // L_: proxy | 194 | lua_remove(L_, -2); // L_: proxy |
196 | STACK_CHECK(L_, 1); | 195 | STACK_CHECK(L_, 1); |
197 | return; | 196 | return; |
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index da4340e..d6716a3 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp | |||
@@ -337,10 +337,9 @@ void InterCopyContext::lookupNativeFunction() const | |||
337 | STACK_CHECK(L2, 1); | 337 | STACK_CHECK(L2, 1); |
338 | LUA_ASSERT(L1, lua_istable(L2, -1)); | 338 | LUA_ASSERT(L1, lua_istable(L2, -1)); |
339 | luaG_pushstring(L2, _fqn); // L1: ... f ... L2: {} "f.q.n" | 339 | luaG_pushstring(L2, _fqn); // L1: ... f ... L2: {} "f.q.n" |
340 | lua_rawget(L2, -2); // L1: ... f ... L2: {} f | 340 | LuaType const _objType{ luaG_rawget(L2, StackIndex{ -2 }) }; // L1: ... f ... L2: {} f |
341 | // nil means we don't know how to transfer stuff: user should do something | 341 | // nil means we don't know how to transfer stuff: user should do something |
342 | // anything other than function or table should not happen! | 342 | // anything other than function or table should not happen! |
343 | LuaType const _objType{ luaG_type(L2, kIdxTop) }; | ||
344 | if (_objType != LuaType::FUNCTION && _objType != LuaType::TABLE && _objType != LuaType::USERDATA) { | 343 | if (_objType != LuaType::FUNCTION && _objType != LuaType::TABLE && _objType != LuaType::USERDATA) { |
345 | kLaneNameRegKey.pushValue(L1); // L1: ... f ... lane_name | 344 | kLaneNameRegKey.pushValue(L1); // L1: ... f ... lane_name |
346 | std::string_view const _from{ luaG_tostring(L1, kIdxTop) }; | 345 | std::string_view const _from{ luaG_tostring(L1, kIdxTop) }; |
@@ -390,9 +389,7 @@ void InterCopyContext::copyCachedFunction() const | |||
390 | //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaG_tostring(L2, -1) << " >>" << std::endl); | 389 | //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaG_tostring(L2, -1) << " >>" << std::endl); |
391 | 390 | ||
392 | lua_pushvalue(L2, -1); // L2: ... {cache} ... p p | 391 | lua_pushvalue(L2, -1); // L2: ... {cache} ... p p |
393 | lua_rawget(L2, L2_cache_i); // L2: ... {cache} ... p function|nil|true | 392 | if (luaG_rawget(L2, L2_cache_i) == LuaType::NIL) { // function is unknown // L2: ... {cache} ... p function|nil|true |
394 | |||
395 | if (lua_isnil(L2, -1)) { // function is unknown | ||
396 | lua_pop(L2, 1); // L2: ... {cache} ... p | 393 | lua_pop(L2, 1); // L2: ... {cache} ... p |
397 | 394 | ||
398 | // Set to 'true' for the duration of creation; need to find self-references | 395 | // Set to 'true' for the duration of creation; need to find self-references |
@@ -443,10 +440,9 @@ bool InterCopyContext::lookupTable() const | |||
443 | STACK_CHECK(L2, 1); | 440 | STACK_CHECK(L2, 1); |
444 | LUA_ASSERT(L1, lua_istable(L2, -1)); | 441 | LUA_ASSERT(L1, lua_istable(L2, -1)); |
445 | luaG_pushstring(L2, _fqn); // L2: {} "f.q.n" | 442 | luaG_pushstring(L2, _fqn); // L2: {} "f.q.n" |
446 | lua_rawget(L2, -2); // L2: {} t | ||
447 | // we accept destination lookup failures in the case of transfering the Lanes body function (this will result in the source table being cloned instead) | 443 | // we accept destination lookup failures in the case of transfering the Lanes body function (this will result in the source table being cloned instead) |
448 | // but not when we extract something out of a keeper, as there is nothing to clone! | 444 | // but not when we extract something out of a keeper, as there is nothing to clone! |
449 | if (lua_isnil(L2, -1) && mode == LookupMode::LaneBody) { | 445 | if (luaG_rawget(L2, StackIndex{ -2 }) == LuaType::NIL && mode == LookupMode::LaneBody) { // L2: {} t |
450 | lua_pop(L2, 2); // L1: ... t ... L2: | 446 | lua_pop(L2, 2); // L1: ... t ... L2: |
451 | STACK_CHECK(L2, 0); | 447 | STACK_CHECK(L2, 0); |
452 | return false; | 448 | return false; |
@@ -619,10 +615,7 @@ bool InterCopyContext::pushCachedMetatable() const | |||
619 | // do we already know this metatable? | 615 | // do we already know this metatable? |
620 | std::ignore = kMtIdRegKey.getSubTable(L2, NArr{ 0 }, NRec{ 0 }); // L2: _R[kMtIdRegKey] | 616 | std::ignore = kMtIdRegKey.getSubTable(L2, NArr{ 0 }, NRec{ 0 }); // L2: _R[kMtIdRegKey] |
621 | lua_pushinteger(L2, _mt_id); // L2: _R[kMtIdRegKey] id | 617 | lua_pushinteger(L2, _mt_id); // L2: _R[kMtIdRegKey] id |
622 | lua_rawget(L2, -2); // L2: _R[kMtIdRegKey] mt|nil | 618 | if (luaG_rawget(L2, StackIndex{ -2 }) == LuaType::NIL) { // L2 did not know the metatable // L2: _R[kMtIdRegKey] mt|nil |
623 | STACK_CHECK(L2, 2); | ||
624 | |||
625 | if (lua_isnil(L2, -1)) { // L2 did not know the metatable | ||
626 | lua_pop(L2, 1); // L2: _R[kMtIdRegKey] | 619 | lua_pop(L2, 1); // L2: _R[kMtIdRegKey] |
627 | InterCopyContext const _c{ U, L2, L1, L2_cache_i, SourceIndex{ lua_gettop(L1) }, VT::METATABLE, mode, name }; | 620 | InterCopyContext const _c{ U, L2, L1, L2_cache_i, SourceIndex{ lua_gettop(L1) }, VT::METATABLE, mode, name }; |
628 | if (_c.interCopyOne() != InterCopyResult::Success) { // L2: _R[kMtIdRegKey] mt? | 621 | if (_c.interCopyOne() != InterCopyResult::Success) { // L2: _R[kMtIdRegKey] mt? |
@@ -671,8 +664,7 @@ bool InterCopyContext::pushCachedTable() const | |||
671 | 664 | ||
672 | //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaG_tostring(L2, -1) << " >>" << std::endl); | 665 | //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaG_tostring(L2, -1) << " >>" << std::endl); |
673 | 666 | ||
674 | lua_rawget(L2, L2_cache_i); // L1: ... t ... L2: ... {cached|nil} | 667 | bool const _not_found_in_cache{ luaG_rawget(L2, L2_cache_i) == LuaType::NIL }; // L1: ... t ... L2: ... {cached|nil} |
675 | bool const _not_found_in_cache{ lua_isnil(L2, -1) }; | ||
676 | if (_not_found_in_cache) { | 668 | if (_not_found_in_cache) { |
677 | // create a new entry in the cache | 669 | // create a new entry in the cache |
678 | lua_pop(L2, 1); // L1: ... t ... L2: ... | 670 | lua_pop(L2, 1); // L1: ... t ... L2: ... |
@@ -714,10 +706,10 @@ bool InterCopyContext::lookupUserdata() const | |||
714 | STACK_CHECK(L2, 1); | 706 | STACK_CHECK(L2, 1); |
715 | LUA_ASSERT(L1, lua_istable(L2, -1)); | 707 | LUA_ASSERT(L1, lua_istable(L2, -1)); |
716 | luaG_pushstring(L2, _fqn); // L1: ... f ... L2: {} "f.q.n" | 708 | luaG_pushstring(L2, _fqn); // L1: ... f ... L2: {} "f.q.n" |
717 | lua_rawget(L2, -2); // L1: ... f ... L2: {} f | 709 | LuaType const _type{ luaG_rawget(L2, StackIndex{ -2 }) }; // L1: ... f ... L2: {} f |
718 | // nil means we don't know how to transfer stuff: user should do something | 710 | // nil means we don't know how to transfer stuff: user should do something |
719 | // anything other than function or table should not happen! | 711 | // anything other than function or table should not happen! |
720 | if (!lua_isfunction(L2, -1) && !lua_istable(L2, -1)) { | 712 | if (_type != LuaType::FUNCTION && _type != LuaType::TABLE) { |
721 | kLaneNameRegKey.pushValue(L1); // L1: ... f ... lane_name | 713 | kLaneNameRegKey.pushValue(L1); // L1: ... f ... lane_name |
722 | std::string_view const _from{ luaG_tostring(L1, kIdxTop) }; | 714 | std::string_view const _from{ luaG_tostring(L1, kIdxTop) }; |
723 | lua_pop(L1, 1); // L1: ... f ... | 715 | lua_pop(L1, 1); // L1: ... f ... |
@@ -752,8 +744,7 @@ bool InterCopyContext::tryCopyClonable() const | |||
752 | 744 | ||
753 | // Check if the source was already cloned during this copy | 745 | // Check if the source was already cloned during this copy |
754 | lua_pushlightuserdata(L2, _source); // L2: ... source | 746 | lua_pushlightuserdata(L2, _source); // L2: ... source |
755 | lua_rawget(L2, L2_cache_i); // L2: ... clone? | 747 | if (luaG_rawget(L2, L2_cache_i) != LuaType::NIL) { // L2: ... clone? |
756 | if (!lua_isnil(L2, -1)) { | ||
757 | STACK_CHECK(L2, 1); | 748 | STACK_CHECK(L2, 1); |
758 | return true; | 749 | return true; |
759 | } else { | 750 | } else { |
@@ -920,8 +911,7 @@ bool InterCopyContext::interCopyFunction() const | |||
920 | lua_getupvalue(L1, L1_i, 2); // L1: ... u | 911 | lua_getupvalue(L1, L1_i, 2); // L1: ... u |
921 | void* _source{ lua_touserdata(L1, -1) }; | 912 | void* _source{ lua_touserdata(L1, -1) }; |
922 | lua_pushlightuserdata(L2, _source); // L2: ... source | 913 | lua_pushlightuserdata(L2, _source); // L2: ... source |
923 | lua_rawget(L2, L2_cache_i); // L2: ... u? | 914 | if (luaG_rawget(L2, L2_cache_i) != LuaType::NIL) { // L2: ... u? |
924 | if (!lua_isnil(L2, -1)) { | ||
925 | lua_pop(L1, 1); // L1: ... | 915 | lua_pop(L1, 1); // L1: ... |
926 | STACK_CHECK(L1, 0); | 916 | STACK_CHECK(L1, 0); |
927 | STACK_CHECK(L2, 1); | 917 | STACK_CHECK(L2, 1); |
diff --git a/src/keeper.cpp b/src/keeper.cpp index 43f3125..cad9207 100644 --- a/src/keeper.cpp +++ b/src/keeper.cpp | |||
@@ -315,9 +315,7 @@ static void PushKeysDB(KeeperState const K_, StackIndex const idx_) | |||
315 | StackIndex const _absidx{ luaG_absindex(K_, idx_) }; | 315 | StackIndex const _absidx{ luaG_absindex(K_, idx_) }; |
316 | kLindasRegKey.pushValue(K_); // K_: ... LindasDB | 316 | kLindasRegKey.pushValue(K_); // K_: ... LindasDB |
317 | lua_pushvalue(K_, _absidx); // K_: ... LindasDB linda | 317 | lua_pushvalue(K_, _absidx); // K_: ... LindasDB linda |
318 | lua_rawget(K_, -2); // K_: ... LindasDB KeysDB | 318 | if (luaG_rawget(K_, StackIndex{ -2 }) == LuaType::NIL) { // K_: ... LindasDB KeysDB |
319 | STACK_CHECK(K_, 2); | ||
320 | if (lua_isnil(K_, -1)) { | ||
321 | lua_pop(K_, 1); // K_: ... LindasDB | 319 | lua_pop(K_, 1); // K_: ... LindasDB |
322 | // add a new KeysDB table for this linda | 320 | // add a new KeysDB table for this linda |
323 | lua_newtable(K_); // K_: ... LindasDB KeysDB | 321 | lua_newtable(K_); // K_: ... LindasDB KeysDB |
@@ -372,8 +370,7 @@ int keepercall_count(lua_State* const L_) | |||
372 | case 2: // _K: linda key | 370 | case 2: // _K: linda key |
373 | PushKeysDB(_K, StackIndex{ 1 }); // _K: linda key KeysDB | 371 | PushKeysDB(_K, StackIndex{ 1 }); // _K: linda key KeysDB |
374 | lua_replace(_K, 1); // _K: KeysDB key | 372 | lua_replace(_K, 1); // _K: KeysDB key |
375 | lua_rawget(_K, -2); // _K: KeysDB KeyUD|nil | 373 | if (luaG_rawget(_K, StackIndex{ -2 }) == LuaType::NIL) { // the key is unknown // _K: KeysDB KeyUD|nil |
376 | if (lua_isnil(_K, -1)) { // the key is unknown // _K: KeysDB nil | ||
377 | lua_remove(_K, -2); // _K: nil | 374 | lua_remove(_K, -2); // _K: nil |
378 | } else { // the key is known // _K: KeysDB KeyUD | 375 | } else { // the key is known // _K: KeysDB KeyUD |
379 | KeyUD* const _key{ KeyUD::GetPtr(_K, kIdxTop) }; | 376 | KeyUD* const _key{ KeyUD::GetPtr(_K, kIdxTop) }; |
@@ -656,8 +653,7 @@ int keepercall_send(lua_State* const L_) | |||
656 | PushKeysDB(_K, StackIndex{ 1 }); // _K: linda key val... KeysDB | 653 | PushKeysDB(_K, StackIndex{ 1 }); // _K: linda key val... KeysDB |
657 | // get the fifo associated to this key in this linda, create it if it doesn't exist | 654 | // get the fifo associated to this key in this linda, create it if it doesn't exist |
658 | lua_pushvalue(_K, 2); // _K: linda key val... KeysDB key | 655 | lua_pushvalue(_K, 2); // _K: linda key val... KeysDB key |
659 | lua_rawget(_K, -2); // _K: linda key val... KeysDB KeyUD|nil | 656 | if (luaG_rawget(_K, StackIndex{ -2 }) == LuaType::NIL) { // _K: linda key val... KeysDB KeyUD|nil |
660 | if (lua_isnil(_K, -1)) { | ||
661 | lua_pop(_K, 1); // _K: linda key val... KeysDB | 657 | lua_pop(_K, 1); // _K: linda key val... KeysDB |
662 | std::ignore = KeyUD::Create(KeeperState{ _K }); // _K: linda key val... KeysDB KeyUD | 658 | std::ignore = KeyUD::Create(KeeperState{ _K }); // _K: linda key val... KeysDB KeyUD |
663 | // KeysDB[key] = KeyUD | 659 | // KeysDB[key] = KeyUD |
@@ -853,9 +849,9 @@ int Keeper::PushLindaStorage(Linda& linda_, DestState const L_) | |||
853 | STACK_CHECK_START_REL(_K, 0); | 849 | STACK_CHECK_START_REL(_K, 0); |
854 | kLindasRegKey.pushValue(_K); // _K: LindasDB L_: | 850 | kLindasRegKey.pushValue(_K); // _K: LindasDB L_: |
855 | lua_pushlightuserdata(_K, &linda_); // _K: LindasDB linda L_: | 851 | lua_pushlightuserdata(_K, &linda_); // _K: LindasDB linda L_: |
856 | lua_rawget(_K, -2); // _K: LindasDB KeysDB L_: | 852 | LuaType const _type{ luaG_rawget(_K, StackIndex{ -2 }) }; // _K: LindasDB KeysDB L_: |
857 | lua_remove(_K, -2); // _K: KeysDB L_: | 853 | lua_remove(_K, -2); // _K: KeysDB L_: |
858 | if (!lua_istable(_K, -1)) { // possible if we didn't send anything through that linda | 854 | if (_type != LuaType::TABLE) { // possible if we didn't send anything through that linda |
859 | lua_pop(_K, 1); // _K: L_: | 855 | lua_pop(_K, 1); // _K: L_: |
860 | STACK_CHECK(_K, 0); | 856 | STACK_CHECK(_K, 0); |
861 | return 0; | 857 | return 0; |
diff --git a/src/lane.cpp b/src/lane.cpp index 5b05b4e..7a5c257 100644 --- a/src/lane.cpp +++ b/src/lane.cpp | |||
@@ -298,8 +298,7 @@ static int lane_index_string(lua_State* L_) | |||
298 | // look in metatable first | 298 | // look in metatable first |
299 | lua_getmetatable(L_, kIdxSelf); // L_: lane "key" mt | 299 | lua_getmetatable(L_, kIdxSelf); // L_: lane "key" mt |
300 | lua_replace(L_, -3); // L_: mt "key" | 300 | lua_replace(L_, -3); // L_: mt "key" |
301 | lua_rawget(L_, -2); // L_: mt value | 301 | if (luaG_rawget(L_, StackIndex{ -2 }) != LuaType::NIL) { // found something? // L_: mt value |
302 | if (luaG_type(L_, kIdxTop) != LuaType::NIL) { // found something? | ||
303 | return 1; // done | 302 | return 1; // done |
304 | } | 303 | } |
305 | 304 | ||
@@ -335,14 +334,12 @@ static LUAG_FUNC(lane_index) | |||
335 | default: // unknown key | 334 | default: // unknown key |
336 | lua_getmetatable(L_, kIdxSelf); // L_: mt | 335 | lua_getmetatable(L_, kIdxSelf); // L_: mt |
337 | kCachedError.pushKey(L_); // L_: mt kCachedError | 336 | kCachedError.pushKey(L_); // L_: mt kCachedError |
338 | lua_rawget(L_, -2); // L_: mt error() | 337 | if (luaG_rawget(L_, StackIndex{ -2 }) != LuaType::FUNCTION) { // L_: mt error() |
339 | if (luaG_type(L_, kIdxTop) != LuaType::FUNCTION) { | ||
340 | raise_luaL_error(L_, "INTERNAL ERROR: cached error() is a %s, not a function", luaG_typename(L_, kIdxTop).data()); | 338 | raise_luaL_error(L_, "INTERNAL ERROR: cached error() is a %s, not a function", luaG_typename(L_, kIdxTop).data()); |
341 | } | 339 | } |
342 | luaG_pushstring(L_, "Unknown key: "); // L_: mt error() "Unknown key: " | 340 | luaG_pushstring(L_, "Unknown key: "); // L_: mt error() "Unknown key: " |
343 | kCachedTostring.pushKey(L_); // L_: mt error() "Unknown key: " kCachedTostring | 341 | kCachedTostring.pushKey(L_); // L_: mt error() "Unknown key: " kCachedTostring |
344 | lua_rawget(L_, -4); // L_: mt error() "Unknown key: " tostring() | 342 | if (luaG_rawget(L_, StackIndex{ -4 }) != LuaType::FUNCTION) { // L_: mt error() "Unknown key: " tostring() |
345 | if (luaG_type(L_, kIdxTop) != LuaType::FUNCTION) { | ||
346 | raise_luaL_error(L_, "INTERNAL ERROR: cached tostring() is a %s, not a function", luaG_typename(L_, kIdxTop).data()); | 343 | raise_luaL_error(L_, "INTERNAL ERROR: cached tostring() is a %s, not a function", luaG_typename(L_, kIdxTop).data()); |
347 | } | 344 | } |
348 | lua_pushvalue(L_, kKey); // L_: mt error() "Unknown key: " tostring() k | 345 | lua_pushvalue(L_, kKey); // L_: mt error() "Unknown key: " tostring() k |
@@ -840,8 +837,7 @@ static LUAG_FUNC(lane_gc) | |||
840 | // if there a gc callback? | 837 | // if there a gc callback? |
841 | lua_getiuservalue(L_, StackIndex{ 1 }, UserValueIndex{ 1 }); // L_: ud uservalue | 838 | lua_getiuservalue(L_, StackIndex{ 1 }, UserValueIndex{ 1 }); // L_: ud uservalue |
842 | kLaneGC.pushKey(L_); // L_: ud uservalue __gc | 839 | kLaneGC.pushKey(L_); // L_: ud uservalue __gc |
843 | lua_rawget(L_, -2); // L_: ud uservalue gc_cb|nil | 840 | if (luaG_rawget(L_, StackIndex{ -2 }) != LuaType::NIL) { // L_: ud uservalue gc_cb|nil |
844 | if (!lua_isnil(L_, -1)) { | ||
845 | lua_remove(L_, -2); // L_: ud gc_cb|nil | 841 | lua_remove(L_, -2); // L_: ud gc_cb|nil |
846 | luaG_pushstring(L_, _lane->getDebugName()); // L_: ud gc_cb name | 842 | luaG_pushstring(L_, _lane->getDebugName()); // L_: ud gc_cb name |
847 | _have_gc_cb = true; | 843 | _have_gc_cb = true; |
diff --git a/src/linda.cpp b/src/linda.cpp index 4f33899..a094a8f 100644 --- a/src/linda.cpp +++ b/src/linda.cpp | |||
@@ -417,8 +417,7 @@ static int linda_index_string(lua_State* L_) | |||
417 | // look in metatable first | 417 | // look in metatable first |
418 | lua_getmetatable(L_, kIdxSelf); // L_: linda "key" mt | 418 | lua_getmetatable(L_, kIdxSelf); // L_: linda "key" mt |
419 | lua_replace(L_, -3); // L_: mt "key" | 419 | lua_replace(L_, -3); // L_: mt "key" |
420 | lua_rawget(L_, -2); // L_: mt value | 420 | if (luaG_rawget(L_, StackIndex{ -2 }) != LuaType::NIL) { // found something? // L_: mt value |
421 | if (luaG_type(L_, kIdxTop) != LuaType::NIL) { // found something? | ||
422 | return 1; // done | 421 | return 1; // done |
423 | } | 422 | } |
424 | 423 | ||