From b6d344fe7991b525958a5825fbd22d7c529d21cc Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Tue, 4 Jun 2024 17:48:14 +0200 Subject: lua_absindex → luaG_absindex for inlining MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/compat.cpp | 2 +- src/compat.h | 4 ---- src/intercopycontext.cpp | 14 +++++++------- src/lane.cpp | 2 +- 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_) return 1; /* table already there */ else { lua_pop(L_, 1); /* remove previous result */ - idx_ = lua_absindex(L_, idx_); + idx_ = luaG_absindex(L_, idx_); lua_newtable(L_); lua_pushvalue(L_, -1); /* copy to be left at top */ 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_) // add some Lua 5.3-style API when building for Lua 5.1 #if LUA_VERSION_NUM == 501 -inline int lua_absindex(lua_State* L_, int idx_) -{ - return (((idx_) >= 0 || (idx_) <= LUA_REGISTRYINDEX) ? (idx_) : lua_gettop(L_) + (idx_) + 1); -} #if LUAJIT_VERSION_NUM < 20200 // moonjit is 5.1 plus bits of 5.2 that we don't need to wrap inline void lua_pushglobaltable(lua_State* L_) { 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 }; // get a unique ID for metatable at [i]. [[nodiscard]] static lua_Integer get_mt_id(Universe* U_, lua_State* L_, int idx_) { - idx_ = lua_absindex(L_, idx_); + idx_ = luaG_absindex(L_, idx_); STACK_GROW(L_, 3); @@ -618,7 +618,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const [[nodiscard]] bool InterCopyContext::tryCopyClonable() const { - SourceIndex const _L1_i{ lua_absindex(L1, L1_i) }; + SourceIndex const _L1_i{ luaG_absindex(L1, L1_i) }; void* const _source{ lua_touserdata(L1, _L1_i) }; STACK_CHECK_START_REL(L1, 0); @@ -650,7 +650,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const // we need to copy over the uservalues of the userdata as well { - int const mt{ lua_absindex(L1, -2) }; // L1: ... mt __lanesclone + int const _mt{ luaG_absindex(L1, -2) }; // L1: ... mt __lanesclone size_t const userdata_size{ lua_rawlen(L1, _L1_i) }; // extract all the uservalues, but don't transfer them yet int _uvi{ 0 }; @@ -661,7 +661,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const // create the clone userdata with the required number of uservalue slots void* const _clone{ lua_newuserdatauv(L2, userdata_size, _uvi) }; // L2: ... u // copy the metatable in the target state, and give it to the clone we put there - InterCopyContext _c{ U, L2, L1, L2_cache_i, SourceIndex{ mt }, VT::NORMAL, mode, name }; + InterCopyContext _c{ U, L2, L1, L2_cache_i, SourceIndex{ _mt }, VT::NORMAL, mode, name }; if (_c.inter_copy_one()) { // L2: ... u mt|sentinel if (LookupMode::ToKeeper == mode) { // L2: ... u sentinel LUA_ASSERT(L1, lua_tocfunction(L2, -1) == table_lookup_sentinel); @@ -688,7 +688,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const } // assign uservalues while (_uvi > 0) { - _c.L1_i = SourceIndex{ lua_absindex(L1, -1) }; + _c.L1_i = SourceIndex{ luaG_absindex(L1, -1) }; if (!_c.inter_copy_one()) { // L2: ... u uv raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); } @@ -748,7 +748,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const InterCopyContext _c{ U, L2, L1, L2_cache_i, {}, VT::NORMAL, mode, name }; int const _clone_i{ lua_gettop(L2) }; while (_nuv) { - _c.L1_i = SourceIndex{ lua_absindex(L1, -1) }; + _c.L1_i = SourceIndex{ luaG_absindex(L1, -1) }; if (!_c.inter_copy_one()) { // L1: ... u [uv]* L2: u uv raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); } @@ -835,7 +835,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const // transfer and assign uservalues InterCopyContext c{ *this }; while (_uvi > 0) { - c.L1_i = SourceIndex{ lua_absindex(L1, -1) }; + c.L1_i = SourceIndex{ luaG_absindex(L1, -1) }; if (!c.inter_copy_one()) { // L2: ... mt u uv raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); } 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() void Lane::changeDebugName(int const nameIdx_) { - int const _nameIdx{ lua_absindex(L, nameIdx_) }; + int const _nameIdx{ luaG_absindex(L, nameIdx_) }; luaL_checktype(L, _nameIdx, LUA_TSTRING); // L: ... "name" ... STACK_CHECK_START_REL(L, 0); // 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 }; } { int _mustpush{ 0 }; - if (lua_absindex(L_, _i) != lua_gettop(L_)) { + if (luaG_absindex(L_, _i) != lua_gettop(L_)) { lua_pushvalue(L_, _i); _mustpush = 1; } @@ -306,7 +306,7 @@ namespace tools { // create a "fully.qualified.name" <-> function equivalence database void PopulateFuncLookupTable(lua_State* const L_, int const i_, std::string_view const& name_) { - int const _in_base{ lua_absindex(L_, i_) }; + int const _in_base{ luaG_absindex(L_, i_) }; DEBUGSPEW_CODE(Universe* _U = Universe::Get(L_)); std::string_view _name{ name_.empty() ? std::string_view{} : name_ }; DEBUGSPEW_CODE(DebugSpew(_U) << L_ << ": PopulateFuncLookupTable('" << _name << "')" << std::endl); -- cgit v1.2.3-55-g6feb