diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-04 17:48:14 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-04 17:48:14 +0200 |
commit | b6d344fe7991b525958a5825fbd22d7c529d21cc (patch) | |
tree | 1cf8b728870d717054bbd05c58b826ad09d0a211 /src | |
parent | 6d90af6ab9ccdfb2f20fb73fc2d6400c23521c0a (diff) | |
download | lanes-b6d344fe7991b525958a5825fbd22d7c529d21cc.tar.gz lanes-b6d344fe7991b525958a5825fbd22d7c529d21cc.tar.bz2 lanes-b6d344fe7991b525958a5825fbd22d7c529d21cc.zip |
lua_absindex → luaG_absindex for inlining
Diffstat (limited to 'src')
-rw-r--r-- | src/compat.cpp | 2 | ||||
-rw-r--r-- | src/compat.h | 4 | ||||
-rw-r--r-- | src/intercopycontext.cpp | 14 | ||||
-rw-r--r-- | src/lane.cpp | 2 | ||||
-rw-r--r-- | src/tools.cpp | 4 |
5 files changed, 11 insertions, 15 deletions
diff --git a/src/compat.cpp b/src/compat.cpp index 66fa3d5..5923d29 100644 --- a/src/compat.cpp +++ b/src/compat.cpp | |||
@@ -39,7 +39,7 @@ int luaL_getsubtable(lua_State* L_, int idx_, const char* fname_) | |||
39 | return 1; /* table already there */ | 39 | return 1; /* table already there */ |
40 | else { | 40 | else { |
41 | lua_pop(L_, 1); /* remove previous result */ | 41 | lua_pop(L_, 1); /* remove previous result */ |
42 | idx_ = lua_absindex(L_, idx_); | 42 | idx_ = luaG_absindex(L_, idx_); |
43 | lua_newtable(L_); | 43 | lua_newtable(L_); |
44 | lua_pushvalue(L_, -1); /* copy to be left at top */ | 44 | lua_pushvalue(L_, -1); /* copy to be left at top */ |
45 | lua_setfield(L_, idx_, fname_); /* assign new table to field */ | 45 | lua_setfield(L_, idx_, fname_); /* assign new table to field */ |
diff --git a/src/compat.h b/src/compat.h index ceb1275..43f8922 100644 --- a/src/compat.h +++ b/src/compat.h | |||
@@ -61,10 +61,6 @@ inline char const* lua_typename(lua_State* L_, LuaType t_) | |||
61 | // add some Lua 5.3-style API when building for Lua 5.1 | 61 | // add some Lua 5.3-style API when building for Lua 5.1 |
62 | #if LUA_VERSION_NUM == 501 | 62 | #if LUA_VERSION_NUM == 501 |
63 | 63 | ||
64 | inline int lua_absindex(lua_State* L_, int idx_) | ||
65 | { | ||
66 | return (((idx_) >= 0 || (idx_) <= LUA_REGISTRYINDEX) ? (idx_) : lua_gettop(L_) + (idx_) + 1); | ||
67 | } | ||
68 | #if LUAJIT_VERSION_NUM < 20200 // moonjit is 5.1 plus bits of 5.2 that we don't need to wrap | 64 | #if LUAJIT_VERSION_NUM < 20200 // moonjit is 5.1 plus bits of 5.2 that we don't need to wrap |
69 | inline void lua_pushglobaltable(lua_State* L_) | 65 | inline void lua_pushglobaltable(lua_State* L_) |
70 | { | 66 | { |
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index 07eea24..670b955 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp | |||
@@ -142,7 +142,7 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull }; | |||
142 | // get a unique ID for metatable at [i]. | 142 | // get a unique ID for metatable at [i]. |
143 | [[nodiscard]] static lua_Integer get_mt_id(Universe* U_, lua_State* L_, int idx_) | 143 | [[nodiscard]] static lua_Integer get_mt_id(Universe* U_, lua_State* L_, int idx_) |
144 | { | 144 | { |
145 | idx_ = lua_absindex(L_, idx_); | 145 | idx_ = luaG_absindex(L_, idx_); |
146 | 146 | ||
147 | STACK_GROW(L_, 3); | 147 | STACK_GROW(L_, 3); |
148 | 148 | ||
@@ -618,7 +618,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
618 | 618 | ||
619 | [[nodiscard]] bool InterCopyContext::tryCopyClonable() const | 619 | [[nodiscard]] bool InterCopyContext::tryCopyClonable() const |
620 | { | 620 | { |
621 | SourceIndex const _L1_i{ lua_absindex(L1, L1_i) }; | 621 | SourceIndex const _L1_i{ luaG_absindex(L1, L1_i) }; |
622 | void* const _source{ lua_touserdata(L1, _L1_i) }; | 622 | void* const _source{ lua_touserdata(L1, _L1_i) }; |
623 | 623 | ||
624 | STACK_CHECK_START_REL(L1, 0); | 624 | STACK_CHECK_START_REL(L1, 0); |
@@ -650,7 +650,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
650 | 650 | ||
651 | // we need to copy over the uservalues of the userdata as well | 651 | // we need to copy over the uservalues of the userdata as well |
652 | { | 652 | { |
653 | int const mt{ lua_absindex(L1, -2) }; // L1: ... mt __lanesclone | 653 | int const _mt{ luaG_absindex(L1, -2) }; // L1: ... mt __lanesclone |
654 | size_t const userdata_size{ lua_rawlen(L1, _L1_i) }; | 654 | size_t const userdata_size{ lua_rawlen(L1, _L1_i) }; |
655 | // extract all the uservalues, but don't transfer them yet | 655 | // extract all the uservalues, but don't transfer them yet |
656 | int _uvi{ 0 }; | 656 | int _uvi{ 0 }; |
@@ -661,7 +661,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
661 | // create the clone userdata with the required number of uservalue slots | 661 | // create the clone userdata with the required number of uservalue slots |
662 | void* const _clone{ lua_newuserdatauv(L2, userdata_size, _uvi) }; // L2: ... u | 662 | void* const _clone{ lua_newuserdatauv(L2, userdata_size, _uvi) }; // L2: ... u |
663 | // copy the metatable in the target state, and give it to the clone we put there | 663 | // copy the metatable in the target state, and give it to the clone we put there |
664 | InterCopyContext _c{ U, L2, L1, L2_cache_i, SourceIndex{ mt }, VT::NORMAL, mode, name }; | 664 | InterCopyContext _c{ U, L2, L1, L2_cache_i, SourceIndex{ _mt }, VT::NORMAL, mode, name }; |
665 | if (_c.inter_copy_one()) { // L2: ... u mt|sentinel | 665 | if (_c.inter_copy_one()) { // L2: ... u mt|sentinel |
666 | if (LookupMode::ToKeeper == mode) { // L2: ... u sentinel | 666 | if (LookupMode::ToKeeper == mode) { // L2: ... u sentinel |
667 | LUA_ASSERT(L1, lua_tocfunction(L2, -1) == table_lookup_sentinel); | 667 | LUA_ASSERT(L1, lua_tocfunction(L2, -1) == table_lookup_sentinel); |
@@ -688,7 +688,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
688 | } | 688 | } |
689 | // assign uservalues | 689 | // assign uservalues |
690 | while (_uvi > 0) { | 690 | while (_uvi > 0) { |
691 | _c.L1_i = SourceIndex{ lua_absindex(L1, -1) }; | 691 | _c.L1_i = SourceIndex{ luaG_absindex(L1, -1) }; |
692 | if (!_c.inter_copy_one()) { // L2: ... u uv | 692 | if (!_c.inter_copy_one()) { // L2: ... u uv |
693 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); | 693 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); |
694 | } | 694 | } |
@@ -748,7 +748,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
748 | InterCopyContext _c{ U, L2, L1, L2_cache_i, {}, VT::NORMAL, mode, name }; | 748 | InterCopyContext _c{ U, L2, L1, L2_cache_i, {}, VT::NORMAL, mode, name }; |
749 | int const _clone_i{ lua_gettop(L2) }; | 749 | int const _clone_i{ lua_gettop(L2) }; |
750 | while (_nuv) { | 750 | while (_nuv) { |
751 | _c.L1_i = SourceIndex{ lua_absindex(L1, -1) }; | 751 | _c.L1_i = SourceIndex{ luaG_absindex(L1, -1) }; |
752 | if (!_c.inter_copy_one()) { // L1: ... u [uv]* L2: u uv | 752 | if (!_c.inter_copy_one()) { // L1: ... u [uv]* L2: u uv |
753 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); | 753 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); |
754 | } | 754 | } |
@@ -835,7 +835,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
835 | // transfer and assign uservalues | 835 | // transfer and assign uservalues |
836 | InterCopyContext c{ *this }; | 836 | InterCopyContext c{ *this }; |
837 | while (_uvi > 0) { | 837 | while (_uvi > 0) { |
838 | c.L1_i = SourceIndex{ lua_absindex(L1, -1) }; | 838 | c.L1_i = SourceIndex{ luaG_absindex(L1, -1) }; |
839 | if (!c.inter_copy_one()) { // L2: ... mt u uv | 839 | if (!c.inter_copy_one()) { // L2: ... mt u uv |
840 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); | 840 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); |
841 | } | 841 | } |
diff --git a/src/lane.cpp b/src/lane.cpp index 029efdb..f07403f 100644 --- a/src/lane.cpp +++ b/src/lane.cpp | |||
@@ -804,7 +804,7 @@ Lane::~Lane() | |||
804 | 804 | ||
805 | void Lane::changeDebugName(int const nameIdx_) | 805 | void Lane::changeDebugName(int const nameIdx_) |
806 | { | 806 | { |
807 | int const _nameIdx{ lua_absindex(L, nameIdx_) }; | 807 | int const _nameIdx{ luaG_absindex(L, nameIdx_) }; |
808 | luaL_checktype(L, _nameIdx, LUA_TSTRING); // L: ... "name" ... | 808 | luaL_checktype(L, _nameIdx, LUA_TSTRING); // L: ... "name" ... |
809 | STACK_CHECK_START_REL(L, 0); | 809 | STACK_CHECK_START_REL(L, 0); |
810 | // store a hidden reference in the registry to make sure the string is kept around even if a lane decides to manually change the "decoda_name" global... | 810 | // store a hidden reference in the registry to make sure the string is kept around even if a lane decides to manually change the "decoda_name" global... |
diff --git a/src/tools.cpp b/src/tools.cpp index e6dadd2..e7d1775 100644 --- a/src/tools.cpp +++ b/src/tools.cpp | |||
@@ -71,7 +71,7 @@ static constexpr int kWriterReturnCode{ 666 }; | |||
71 | } | 71 | } |
72 | { | 72 | { |
73 | int _mustpush{ 0 }; | 73 | int _mustpush{ 0 }; |
74 | if (lua_absindex(L_, _i) != lua_gettop(L_)) { | 74 | if (luaG_absindex(L_, _i) != lua_gettop(L_)) { |
75 | lua_pushvalue(L_, _i); | 75 | lua_pushvalue(L_, _i); |
76 | _mustpush = 1; | 76 | _mustpush = 1; |
77 | } | 77 | } |
@@ -306,7 +306,7 @@ namespace tools { | |||
306 | // create a "fully.qualified.name" <-> function equivalence database | 306 | // create a "fully.qualified.name" <-> function equivalence database |
307 | void PopulateFuncLookupTable(lua_State* const L_, int const i_, std::string_view const& name_) | 307 | void PopulateFuncLookupTable(lua_State* const L_, int const i_, std::string_view const& name_) |
308 | { | 308 | { |
309 | int const _in_base{ lua_absindex(L_, i_) }; | 309 | int const _in_base{ luaG_absindex(L_, i_) }; |
310 | DEBUGSPEW_CODE(Universe* _U = Universe::Get(L_)); | 310 | DEBUGSPEW_CODE(Universe* _U = Universe::Get(L_)); |
311 | std::string_view _name{ name_.empty() ? std::string_view{} : name_ }; | 311 | std::string_view _name{ name_.empty() ? std::string_view{} : name_ }; |
312 | DEBUGSPEW_CODE(DebugSpew(_U) << L_ << ": PopulateFuncLookupTable('" << _name << "')" << std::endl); | 312 | DEBUGSPEW_CODE(DebugSpew(_U) << L_ << ": PopulateFuncLookupTable('" << _name << "')" << std::endl); |