From 042055968ab0c48faec607889814e38c50c09efa Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Fri, 4 Jul 2025 13:50:53 +0200 Subject: Changed lua wrapper prefixes from luaG_ to luaW_ (w as in wrapper!) --- src/allocator.cpp | 2 +- src/cancel.cpp | 14 ++--- src/compat.cpp | 12 ++-- src/compat.hpp | 66 +++++++++++----------- src/deep.cpp | 28 +++++----- src/intercopycontext.cpp | 142 +++++++++++++++++++++++------------------------ src/keeper.cpp | 50 ++++++++--------- src/lane.cpp | 92 +++++++++++++++--------------- src/lanes.cpp | 58 +++++++++---------- src/linda.cpp | 60 ++++++++++---------- src/lindafactory.cpp | 16 +++--- src/nameof.cpp | 34 ++++++------ src/state.cpp | 18 +++--- src/threading.cpp | 4 +- src/tools.cpp | 50 ++++++++--------- src/tools.hpp | 2 +- src/tracker.cpp | 2 +- src/uniquekey.hpp | 6 +- src/universe.cpp | 56 +++++++++---------- src/universe.hpp | 2 +- 20 files changed, 357 insertions(+), 357 deletions(-) (limited to 'src') diff --git a/src/allocator.cpp b/src/allocator.cpp index 84acde5..243583b 100644 --- a/src/allocator.cpp +++ b/src/allocator.cpp @@ -35,7 +35,7 @@ namespace lanes { AllocatorDefinition& AllocatorDefinition::Validated(lua_State* const L_, StackIndex const idx_) { - lanes::AllocatorDefinition* const _def{ luaG_tofulluserdata(L_, idx_) }; + lanes::AllocatorDefinition* const _def{ luaW_tofulluserdata(L_, idx_) }; // raise an error and don't return if the full userdata at the specified index is not a valid AllocatorDefinition if (!_def) { raise_luaL_error(L_, "Bad config.allocator function, provided value is not a userdata"); diff --git a/src/cancel.cpp b/src/cancel.cpp index 2d8029e..6812b0d 100644 --- a/src/cancel.cpp +++ b/src/cancel.cpp @@ -70,8 +70,8 @@ namespace { [[nodiscard]] static CancelOp WhichCancelOp(lua_State* const L_, StackIndex const idx_) { - if (luaG_type(L_, idx_) == LuaType::STRING) { - std::string_view const _str{ luaG_tostring(L_, idx_) }; + if (luaW_type(L_, idx_) == LuaType::STRING) { + std::string_view const _str{ luaW_tostring(L_, idx_) }; auto const _op{ WhichCancelOp(_str) }; lua_remove(L_, idx_); // argument is processed, remove it if (!_op.has_value()) { @@ -123,7 +123,7 @@ LUAG_FUNC(cancel_test) if (_test == CancelRequest::None) { lua_pushboolean(L_, 0); } else { - luaG_pushstring(L_, (_test == CancelRequest::Soft) ? "soft" : "hard"); + luaW_pushstring(L_, (_test == CancelRequest::Soft) ? "soft" : "hard"); } return 1; } @@ -158,7 +158,7 @@ LUAG_FUNC(lane_cancel) // the caller shouldn't have provided a hook count in that case return 0; } - if (luaG_type(L_, StackIndex{ 2 }) != LuaType::NUMBER) { + if (luaW_type(L_, StackIndex{ 2 }) != LuaType::NUMBER) { raise_luaL_error(L_, "Hook count expected"); } auto const _hook_count{ static_cast(lua_tointeger(L_, 2)) }; @@ -170,7 +170,7 @@ LUAG_FUNC(lane_cancel) }) }; std::chrono::time_point _until{ std::chrono::time_point::max() }; - if (luaG_type(L_, StackIndex{ 2 }) == LuaType::NUMBER) { // we don't want to use lua_isnumber() because of autocoercion + if (luaW_type(L_, StackIndex{ 2 }) == LuaType::NUMBER) { // we don't want to use lua_isnumber() because of autocoercion lua_Duration const duration{ lua_tonumber(L_, 2) }; if (duration.count() >= 0.0) { _until = std::chrono::steady_clock::now() + std::chrono::duration_cast(duration); @@ -186,7 +186,7 @@ LUAG_FUNC(lane_cancel) WakeLane _wake_lane{ (_op.mode == CancelRequest::Hard) ? WakeLane::Yes : WakeLane::No }; if (lua_gettop(L_) >= 2) { if (!lua_isboolean(L_, 2)) { - raise_luaL_error(L_, "Boolean expected for wake_lane argument, got %s", luaG_typename(L_, StackIndex{ 2 }).data()); + raise_luaL_error(L_, "Boolean expected for wake_lane argument, got %s", luaW_typename(L_, StackIndex{ 2 }).data()); } _wake_lane = lua_toboolean(L_, 2) ? WakeLane::Yes : WakeLane::No; lua_remove(L_, 2); // argument is processed, remove it // L_: lane @@ -206,7 +206,7 @@ LUAG_FUNC(lane_cancel) case CancelResult::Timeout: lua_pushboolean(L_, 0); // L_: false - luaG_pushstring(L_, "timeout"); // L_: false "timeout" + luaW_pushstring(L_, "timeout"); // L_: false "timeout" break; case CancelResult::Cancelled: diff --git a/src/compat.cpp b/src/compat.cpp index 7e90142..08f22ca 100644 --- a/src/compat.cpp +++ b/src/compat.cpp @@ -5,10 +5,10 @@ // ################################################################################################# -UserValueCount luaG_getalluservalues(lua_State* const L_, StackIndex const idx_) +UserValueCount luaW_getalluservalues(lua_State* const L_, StackIndex const idx_) { STACK_CHECK_START_REL(L_, 0); - StackIndex const _idx{ luaG_absindex(L_, idx_) }; + StackIndex const _idx{ luaW_absindex(L_, idx_) }; UserValueIndex _nuv{ 0 }; do { // we don't know how many uservalues we are going to extract, there might be a lot... @@ -24,15 +24,15 @@ UserValueCount luaG_getalluservalues(lua_State* const L_, StackIndex const idx_) // ################################################################################################# // a small helper to obtain a module's table from the registry instead of relying on the presence of _G[""] -LuaType luaG_getmodule(lua_State* const L_, std::string_view const& name_) +LuaType luaW_getmodule(lua_State* const L_, std::string_view const& name_) { STACK_CHECK_START_REL(L_, 0); - LuaType _type{ luaG_getfield(L_, kIdxRegistry, LUA_LOADED_TABLE) }; // L_: _R._LOADED|nil + LuaType _type{ luaW_getfield(L_, kIdxRegistry, LUA_LOADED_TABLE) }; // L_: _R._LOADED|nil if (_type != LuaType::TABLE) { // L_: _R._LOADED|nil STACK_CHECK(L_, 1); return _type; } - _type = luaG_getfield(L_, kIdxTop, name_); // L_: _R._LOADED {module}|nil + _type = luaW_getfield(L_, kIdxTop, name_); // L_: _R._LOADED {module}|nil lua_remove(L_, -2); // L_: {module}|nil STACK_CHECK(L_, 1); return _type; @@ -52,7 +52,7 @@ int luaL_getsubtable(lua_State* const L_, StackIndex const idx_, char const* fna return 1; /* table already there */ } else { lua_pop(L_, 1); /* remove previous result */ - StackIndex const _absidx{ luaG_absindex(L_, idx_) }; + StackIndex const _absidx{ luaW_absindex(L_, idx_) }; lua_newtable(L_); lua_pushvalue(L_, -1); /* copy to be left at top */ lua_setfield(L_, _absidx, fname_); /* assign new table to field */ diff --git a/src/compat.hpp b/src/compat.hpp index 9a8dedf..99c468c 100644 --- a/src/compat.hpp +++ b/src/compat.hpp @@ -136,14 +136,14 @@ inline constexpr LuaError ToLuaError(int const rc_) // break lexical order for that one because it's needed below [[nodiscard]] -inline LuaType luaG_type(lua_State* const L_, StackIndex const idx_) +inline LuaType luaW_type(lua_State* const L_, StackIndex const idx_) { return static_cast(lua_type(L_, idx_)); } // ################################################################################################# // ################################################################################################# -// All the compatibility wrappers we expose start with luaG_ +// All the compatibility wrappers we expose start with luaW_ // ################################################################################################# // ################################################################################################# @@ -152,7 +152,7 @@ inline LuaType luaG_type(lua_State* const L_, StackIndex const idx_) // a replacement of lua_tolstring [[nodiscard]] -inline std::string_view luaG_tostring(lua_State* const L_, StackIndex const idx_) +inline std::string_view luaW_tostring(lua_State* const L_, StackIndex const idx_) { size_t _len{ 0 }; char const* _str{ lua_tolstring(L_, idx_, &_len) }; @@ -160,7 +160,7 @@ inline std::string_view luaG_tostring(lua_State* const L_, StackIndex const idx_ } [[nodiscard]] -inline std::string_view luaG_checkstring(lua_State* const L_, StackIndex const idx_) +inline std::string_view luaW_checkstring(lua_State* const L_, StackIndex const idx_) { size_t _len{ 0 }; char const* _str{ luaL_checklstring(L_, idx_, &_len) }; @@ -168,7 +168,7 @@ inline std::string_view luaG_checkstring(lua_State* const L_, StackIndex const i } [[nodiscard]] -inline std::string_view luaG_optstring(lua_State* const L_, StackIndex const idx_, std::string_view const& default_) +inline std::string_view luaW_optstring(lua_State* const L_, StackIndex const idx_, std::string_view const& default_) { if (lua_isnoneornil(L_, idx_)) { return default_; @@ -179,13 +179,13 @@ inline std::string_view luaG_optstring(lua_State* const L_, StackIndex const idx } template -inline std::string_view luaG_pushstring(lua_State* const L_, std::string_view const& str_, EXTRA&&... extra_) +inline std::string_view luaW_pushstring(lua_State* const L_, std::string_view const& str_, EXTRA&&... extra_) { if constexpr (sizeof...(EXTRA) == 0) { if constexpr (LUA_VERSION_NUM == 501) { // lua_pushlstring doesn't return a value in Lua 5.1 lua_pushlstring(L_, str_.data(), str_.size()); - return luaG_tostring(L_, kIdxTop); + return luaW_tostring(L_, kIdxTop); } else { return std::string_view{ lua_pushlstring(L_, str_.data(), str_.size()), str_.size() }; } @@ -198,7 +198,7 @@ inline std::string_view luaG_pushstring(lua_State* const L_, std::string_view co // ################################################################################################# // use this in place of lua_absindex to save a function call -inline StackIndex luaG_absindex(lua_State* const L_, StackIndex const idx_) +inline StackIndex luaW_absindex(lua_State* const L_, StackIndex const idx_) { return StackIndex{ (idx_ >= 0 || idx_ <= kIdxRegistry) ? idx_ : StackIndex{ lua_gettop(L_) + idx_ + 1 } }; } @@ -227,14 +227,14 @@ static inline int WrapLuaDump(LUA_DUMP f_, lua_State* const L_, lua_Writer const // ------------------------------------------------------------------------------------------------- -static inline int luaG_dump(lua_State* const L_, lua_Writer const writer_, void* const data_, int const strip_) +static inline int luaW_dump(lua_State* const L_, lua_Writer const writer_, void* const data_, int const strip_) { return WrapLuaDump(lua_dump, L_, writer_, data_, strip_); } // ################################################################################################# -UserValueCount luaG_getalluservalues(lua_State* L_, StackIndex idx_); +UserValueCount luaW_getalluservalues(lua_State* L_, StackIndex idx_); // ################################################################################################# @@ -272,7 +272,7 @@ static inline int WrapLuaGetField(LUA_GETFIELD f_, lua_State* const L_, StackInd // ------------------------------------------------------------------------------------------------- [[nodiscard]] -static inline LuaType luaG_getfield(lua_State* const L_, StackIndex const idx_, std::string_view const& name_) +static inline LuaType luaW_getfield(lua_State* const L_, StackIndex const idx_, std::string_view const& name_) { return static_cast(WrapLuaGetField(lua_getfield, L_, idx_, name_)); } @@ -280,21 +280,21 @@ static inline LuaType luaG_getfield(lua_State* const L_, StackIndex const idx_, // ################################################################################################# [[nodiscard]] -LuaType luaG_getmodule(lua_State* L_, std::string_view const& name_); +LuaType luaW_getmodule(lua_State* L_, std::string_view const& name_); // ################################################################################################# template requires std::is_enum_v [[nodiscard]] -ENUM luaG_optenum(lua_State* const L_, StackIndex const idx_, ENUM const def_) +ENUM luaW_optenum(lua_State* const L_, StackIndex const idx_, ENUM const def_) { return static_cast(luaL_optinteger(L_, idx_, static_cast>(def_))); } // ################################################################################################# -inline void luaG_registerlibfuncs(lua_State* const L_, luaL_Reg const* funcs_) +inline void luaW_registerlibfuncs(lua_State* const L_, luaL_Reg const* funcs_) { // fake externs to make clang happy... extern void luaL_register(lua_State*, char const*, luaL_Reg const*); // Lua 5.1 @@ -353,7 +353,7 @@ static inline int WrapLuaResume(LUA_RESUME const lua_resume_, lua_State* const L // ------------------------------------------------------------------------------------------------- [[nodiscard]] -static inline LuaError luaG_resume(lua_State* const L_, lua_State* const from_, int const nargs_, int* const nresults_) +static inline LuaError luaW_resume(lua_State* const L_, lua_State* const from_, int const nargs_, int* const nresults_) { return ToLuaError(WrapLuaResume(lua_resume, L_, from_, nargs_, nresults_)); } @@ -368,7 +368,7 @@ static inline LuaType WrapLuaRawget(LUA_RAWGET lua_rawget_, lua_State* const L_, { // until Lua 5.3, lua_rawget -> void lua_rawget_(L_, idx_); - return luaG_type(L_, kIdxTop); + return luaW_type(L_, kIdxTop); } // ------------------------------------------------------------------------------------------------- @@ -385,42 +385,42 @@ static inline LuaType WrapLuaRawget(LUA_RAWGET lua_rawget_, lua_State* const L_, // ------------------------------------------------------------------------------------------------- -static inline LuaType luaG_rawget(lua_State* const L_, StackIndex const idx_) +static inline LuaType luaW_rawget(lua_State* const L_, StackIndex const idx_) { return WrapLuaRawget(lua_rawget, L_, idx_); } // ################################################################################################# -static inline LuaType luaG_rawgetfield(lua_State* const L_, StackIndex const idx_, std::string_view const& name_) +static inline LuaType luaW_rawgetfield(lua_State* const L_, StackIndex const idx_, std::string_view const& name_) { - auto const _absIdx{ luaG_absindex(L_, idx_) }; - luaG_pushstring(L_, name_); // L_: ... t ... name_ + auto const _absIdx{ luaW_absindex(L_, idx_) }; + luaW_pushstring(L_, name_); // L_: ... t ... name_ lua_rawget(L_, _absIdx); // L_: ... t ... - return luaG_type(L_, kIdxTop); + return luaW_type(L_, kIdxTop); } // ################################################################################################# template -static inline void luaG_newlib(lua_State* const L_, luaL_Reg const (&funcs_)[N]) +static inline void luaW_newlib(lua_State* const L_, luaL_Reg const (&funcs_)[N]) { lua_createtable(L_, 0, N - 1); - luaG_registerlibfuncs(L_, funcs_); + luaW_registerlibfuncs(L_, funcs_); } // ################################################################################################# template [[nodiscard]] -T* luaG_newuserdatauv(lua_State* const L_, UserValueCount const nuvalue_) +T* luaW_newuserdatauv(lua_State* const L_, UserValueCount const nuvalue_) { return static_cast(lua_newuserdatauv(L_, sizeof(T), nuvalue_)); } // ################################################################################################# -inline void luaG_pushglobaltable(lua_State* const L_) +inline void luaW_pushglobaltable(lua_State* const L_) { #ifdef LUA_GLOBALSINDEX // All flavors of Lua 5.1 ::lua_pushvalue(L_, LUA_GLOBALSINDEX); @@ -431,15 +431,15 @@ inline void luaG_pushglobaltable(lua_State* const L_) // ################################################################################################# -inline void luaG_setfield(lua_State* const L_, StackIndex const idx_, char const* const k_) = delete; -inline void luaG_setfield(lua_State* const L_, StackIndex const idx_, std::string_view const& k_) +inline void luaW_setfield(lua_State* const L_, StackIndex const idx_, char const* const k_) = delete; +inline void luaW_setfield(lua_State* const L_, StackIndex const idx_, std::string_view const& k_) { lua_setfield(L_, idx_, k_.data()); } // ################################################################################################# -inline void luaG_setmetatable(lua_State* const L_, std::string_view const& tname_) +inline void luaW_setmetatable(lua_State* const L_, std::string_view const& tname_) { // fake externs to make clang happy... if constexpr (LUA_VERSION_NUM > 501) { @@ -456,7 +456,7 @@ inline void luaG_setmetatable(lua_State* const L_, std::string_view const& tname // a small helper to extract a full userdata pointer from the stack in a safe way template [[nodiscard]] -T* luaG_tofulluserdata(lua_State* const L_, StackIndex const index_) +T* luaW_tofulluserdata(lua_State* const L_, StackIndex const index_) { LUA_ASSERT(L_, lua_isnil(L_, index_) || lua_type(L_, index_) == LUA_TUSERDATA); return static_cast(lua_touserdata(L_, index_)); @@ -466,7 +466,7 @@ T* luaG_tofulluserdata(lua_State* const L_, StackIndex const index_) template [[nodiscard]] -auto luaG_tolightuserdata(lua_State* const L_, StackIndex const index_) +auto luaW_tolightuserdata(lua_State* const L_, StackIndex const index_) { LUA_ASSERT(L_, lua_isnil(L_, index_) || lua_islightuserdata(L_, index_)); if constexpr (std::is_pointer_v) { @@ -479,7 +479,7 @@ auto luaG_tolightuserdata(lua_State* const L_, StackIndex const index_) // ------------------------------------------------------------------------------------------------- [[nodiscard]] -inline std::string_view luaG_typename(lua_State* const L_, LuaType const t_) +inline std::string_view luaW_typename(lua_State* const L_, LuaType const t_) { return lua_typename(L_, static_cast(t_)); } @@ -487,7 +487,7 @@ inline std::string_view luaG_typename(lua_State* const L_, LuaType const t_) // ------------------------------------------------------------------------------------------------- [[nodiscard]] -inline std::string_view luaG_typename(lua_State* const L_, StackIndex const idx_) +inline std::string_view luaW_typename(lua_State* const L_, StackIndex const idx_) { - return luaG_typename(L_, luaG_type(L_, idx_)); + return luaW_typename(L_, luaW_type(L_, idx_)); } diff --git a/src/deep.cpp b/src/deep.cpp index 82f1214..acd93a6 100644 --- a/src/deep.cpp +++ b/src/deep.cpp @@ -75,7 +75,7 @@ namespace { lua_rawget(L_, -2); // L_: {} b } lua_remove(L_, -2); // L_: a|b - LuaType const _type{ luaG_type(L_, kIdxTop) }; + LuaType const _type{ luaW_type(L_, kIdxTop) }; if (_type != LuaType::NIL && _type != expectedType_) { raise_luaL_error(L_, "INTERNAL ERROR: Unexpected value."); } @@ -103,7 +103,7 @@ namespace { [[nodiscard]] int DeepFactory::DeepGC(lua_State* const L_) { - DeepPrelude* const* const _proxy{ luaG_tofulluserdata(L_, StackIndex{ 1 }) }; + DeepPrelude* const* const _proxy{ luaW_tofulluserdata(L_, StackIndex{ 1 }) }; DeepPrelude* const _p{ *_proxy }; // can work without a universe if creating a deep userdata from some external C module when Lanes isn't loaded @@ -150,7 +150,7 @@ DeepFactory* DeepFactory::LookupFactory(lua_State* const L_, StackIndex const in { // when looking inside a keeper, we are 100% sure the object is a deep userdata if (mode_ == LookupMode::FromKeeper) { - DeepPrelude* const _proxy{ *luaG_tofulluserdata(L_, index_) }; + DeepPrelude* const _proxy{ *luaW_tofulluserdata(L_, index_) }; // we can (and must) cast and fetch the internally stored factory return &_proxy->factory; } else { @@ -167,7 +167,7 @@ DeepFactory* DeepFactory::LookupFactory(lua_State* const L_, StackIndex const in // replace metatable with the factory pointer, if it is actually a deep userdata LookupDeep(L_, LuaType::LIGHTUSERDATA); // L_: deep ... factory|nil - DeepFactory* const _ret{ luaG_tolightuserdata(L_, kIdxTop) }; // nullptr if not a userdata + DeepFactory* const _ret{ luaW_tolightuserdata(L_, kIdxTop) }; // nullptr if not a userdata lua_pop(L_, 1); STACK_CHECK(L_, 0); return _ret; @@ -190,7 +190,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, // Check if a proxy already exists lua_pushlightuserdata(L_, prelude_); // L_: DPC deep - if (luaG_rawget(L_, StackIndex{ -2 }) != LuaType::NIL) { // L_: DPC proxy + if (luaW_rawget(L_, StackIndex{ -2 }) != LuaType::NIL) { // L_: DPC proxy lua_remove(L_, -2); // L_: proxy STACK_CHECK(L_, 1); return; @@ -202,7 +202,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, STACK_GROW(L_, 7); // a new full userdata, fitted with the specified number of uservalue slots (always 1 for Lua < 5.4) - DeepPrelude** const _proxy{ luaG_newuserdatauv(L_, nuv_) }; // L_: DPC proxy + DeepPrelude** const _proxy{ luaW_newuserdatauv(L_, nuv_) }; // L_: DPC proxy LUA_ASSERT(L_, _proxy); *_proxy = prelude_; prelude_->refcount.fetch_add(1, std::memory_order_relaxed); // one more proxy pointing to this deep data @@ -223,7 +223,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, raise_luaL_error(errL_, "Bad DeepFactory::createMetatable overload: unexpected pushed value"); } // if the metatable contains a __gc, we will call it from our own - std::ignore = luaG_rawgetfield(L_, kIdxTop, "__gc"); // L_: DPC proxy metatable __gc + std::ignore = luaW_rawgetfield(L_, kIdxTop, "__gc"); // L_: DPC proxy metatable __gc } else { // keepers need a minimal metatable that only contains our own __gc lua_createtable(L_, 0, 1); // L_: DPC proxy metatable @@ -251,8 +251,8 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, raise_luaL_error(errL_, "lanes receiving deep userdata should register the 'package' library"); } - luaG_pushstring(L_, _modname); // L_: DPC proxy metatable require() "module" - if (luaG_getfield(L_, kIdxRegistry, LUA_LOADED_TABLE) != LuaType::TABLE) { // L_: DPC proxy metatable require() "module" _R._LOADED + luaW_pushstring(L_, _modname); // L_: DPC proxy metatable require() "module" + if (luaW_getfield(L_, kIdxRegistry, LUA_LOADED_TABLE) != LuaType::TABLE) { // L_: DPC proxy metatable require() "module" _R._LOADED // no L.registry._LOADED; can this ever happen? lua_pop(L_, 6); // L_: raise_luaL_error(errL_, "unexpected error while requiring a module identified by DeepFactory::moduleName"); @@ -270,7 +270,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, LuaError const _require_result{ lua_pcall(L_, 1, 0, 0) }; // L_: DPC proxy metatable error? if (_require_result != LuaError::OK) { // failed, raise the error in the proper state - raise_luaL_error(errL_, luaG_tostring(L_, kIdxTop)); + raise_luaL_error(errL_, luaW_tostring(L_, kIdxTop)); } } } else { // already loaded, we are happy @@ -279,7 +279,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, } } STACK_CHECK(L_, 3); // L_: DPC proxy metatable - LUA_ASSERT(L_, luaG_type(L_, StackIndex{ -2 }) == LuaType::USERDATA); + LUA_ASSERT(L_, luaW_type(L_, StackIndex{ -2 }) == LuaType::USERDATA); LUA_ASSERT(L_, lua_istable(L_, -1)); lua_setmetatable(L_, -2); // L_: DPC proxy @@ -288,7 +288,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, lua_pushvalue(L_, -2); // L_: DPC proxy deep proxy lua_rawset(L_, -4); // L_: DPC proxy lua_remove(L_, -2); // L_: proxy - LUA_ASSERT(L_, luaG_type(L_, kIdxTop) == LuaType::USERDATA); + LUA_ASSERT(L_, luaW_type(L_, kIdxTop) == LuaType::USERDATA); STACK_CHECK(L_, 1); } @@ -305,7 +305,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, * Reference counting and true userdata proxying are taken care of for the actual data type. * * Types using the deep userdata system (and only those!) can be passed between - * separate Lua states via 'luaG_inter_move()'. + * separate Lua states via 'luaW_inter_move()'. * * Returns: 'proxy' userdata for accessing the deep data via 'DeepFactory::toDeep()' */ @@ -382,7 +382,7 @@ DeepPrelude* DeepFactory::toDeep(lua_State* const L_, StackIndex const index_) c } STACK_CHECK(L_, 0); - DeepPrelude** const _proxy{ luaG_tofulluserdata(L_, index_) }; + DeepPrelude** const _proxy{ luaW_tofulluserdata(L_, index_) }; return *_proxy; } diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index a93615b..7be1326 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp @@ -93,7 +93,7 @@ static int userdata_lookup_sentinel(lua_State* const L_) [[nodiscard]] std::string_view InterCopyContext::findLookupName() const { - LUA_ASSERT(L1, lua_isfunction(L1, L1_i) || lua_istable(L1, L1_i) || luaG_type(L1, L1_i) == LuaType::USERDATA); + LUA_ASSERT(L1, lua_isfunction(L1, L1_i) || lua_istable(L1, L1_i) || luaW_type(L1, L1_i) == LuaType::USERDATA); STACK_CHECK_START_REL(L1, 0); // L1: ... v ... STACK_GROW(L1, 3); // up to 3 slots are necessary on error if (mode == LookupMode::FromKeeper) { @@ -114,7 +114,7 @@ std::string_view InterCopyContext::findLookupName() const lua_pushvalue(L1, L1_i); // L1: ... v ... {} v lua_rawget(L1, -2); // L1: ... v ... {} "f.q.n" } - std::string_view _fqn{ luaG_tostring(L1, kIdxTop) }; + std::string_view _fqn{ luaW_tostring(L1, kIdxTop) }; DEBUGSPEW_CODE(DebugSpew(U) << "function [C] " << _fqn << std::endl); // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database lua_pop(L1, (mode == LookupMode::FromKeeper) ? 1 : 2); // L1: ... v ... @@ -122,12 +122,12 @@ std::string_view InterCopyContext::findLookupName() const if (_fqn.empty() && !lua_istable(L1, L1_i)) { // raise an error if we try to send an unknown function/userdata (but not for tables) // try to discover the name of the function/userdata we want to send kLaneNameRegKey.pushValue(L1); // L1: ... v ... lane_name - std::string_view const _from{ luaG_tostring(L1, kIdxTop) }; + std::string_view const _from{ luaW_tostring(L1, kIdxTop) }; lua_pushcfunction(L1, LG_nameof); // L1: ... v ... lane_name LG_nameof lua_pushvalue(L1, L1_i); // L1: ... v ... lane_name LG_nameof t lua_call(L1, 1, 2); // L1: ... v ... lane_name "type" "name"|nil StackIndex const _indexTypeWhat{ -2 }; - std::string_view const _typewhat{ (luaG_type(L1, _indexTypeWhat) == LuaType::STRING) ? luaG_tostring(L1, _indexTypeWhat) : luaG_typename(L1, _indexTypeWhat) }; + std::string_view const _typewhat{ (luaW_type(L1, _indexTypeWhat) == LuaType::STRING) ? luaW_tostring(L1, _indexTypeWhat) : luaW_typename(L1, _indexTypeWhat) }; // second return value can be nil if the table was not found // probable reason: the function was removed from the source Lua state before Lanes was required. std::string_view _what, _gotchaA, _gotchaB; @@ -139,7 +139,7 @@ std::string_view InterCopyContext::findLookupName() const _gotchaA = ""; _gotchaB = ""; StackIndex const _indexWhat{ kIdxTop }; - _what = (luaG_type(L1, _indexWhat) == LuaType::STRING) ? luaG_tostring(L1, _indexWhat) : luaG_typename(L1, _indexWhat); + _what = (luaW_type(L1, _indexWhat) == LuaType::STRING) ? luaW_tostring(L1, _indexWhat) : luaW_typename(L1, _indexWhat); } raise_luaL_error(L1, "%s%s '%s' not found in %s origin transfer database.%s", _typewhat.data(), _gotchaA.data(), _what.data(), _from.empty() ? "main" : _from.data(), _gotchaB.data()); } @@ -158,7 +158,7 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull }; [[nodiscard]] static lua_Integer get_mt_id(Universe* const U_, lua_State* const L_, StackIndex const idx_) { - StackIndex const _absidx{ luaG_absindex(L_, idx_) }; + StackIndex const _absidx{ luaW_absindex(L_, idx_) }; STACK_GROW(L_, 3); @@ -199,7 +199,7 @@ void InterCopyContext::copyFunction() const STACK_GROW(L1, 2); STACK_CHECK_START_REL(L1, 0); - // 'luaG_dump()' needs the function at top of stack + // 'luaW_dump()' needs the function at top of stack // if already on top of the stack, no need to push again bool const _needToPush{ L1_i != lua_gettop(L1) }; if (_needToPush) { @@ -212,7 +212,7 @@ void InterCopyContext::copyFunction() const // not sure this could ever fail but for memory shortage reasons // last argument is Lua 5.4-specific (no stripping) luaL_Buffer B{}; - if (luaG_dump(L1, buf_writer, &B, U->stripFunctions) != 0) { + if (luaW_dump(L1, buf_writer, &B, U->stripFunctions) != 0) { raise_luaL_error(getErrL(), "internal error: function dump failed."); } @@ -240,7 +240,7 @@ void InterCopyContext::copyFunction() const } { - std::string_view const _bytecode{ luaG_tostring(L1, kIdxTop) }; // L1: ... b + std::string_view const _bytecode{ luaW_tostring(L1, kIdxTop) }; // L1: ... b LUA_ASSERT(L1, !_bytecode.empty()); STACK_GROW(L2, 2); // Note: Line numbers seem to be taken precisely from the @@ -278,12 +278,12 @@ void InterCopyContext::copyFunction() const { InterCopyContext _c{ U, L2, L1, L2_cache_i, {}, VT::NORMAL, mode, {} }; // if we encounter an upvalue equal to the global table in the source, bind it to the destination's global table - luaG_pushglobaltable(L1); // L1: ... _G + luaW_pushglobaltable(L1); // L1: ... _G for (char const* _upname{}; (_upname = lua_getupvalue(L1, L1_i, 1 + _n)); ++_n) { // L1: ... _G up[n] DEBUGSPEW_CODE(DebugSpew(U) << "UPNAME[" << _n << "]: " << _c.name << " -> "); if (lua_rawequal(L1, -1, -2)) { // is the upvalue equal to the global table? DEBUGSPEW_CODE(DebugSpew(nullptr) << "pushing destination global scope" << std::endl); - luaG_pushglobaltable(L2); // L2: ... {cache} ... function + luaW_pushglobaltable(L2); // L2: ... {cache} ... function } else { DEBUGSPEW_CODE(DebugSpew(nullptr) << "copying value" << std::endl); _c.name = _upname; @@ -327,7 +327,7 @@ void InterCopyContext::lookupNativeFunction() const case LookupMode::ToKeeper: // push a sentinel closure that holds the lookup name as upvalue - luaG_pushstring(L2, _fqn); // L1: ... f ... L2: "f.q.n" + luaW_pushstring(L2, _fqn); // L1: ... f ... L2: "f.q.n" lua_pushcclosure(L2, func_lookup_sentinel, 1); // L1: ... f ... L2: f break; @@ -336,16 +336,16 @@ void InterCopyContext::lookupNativeFunction() const kLookupRegKey.pushValue(L2); // L1: ... f ... L2: {} STACK_CHECK(L2, 1); LUA_ASSERT(L1, lua_istable(L2, -1)); - luaG_pushstring(L2, _fqn); // L1: ... f ... L2: {} "f.q.n" - LuaType const _objType{ luaG_rawget(L2, StackIndex{ -2 }) }; // L1: ... f ... L2: {} f + luaW_pushstring(L2, _fqn); // L1: ... f ... L2: {} "f.q.n" + LuaType const _objType{ luaW_rawget(L2, StackIndex{ -2 }) }; // L1: ... f ... L2: {} f // nil means we don't know how to transfer stuff: user should do something // anything other than function or table should not happen! if (_objType != LuaType::FUNCTION && _objType != LuaType::TABLE && _objType != LuaType::USERDATA) { kLaneNameRegKey.pushValue(L1); // L1: ... f ... lane_name - std::string_view const _from{ luaG_tostring(L1, kIdxTop) }; + std::string_view const _from{ luaW_tostring(L1, kIdxTop) }; lua_pop(L1, 1); // L1: ... f ... kLaneNameRegKey.pushValue(L2); // L1: ... f ... L2: {} f lane_name - std::string_view const _to{ luaG_tostring(L2, kIdxTop) }; + std::string_view const _to{ luaW_tostring(L2, kIdxTop) }; lua_pop(L2, 1); // L2: {} f raise_luaL_error( getErrL(), @@ -368,7 +368,7 @@ void InterCopyContext::lookupNativeFunction() const // Always pushes a function to 'L2'. void InterCopyContext::copyCachedFunction() const { - FuncSubType const _funcSubType{ luaG_getfuncsubtype(L1, L1_i) }; + FuncSubType const _funcSubType{ luaW_getfuncsubtype(L1, L1_i) }; if (_funcSubType == FuncSubType::Bytecode) { void* const _aspointer{ const_cast(lua_topointer(L1, L1_i)) }; // TODO: Merge this and same code for tables @@ -386,10 +386,10 @@ void InterCopyContext::copyCachedFunction() const // push a light userdata uniquely representing the function lua_pushlightuserdata(L2, _aspointer); // L2: ... {cache} ... p - //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaG_tostring(L2, -1) << " >>" << std::endl); + //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaW_tostring(L2, -1) << " >>" << std::endl); lua_pushvalue(L2, -1); // L2: ... {cache} ... p p - if (luaG_rawget(L2, L2_cache_i) == LuaType::NIL) { // function is unknown // L2: ... {cache} ... p function|nil|true + if (luaW_rawget(L2, L2_cache_i) == LuaType::NIL) { // function is unknown // L2: ... {cache} ... p function|nil|true lua_pop(L2, 1); // L2: ... {cache} ... p // Set to 'true' for the duration of creation; need to find self-references @@ -405,7 +405,7 @@ void InterCopyContext::copyCachedFunction() const } else { // function is native/LuaJIT: no need to cache lookupNativeFunction(); // L2: ... {cache} ... function // if the function was in fact a lookup sentinel, we can either get a function, table or full userdata here - LUA_ASSERT(L1, lua_isfunction(L2, kIdxTop) || lua_istable(L2, kIdxTop) || luaG_type(L2, kIdxTop) == LuaType::USERDATA); + LUA_ASSERT(L1, lua_isfunction(L2, kIdxTop) || lua_istable(L2, kIdxTop) || luaW_type(L2, kIdxTop) == LuaType::USERDATA); } } @@ -430,7 +430,7 @@ bool InterCopyContext::lookupTable() const case LookupMode::ToKeeper: // push a sentinel closure that holds the lookup name as upvalue - luaG_pushstring(L2, _fqn); // L1: ... t ... L2: "f.q.n" + luaW_pushstring(L2, _fqn); // L1: ... t ... L2: "f.q.n" lua_pushcclosure(L2, table_lookup_sentinel, 1); // L1: ... t ... L2: f break; @@ -439,26 +439,26 @@ bool InterCopyContext::lookupTable() const kLookupRegKey.pushValue(L2); // L1: ... t ... L2: {} STACK_CHECK(L2, 1); LUA_ASSERT(L1, lua_istable(L2, -1)); - luaG_pushstring(L2, _fqn); // L2: {} "f.q.n" + luaW_pushstring(L2, _fqn); // L2: {} "f.q.n" // we accept destination lookup failures in the case of transfering the Lanes body function (this will result in the source table being cloned instead) // but not when we extract something out of a keeper, as there is nothing to clone! - if (luaG_rawget(L2, StackIndex{ -2 }) == LuaType::NIL && mode == LookupMode::LaneBody) { // L2: {} t + if (luaW_rawget(L2, StackIndex{ -2 }) == LuaType::NIL && mode == LookupMode::LaneBody) { // L2: {} t lua_pop(L2, 2); // L1: ... t ... L2: STACK_CHECK(L2, 0); return false; } else if (!lua_istable(L2, -1)) { // this can happen if someone decides to replace same already registered item (for a example a standard lib function) with a table kLaneNameRegKey.pushValue(L1); // L1: ... t ... lane_name - std::string_view const _from{ luaG_tostring(L1, kIdxTop) }; + std::string_view const _from{ luaW_tostring(L1, kIdxTop) }; lua_pop(L1, 1); // L1: ... t ... kLaneNameRegKey.pushValue(L2); // L1: ... t ... L2: {} t lane_name - std::string_view const _to{ luaG_tostring(L2, kIdxTop) }; + std::string_view const _to{ luaW_tostring(L2, kIdxTop) }; lua_pop(L2, 1); // L1: ... t ... L2: {} t raise_luaL_error( getErrL(), "%s: source table '%s' found as %s in %s destination transfer database.", _from.empty() ? "main" : _from.data(), _fqn.data(), - luaG_typename(L2, kIdxTop).data(), + luaW_typename(L2, kIdxTop).data(), _to.empty() ? "main" : _to.data()); } lua_remove(L2, -2); // L1: ... t ... L2: t @@ -487,8 +487,8 @@ void InterCopyContext::interCopyKeyValuePair() const char* _valPath{ nullptr }; if (U->verboseErrors) { // for debug purposes, let's try to build a useful name - if (luaG_type(L1, _key_i) == LuaType::STRING) { - std::string_view const _key{ luaG_tostring(L1, _key_i) }; + if (luaW_type(L1, _key_i) == LuaType::STRING) { + std::string_view const _key{ luaW_tostring(L1, _key_i) }; size_t const _bufLen{ name.size() + _key.size() + 2 }; // +2 for separator dot and terminating 0 _valPath = static_cast(alloca(_bufLen)); sprintf(_valPath, "%s." STRINGVIEW_FMT, name.data(), (int) _key.size(), _key.data()); @@ -500,15 +500,15 @@ void InterCopyContext::interCopyKeyValuePair() const sprintf(_valPath, "%s[" LUA_INTEGER_FMT "]", name.data(), key); } #endif // defined LUA_LNUM || LUA_VERSION_NUM >= 503 - else if (luaG_type(L1, _key_i) == LuaType::NUMBER) { + else if (luaW_type(L1, _key_i) == LuaType::NUMBER) { lua_Number const key{ lua_tonumber(L1, _key_i) }; _valPath = (char*) alloca(name.size() + 32 + 3); // +3 for [] and terminating 0 sprintf(_valPath, "%s[" LUA_NUMBER_FMT "]", name.data(), key); - } else if (luaG_type(L1, _key_i) == LuaType::LIGHTUSERDATA) { + } else if (luaW_type(L1, _key_i) == LuaType::LIGHTUSERDATA) { void* const _key{ lua_touserdata(L1, _key_i) }; _valPath = (char*) alloca(name.size() + 16 + 5); // +5 for [U:] and terminating 0 sprintf(_valPath, "%s[U:%p]", name.data(), _key); - } else if (luaG_type(L1, _key_i) == LuaType::BOOLEAN) { + } else if (luaW_type(L1, _key_i) == LuaType::BOOLEAN) { int const _key{ lua_toboolean(L1, _key_i) }; _valPath = (char*) alloca(name.size() + 8); // +8 for [], 'false' and terminating 0 sprintf(_valPath, "%s[%s]", name.data(), _key ? "true" : "false"); @@ -532,7 +532,7 @@ LuaType InterCopyContext::processConversion() const { static constexpr int kPODmask = (1 << LUA_TNIL) | (1 << LUA_TBOOLEAN) | (1 << LUA_TLIGHTUSERDATA) | (1 << LUA_TNUMBER) | (1 << LUA_TSTRING); - LuaType _val_type{ luaG_type(L1, L1_i) }; + LuaType _val_type{ luaW_type(L1, L1_i) }; STACK_CHECK_START_REL(L1, 0); @@ -548,7 +548,7 @@ LuaType InterCopyContext::processConversion() const } // we have a metatable // L1: ... mt static constexpr std::string_view kConvertField{ "__lanesconvert" }; - LuaType const _converterType{ luaG_getfield(L1, kIdxTop, kConvertField) }; // L1: ... mt kConvertField + LuaType const _converterType{ luaW_getfield(L1, kIdxTop, kConvertField) }; // L1: ... mt kConvertField switch (_converterType) { case LuaType::NIL: // no __lanesconvert, nothing to do @@ -557,18 +557,18 @@ LuaType InterCopyContext::processConversion() const case LuaType::LIGHTUSERDATA: if (kNilSentinel.equals(L1, kIdxTop)) { - DEBUGSPEW_CODE(DebugSpew(U) << "converted " << luaG_typename(L1, _val_type) << " to nil" << std::endl); + DEBUGSPEW_CODE(DebugSpew(U) << "converted " << luaW_typename(L1, _val_type) << " to nil" << std::endl); lua_replace(L1, L1_i); // L1: ... mt lua_pop(L1, 1); // L1: ... _val_type = _converterType; } else { - raise_luaL_error(getErrL(), "Invalid %s type %s", kConvertField.data(), luaG_typename(L1, _converterType).data()); + raise_luaL_error(getErrL(), "Invalid %s type %s", kConvertField.data(), luaW_typename(L1, _converterType).data()); } break; case LuaType::STRING: // kConvertField == "decay" -> replace source value with it's pointer - if (std::string_view const _mode{ luaG_tostring(L1, kIdxTop) }; _mode == "decay") { + if (std::string_view const _mode{ luaW_tostring(L1, kIdxTop) }; _mode == "decay") { lua_pop(L1, 1); // L1: ... mt lua_pushlightuserdata(L1, const_cast(lua_topointer(L1, L1_i))); // L1: ... mt decayed lua_replace(L1, L1_i); // L1: ... mt @@ -581,18 +581,18 @@ LuaType InterCopyContext::processConversion() const case LuaType::FUNCTION: lua_pushvalue(L1, L1_i); // L1: ... mt kConvertField val - luaG_pushstring(L1, mode == LookupMode::ToKeeper ? "keeper" : "regular"); // L1: ... mt kConvertField val string + luaW_pushstring(L1, mode == LookupMode::ToKeeper ? "keeper" : "regular"); // L1: ... mt kConvertField val string lua_call(L1, 2, 1); // val:kConvertField(str) -> result // L1: ... mt kConvertField converted lua_replace(L1, L1_i); // L1: ... mt lua_pop(L1, 1); // L1: ... mt - _val_type = luaG_type(L1, L1_i); + _val_type = luaW_type(L1, L1_i); break; default: - raise_luaL_error(getErrL(), "Invalid %s type %s", kConvertField.data(), luaG_typename(L1, _converterType).data()); + raise_luaL_error(getErrL(), "Invalid %s type %s", kConvertField.data(), luaW_typename(L1, _converterType).data()); } STACK_CHECK(L1, 0); - LUA_ASSERT(getErrL(), luaG_type(L1, L1_i) == _val_type); + LUA_ASSERT(getErrL(), luaW_type(L1, L1_i) == _val_type); return _val_type; } @@ -615,7 +615,7 @@ bool InterCopyContext::pushCachedMetatable() const // do we already know this metatable? std::ignore = kMtIdRegKey.getSubTable(L2, NArr{ 0 }, NRec{ 0 }); // L2: _R[kMtIdRegKey] lua_pushinteger(L2, _mt_id); // L2: _R[kMtIdRegKey] id - if (luaG_rawget(L2, StackIndex{ -2 }) == LuaType::NIL) { // L2 did not know the metatable // L2: _R[kMtIdRegKey] mt|nil + if (luaW_rawget(L2, StackIndex{ -2 }) == LuaType::NIL) { // L2 did not know the metatable // L2: _R[kMtIdRegKey] mt|nil lua_pop(L2, 1); // L2: _R[kMtIdRegKey] InterCopyContext const _c{ U, L2, L1, L2_cache_i, SourceIndex{ lua_gettop(L1) }, VT::METATABLE, mode, name }; if (_c.interCopyOne() != InterCopyResult::Success) { // L2: _R[kMtIdRegKey] mt? @@ -662,9 +662,9 @@ bool InterCopyContext::pushCachedTable() const // push a light userdata uniquely representing the table lua_pushlightuserdata(L2, const_cast(_p)); // L1: ... t ... L2: ... p - //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaG_tostring(L2, -1) << " >>" << std::endl); + //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaW_tostring(L2, -1) << " >>" << std::endl); - bool const _not_found_in_cache{ luaG_rawget(L2, L2_cache_i) == LuaType::NIL }; // L1: ... t ... L2: ... {cached|nil} + bool const _not_found_in_cache{ luaW_rawget(L2, L2_cache_i) == LuaType::NIL }; // L1: ... t ... L2: ... {cached|nil} if (_not_found_in_cache) { // create a new entry in the cache lua_pop(L2, 1); // L1: ... t ... L2: ... @@ -696,7 +696,7 @@ bool InterCopyContext::lookupUserdata() const case LookupMode::ToKeeper: // push a sentinel closure that holds the lookup name as upvalue - luaG_pushstring(L2, _fqn); // L1: ... f ... L2: "f.q.n" + luaW_pushstring(L2, _fqn); // L1: ... f ... L2: "f.q.n" lua_pushcclosure(L2, userdata_lookup_sentinel, 1); // L1: ... f ... L2: f break; @@ -705,16 +705,16 @@ bool InterCopyContext::lookupUserdata() const kLookupRegKey.pushValue(L2); // L1: ... f ... L2: {} STACK_CHECK(L2, 1); LUA_ASSERT(L1, lua_istable(L2, -1)); - luaG_pushstring(L2, _fqn); // L1: ... f ... L2: {} "f.q.n" - LuaType const _type{ luaG_rawget(L2, StackIndex{ -2 }) }; // L1: ... f ... L2: {} f + luaW_pushstring(L2, _fqn); // L1: ... f ... L2: {} "f.q.n" + LuaType const _type{ luaW_rawget(L2, StackIndex{ -2 }) }; // L1: ... f ... L2: {} f // nil means we don't know how to transfer stuff: user should do something // anything other than function or table should not happen! if (_type != LuaType::FUNCTION && _type != LuaType::TABLE) { kLaneNameRegKey.pushValue(L1); // L1: ... f ... lane_name - std::string_view const _from{ luaG_tostring(L1, kIdxTop) }; + std::string_view const _from{ luaW_tostring(L1, kIdxTop) }; lua_pop(L1, 1); // L1: ... f ... kLaneNameRegKey.pushValue(L2); // L1: ... f ... L2: {} f lane_name - std::string_view const _to{ luaG_tostring(L2, kIdxTop) }; + std::string_view const _to{ luaW_tostring(L2, kIdxTop) }; lua_pop(L2, 1); // L2: {} f raise_luaL_error( getErrL(), @@ -736,7 +736,7 @@ bool InterCopyContext::lookupUserdata() const [[nodiscard]] bool InterCopyContext::tryCopyClonable() const { - SourceIndex const _L1_i{ luaG_absindex(L1, L1_i).value() }; + SourceIndex const _L1_i{ luaW_absindex(L1, L1_i).value() }; void* const _source{ lua_touserdata(L1, _L1_i) }; STACK_CHECK_START_REL(L1, 0); @@ -744,7 +744,7 @@ bool InterCopyContext::tryCopyClonable() const // Check if the source was already cloned during this copy lua_pushlightuserdata(L2, _source); // L2: ... source - if (luaG_rawget(L2, L2_cache_i) != LuaType::NIL) { // L2: ... clone? + if (luaW_rawget(L2, L2_cache_i) != LuaType::NIL) { // L2: ... clone? STACK_CHECK(L2, 1); return true; } else { @@ -759,7 +759,7 @@ bool InterCopyContext::tryCopyClonable() const } // no __lanesclone? -> not clonable - if (luaG_getfield(L1, kIdxTop, "__lanesclone") == LuaType::NIL) { // L1: ... mt nil + if (luaW_getfield(L1, kIdxTop, "__lanesclone") == LuaType::NIL) { // L1: ... mt nil lua_pop(L1, 2); // L1: ... STACK_CHECK(L1, 0); return false; @@ -769,10 +769,10 @@ bool InterCopyContext::tryCopyClonable() const // we need to copy over the uservalues of the userdata as well { - StackIndex const _mt{ luaG_absindex(L1, StackIndex{ -2 }) }; // L1: ... mt __lanesclone + StackIndex const _mt{ luaW_absindex(L1, StackIndex{ -2 }) }; // L1: ... mt __lanesclone auto const userdata_size{ static_cast(lua_rawlen(L1, _L1_i)) }; // make 32-bits builds happy // extract all the uservalues, but don't transfer them yet - UserValueCount const _nuv{ luaG_getalluservalues(L1, _L1_i) }; // L1: ... mt __lanesclone [uv]* + UserValueCount const _nuv{ luaW_getalluservalues(L1, _L1_i) }; // L1: ... mt __lanesclone [uv]* // create the clone userdata with the required number of uservalue slots void* const _clone{ lua_newuserdatauv(L2, userdata_size, _nuv) }; // L2: ... u // copy the metatable in the target state, and give it to the clone we put there @@ -804,7 +804,7 @@ bool InterCopyContext::tryCopyClonable() const // assign uservalues UserValueIndex _uvi{ _nuv.value() }; while (_uvi > 0) { - _c.L1_i = SourceIndex{ luaG_absindex(L1, kIdxTop).value() }; + _c.L1_i = SourceIndex{ luaW_absindex(L1, kIdxTop).value() }; if (_c.interCopyOne() != InterCopyResult::Success) { // L2: ... u uv raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); } @@ -850,10 +850,10 @@ bool InterCopyContext::tryCopyDeep() const STACK_CHECK_START_REL(L2, 0); // extract all uservalues of the source. unfortunately, the only way to know their count is to iterate until we fail - UserValueCount const _nuv{ luaG_getalluservalues(L1, L1_i) }; // L1: ... deep ... [uv]* + UserValueCount const _nuv{ luaW_getalluservalues(L1, L1_i) }; // L1: ... deep ... [uv]* STACK_CHECK(L1, _nuv); - DeepPrelude* const _deep{ *luaG_tofulluserdata(L1, L1_i) }; + DeepPrelude* const _deep{ *luaW_tofulluserdata(L1, L1_i) }; DeepFactory::PushDeepProxy(L2, _deep, _nuv, mode, getErrL()); // L1: ... deep ... [uv]* L2: deep // transfer all uservalues of the source in the destination @@ -863,7 +863,7 @@ bool InterCopyContext::tryCopyDeep() const STACK_GROW(L2, _nuv); UserValueIndex _uvi{ _nuv.value() }; while (_uvi) { - _c.L1_i = SourceIndex{ luaG_absindex(L1, kIdxTop).value() }; + _c.L1_i = SourceIndex{ luaW_absindex(L1, kIdxTop).value() }; if (_c.interCopyOne() != InterCopyResult::Success) { // L1: ... deep ... [uv]* L2: deep uv raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); } @@ -911,7 +911,7 @@ bool InterCopyContext::interCopyFunction() const lua_getupvalue(L1, L1_i, 2); // L1: ... u void* _source{ lua_touserdata(L1, -1) }; lua_pushlightuserdata(L2, _source); // L2: ... source - if (luaG_rawget(L2, L2_cache_i) != LuaType::NIL) { // L2: ... u? + if (luaW_rawget(L2, L2_cache_i) != LuaType::NIL) { // L2: ... u? lua_pop(L1, 1); // L1: ... STACK_CHECK(L1, 0); STACK_CHECK(L2, 1); @@ -933,7 +933,7 @@ bool InterCopyContext::interCopyFunction() const auto const _userdata_size{ static_cast(lua_rawlen(L1, kIdxTop)) }; // make 32-bits builds happy { // extract uservalues (don't transfer them yet) - UserValueCount const _nuv{ luaG_getalluservalues(L1, source_i) }; // L1: ... u [uv]* + UserValueCount const _nuv{ luaW_getalluservalues(L1, source_i) }; // L1: ... u [uv]* STACK_CHECK(L1, _nuv + 1); // create the clone userdata with the required number of uservalue slots _clone = lua_newuserdatauv(L2, _userdata_size, _nuv); // L2: ... mt u @@ -948,7 +948,7 @@ bool InterCopyContext::interCopyFunction() const InterCopyContext _c{ *this }; UserValueIndex _uvi{ _nuv.value() }; while (_uvi > 0) { - _c.L1_i = SourceIndex{ luaG_absindex(L1, kIdxTop).value() }; + _c.L1_i = SourceIndex{ luaW_absindex(L1, kIdxTop).value() }; if (_c.interCopyOne() != InterCopyResult::Success) { // L2: ... mt u uv raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); } @@ -965,9 +965,9 @@ bool InterCopyContext::interCopyFunction() const // perform the custom cloning part lua_insert(L2, -2); // L2: ... u mt // __lanesclone should always exist because we wouldn't be restoring data from a userdata_clone_sentinel closure to begin with - LuaType const _funcType{ luaG_getfield(L2, kIdxTop, "__lanesclone") }; // L2: ... u mt __lanesclone + LuaType const _funcType{ luaW_getfield(L2, kIdxTop, "__lanesclone") }; // L2: ... u mt __lanesclone if (_funcType != LuaType::FUNCTION) { - raise_luaL_error(getErrL(), "INTERNAL ERROR: __lanesclone is a %s, not a function", luaG_typename(L2, _funcType).data()); + raise_luaL_error(getErrL(), "INTERNAL ERROR: __lanesclone is a %s, not a function", luaW_typename(L2, _funcType).data()); } lua_remove(L2, -2); // L2: ... u __lanesclone lua_pushlightuserdata(L2, _clone); // L2: ... u __lanesclone clone @@ -1060,9 +1060,9 @@ bool InterCopyContext::interCopyNumber() const [[nodiscard]] bool InterCopyContext::interCopyString() const { - std::string_view const _s{ luaG_tostring(L1, L1_i) }; + std::string_view const _s{ luaW_tostring(L1, L1_i) }; DEBUGSPEW_CODE(DebugSpew(nullptr) << "'" << _s << "'" << std::endl); - luaG_pushstring(L2, _s); + luaW_pushstring(L2, _s); return true; } @@ -1154,7 +1154,7 @@ bool InterCopyContext::interCopyUserdata() const // Last, let's try to see if this userdata is special (aka is it some userdata that we registered in our lookup databases during module registration?) if (lookupUserdata()) { - LUA_ASSERT(L1, luaG_type(L2, kIdxTop) == LuaType::USERDATA || (lua_tocfunction(L2, kIdxTop) == userdata_lookup_sentinel)); // from lookup data. can also be userdata_lookup_sentinel if this is a userdata we know + LUA_ASSERT(L1, luaW_type(L2, kIdxTop) == LuaType::USERDATA || (lua_tocfunction(L2, kIdxTop) == userdata_lookup_sentinel)); // from lookup data. can also be userdata_lookup_sentinel if this is a userdata we know return true; } @@ -1291,8 +1291,8 @@ InterCopyResult InterCopyContext::interCopyPackage() const } const _onExit{ L2 }; STACK_CHECK_START_REL(L1, 0); - if (luaG_type(L1, L1_i) != LuaType::TABLE) { - std::string_view const _msg{ luaG_pushstring(L1, "expected package as table, got a %s", luaL_typename(L1, L1_i)) }; + if (luaW_type(L1, L1_i) != LuaType::TABLE) { + std::string_view const _msg{ luaW_pushstring(L1, "expected package as table, got a %s", luaL_typename(L1, L1_i)) }; STACK_CHECK(L1, 1); // raise the error when copying from lane to lane, else just leave it on the stack to be raised later if (mode == LookupMode::LaneBody) { @@ -1300,7 +1300,7 @@ InterCopyResult InterCopyContext::interCopyPackage() const } return InterCopyResult::Error; } - if (luaG_getmodule(L2, LUA_LOADLIBNAME) == LuaType::NIL) { // package library not loaded: do nothing + if (luaW_getmodule(L2, LUA_LOADLIBNAME) == LuaType::NIL) { // package library not loaded: do nothing DEBUGSPEW_CODE(DebugSpew(U) << "'package' not loaded, nothing to do" << std::endl); STACK_CHECK(L1, 0); return InterCopyResult::Success; @@ -1317,7 +1317,7 @@ InterCopyResult InterCopyContext::interCopyPackage() const continue; } DEBUGSPEW_CODE(DebugSpew(U) << "package." << _entry << std::endl); - if (luaG_getfield(L1, L1_i, _entry) == LuaType::NIL) { + if (luaW_getfield(L1, L1_i, _entry) == LuaType::NIL) { lua_pop(L1, 1); } else { { @@ -1328,9 +1328,9 @@ InterCopyResult InterCopyContext::interCopyPackage() const STACK_CHECK(L1, 0); } if (_result == InterCopyResult::Success) { - luaG_setfield(L2, StackIndex{ -2 }, _entry); // set package[entry] + luaW_setfield(L2, StackIndex{ -2 }, _entry); // set package[entry] } else { - std::string_view const _msg{ luaG_pushstring(L1, "failed to copy package.%s", _entry.data()) }; + std::string_view const _msg{ luaW_pushstring(L1, "failed to copy package.%s", _entry.data()) }; // raise the error when copying from lane to lane, else just leave it on the stack to be raised later if (mode == LookupMode::LaneBody) { raise_luaL_error(getErrL(), _msg); diff --git a/src/keeper.cpp b/src/keeper.cpp index 2e13de3..4af0d86 100644 --- a/src/keeper.cpp +++ b/src/keeper.cpp @@ -77,7 +77,7 @@ class KeyUD final // a fifo full userdata has one uservalue, the table that holds the actual fifo contents [[nodiscard]] - static void* operator new([[maybe_unused]] size_t size_, KeeperState L_) noexcept { return luaG_newuserdatauv(L_, UserValueCount{ 1 }); } + static void* operator new([[maybe_unused]] size_t size_, KeeperState L_) noexcept { return luaW_newuserdatauv(L_, UserValueCount{ 1 }); } // always embedded somewhere else or "in-place constructed" as a full userdata // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception static void operator delete([[maybe_unused]] void* p_, [[maybe_unused]] KeeperState L_) { LUA_ASSERT(L_, !"should never be called"); } @@ -146,7 +146,7 @@ KeyUD* KeyUD::Create(KeeperState const K_) [[nodiscard]] KeyUD* KeyUD::GetPtr(KeeperState const K_, StackIndex const idx_) { - return luaG_tofulluserdata(K_, idx_); + return luaW_tofulluserdata(K_, idx_); } // ################################################################################################# @@ -236,7 +236,7 @@ int KeyUD::pop(KeeperState const K_, int const minCount_, int const maxCount_) // replaces it by its uservalue on the stack (the table holding the fifo values) void KeyUD::prepareAccess(KeeperState const K_, StackIndex const idx_) const { - StackIndex const _idx{ luaG_absindex(K_, idx_) }; + StackIndex const _idx{ luaW_absindex(K_, idx_) }; LUA_ASSERT(K_, KeyUD::GetPtr(K_, idx_) == this); // we can replace the key userdata in the stack without fear of it being GCed, there are other references around lua_getiuservalue(K_, _idx, kContentsTableIndex); @@ -250,7 +250,7 @@ void KeyUD::prepareAccess(KeeperState const K_, StackIndex const idx_) const [[nodiscard]] bool KeyUD::push(KeeperState const K_, int const count_, bool const enforceLimit_) { - StackIndex const _fifoIdx{ luaG_absindex(K_, StackIndex{ -1 - count_ }) }; + StackIndex const _fifoIdx{ luaW_absindex(K_, StackIndex{ -1 - count_ }) }; LUA_ASSERT(K_, KeyUD::GetPtr(K_, _fifoIdx) == this); // K_: this val... if (enforceLimit_ && (limit >= 0) && (count + count_ > limit)) { // not enough room return false; @@ -274,16 +274,16 @@ bool KeyUD::push(KeeperState const K_, int const count_, bool const enforceLimit void KeyUD::pushFillStatus(KeeperState const K_) const { if (limit < 0) { - luaG_pushstring(K_, kUnder); + luaW_pushstring(K_, kUnder); return; } int const _delta{ limit - count }; if (_delta < 0) { - luaG_pushstring(K_, kOver); + luaW_pushstring(K_, kOver); } else if (_delta > 0) { - luaG_pushstring(K_, kUnder); + luaW_pushstring(K_, kUnder); } else { - luaG_pushstring(K_, kExact); + luaW_pushstring(K_, kExact); } } @@ -294,7 +294,7 @@ void KeyUD::PushFillStatus(KeeperState const K_, KeyUD const* const key_) if (key_) { key_->pushFillStatus(K_); // _K: ... } else { - luaG_pushstring(K_, KeyUD::kUnder); // _K: ... "under" + luaW_pushstring(K_, KeyUD::kUnder); // _K: ... "under" } } @@ -330,10 +330,10 @@ static void PushKeysDB(KeeperState const K_, StackIndex const idx_) { STACK_GROW(K_, 5); STACK_CHECK_START_REL(K_, 0); - StackIndex const _absidx{ luaG_absindex(K_, idx_) }; + StackIndex const _absidx{ luaW_absindex(K_, idx_) }; kLindasRegKey.pushValue(K_); // K_: ... LindasDB lua_pushvalue(K_, _absidx); // K_: ... LindasDB linda - if (luaG_rawget(K_, StackIndex{ -2 }) == LuaType::NIL) { // K_: ... LindasDB KeysDB + if (luaW_rawget(K_, StackIndex{ -2 }) == LuaType::NIL) { // K_: ... LindasDB KeysDB lua_pop(K_, 1); // K_: ... LindasDB // add a new KeysDB table for this linda lua_newtable(K_); // K_: ... LindasDB KeysDB @@ -390,7 +390,7 @@ int keepercall_count(lua_State* const L_) case 2: // _K: linda key PushKeysDB(_K, StackIndex{ 1 }); // _K: linda key KeysDB lua_replace(_K, 1); // _K: KeysDB key - if (luaG_rawget(_K, StackIndex{ -2 }) == LuaType::NIL) { // the key is unknown // _K: KeysDB KeyUD|nil + if (luaW_rawget(_K, StackIndex{ -2 }) == LuaType::NIL) { // the key is unknown // _K: KeysDB KeyUD|nil lua_remove(_K, -2); // _K: nil } else { // the key is known // _K: KeysDB KeyUD KeyUD* const _key{ KeyUD::GetPtr(_K, kIdxTop) }; @@ -503,7 +503,7 @@ int keepercall_limit(lua_State* const L_) if (_key && _key->limit >= 0) { lua_pushinteger(_K, _key->limit); // _K: limit } else { // if the key doesn't exist, it is unlimited by default - luaG_pushstring(_K, "unlimited"); // _K: "unlimited" + luaW_pushstring(_K, "unlimited"); // _K: "unlimited" } // return a single value: the limit of the key } else { @@ -617,7 +617,7 @@ int keepercall_restrict(lua_State* const L_) if (_reading) { return LindaRestrict::None; } - std::string_view const _val{ luaG_tostring(_K, StackIndex{ 3 }) }; + std::string_view const _val{ luaW_tostring(_K, StackIndex{ 3 }) }; if (_val == "set/get") { return LindaRestrict::SetGet; } @@ -649,7 +649,7 @@ int keepercall_restrict(lua_State* const L_) lua_settop(_K, 0); // _K: auto const _prevRstrct{ _key ? _key->restrict : LindaRestrict::None }; // return a single value: the restrict mode of the key - luaG_pushstring(_K, _encodeRestrict(_prevRstrct)); // _K: _previous + luaW_pushstring(_K, _encodeRestrict(_prevRstrct)); // _K: _previous } else { if (_key == nullptr) { // _K: KeysDB key nil lua_pop(_K, 1); // _K: KeysDB key @@ -661,7 +661,7 @@ int keepercall_restrict(lua_State* const L_) // return true if we decide that blocked threads waiting to write on that key should be awakened // this is the case if we detect the key was full but it is no longer the case LindaRestrict const _previous{ _key->changeRestrict(_rstrct) }; - luaG_pushstring(_K, _encodeRestrict(_previous)); // _K: _previous + luaW_pushstring(_K, _encodeRestrict(_previous)); // _K: _previous } STACK_CHECK(_K, 1); return 1; @@ -680,7 +680,7 @@ int keepercall_send(lua_State* const L_) PushKeysDB(_K, StackIndex{ 1 }); // _K: linda key val... KeysDB // get the fifo associated to this key in this linda, create it if it doesn't exist lua_pushvalue(_K, 2); // _K: linda key val... KeysDB key - if (luaG_rawget(_K, StackIndex{ -2 }) == LuaType::NIL) { // _K: linda key val... KeysDB KeyUD|nil + if (luaW_rawget(_K, StackIndex{ -2 }) == LuaType::NIL) { // _K: linda key val... KeysDB KeyUD|nil lua_pop(_K, 1); // _K: linda key val... KeysDB std::ignore = KeyUD::Create(KeeperState{ _K }); // _K: linda key val... KeysDB KeyUD // KeysDB[key] = KeyUD @@ -863,7 +863,7 @@ int Keeper::PushLindaStorage(Linda& linda_, DestState const L_) STACK_CHECK_START_REL(_K, 0); kLindasRegKey.pushValue(_K); // _K: LindasDB L_: lua_pushlightuserdata(_K, &linda_); // _K: LindasDB linda L_: - LuaType const _type{ luaG_rawget(_K, StackIndex{ -2 }) }; // _K: LindasDB KeysDB L_: + LuaType const _type{ luaW_rawget(_K, StackIndex{ -2 }) }; // _K: LindasDB KeysDB L_: lua_remove(_K, -2); // _K: KeysDB L_: if (_type != LuaType::TABLE) { // possible if we didn't send anything through that linda lua_pop(_K, 1); // _K: L_: @@ -900,20 +900,20 @@ int Keeper::PushLindaStorage(Linda& linda_, DestState const L_) if (_key->limit >= 0) { lua_pushinteger(L_, _key->limit); // _K: KeysDB key L_: out key keyout fifo limit } else { - luaG_pushstring(L_, "unlimited"); // _K: KeysDB key L_: out key keyout fifo limit + luaW_pushstring(L_, "unlimited"); // _K: KeysDB key L_: out key keyout fifo limit } STACK_CHECK(L_, 5); lua_setfield(L_, -3, "limit"); // _K: KeysDB key L_: out key keyout fifo // keyout.restrict switch (_key->restrict) { case LindaRestrict::None: - luaG_pushstring(L_, "none"); // _K: KeysDB key L_: out key keyout fifo restrict + luaW_pushstring(L_, "none"); // _K: KeysDB key L_: out key keyout fifo restrict break; case LindaRestrict::SetGet: - luaG_pushstring(L_, "set/get"); // _K: KeysDB key L_: out key keyout fifo restrict + luaW_pushstring(L_, "set/get"); // _K: KeysDB key L_: out key keyout fifo restrict break; case LindaRestrict::SendReceive: - luaG_pushstring(L_, "send/receive"); // _K: KeysDB key L_: out key keyout fifo restrict + luaW_pushstring(L_, "send/receive"); // _K: KeysDB key L_: out key keyout fifo restrict break; } STACK_CHECK(L_, 5); @@ -1090,7 +1090,7 @@ void Keepers::initialize(Universe& U_, lua_State* L_, size_t const nbKeepers_, i keeper_.K = _K; // Give a name to the state - luaG_pushstring(_K, "Keeper #%d", i_ + 1); // L_: settings _K: "Keeper #n" + luaW_pushstring(_K, "Keeper #%d", i_ + 1); // L_: settings _K: "Keeper #n" if constexpr (HAVE_DECODA_SUPPORT()) { lua_pushvalue(_K, -1); // _K: "Keeper #n" Keeper #n" lua_setglobal(_K, "decoda_name"); // L_: settings _K: "Keeper #n" @@ -1112,9 +1112,9 @@ void Keepers::initialize(Universe& U_, lua_State* L_, size_t const nbKeepers_, i STACK_CHECK(_K, 0); // copy package.path and package.cpath from the source state - if (luaG_getmodule(L, LUA_LOADLIBNAME) != LuaType::NIL) { // L_: settings package _K: + if (luaW_getmodule(L, LUA_LOADLIBNAME) != LuaType::NIL) { // L_: settings package _K: // when copying with mode LookupMode::ToKeeper, error message is pushed at the top of the stack, not raised immediately - InterCopyContext _c{ U, DestState{ _K.value() }, SourceState{ L }, {}, SourceIndex{ luaG_absindex(L, kIdxTop).value() }, {}, LookupMode::ToKeeper, {} }; + InterCopyContext _c{ U, DestState{ _K.value() }, SourceState{ L }, {}, SourceIndex{ luaW_absindex(L, kIdxTop).value() }, {}, LookupMode::ToKeeper, {} }; if (_c.interCopyPackage() != InterCopyResult::Success) { // L_: settings ... error_msg _K: // if something went wrong, the error message is at the top of the stack lua_remove(L, -2); // L_: settings error_msg diff --git a/src/lane.cpp b/src/lane.cpp index 33ee8a0..b23ff78 100644 --- a/src/lane.cpp +++ b/src/lane.cpp @@ -49,7 +49,7 @@ static LUAG_FUNC(lane_get_threadname) { Lane* const _lane{ ToLane(L_, StackIndex{ 1 }) }; luaL_argcheck(L_, lua_gettop(L_) == 1, 2, "too many arguments"); - luaG_pushstring(L_, _lane->getDebugName()); + luaW_pushstring(L_, _lane->getDebugName()); return 1; } @@ -85,17 +85,17 @@ static LUAG_FUNC(set_finalizer) static LUAG_FUNC(lane_threadname) { // C s_lane structure is a light userdata upvalue - Lane* const _lane{ luaG_tolightuserdata(L_, StackIndex{ lua_upvalueindex(1) }) }; + Lane* const _lane{ luaW_tolightuserdata(L_, StackIndex{ lua_upvalueindex(1) }) }; LUA_ASSERT(L_, L_ == _lane->L); // this function is exported in a lane's state, therefore it is callable only from inside the Lane's state if (lua_gettop(L_) == 1) { lua_settop(L_, 1); STACK_CHECK_START_REL(L_, 0); - _lane->storeDebugName(luaG_tostring(L_, kIdxTop)); + _lane->storeDebugName(luaW_tostring(L_, kIdxTop)); _lane->applyDebugName(); STACK_CHECK(L_, 0); return 0; } else if (lua_gettop(L_) == 0) { - luaG_pushstring(L_, _lane->getDebugName()); + luaW_pushstring(L_, _lane->getDebugName()); return 1; } else { raise_luaL_error(L_, "Wrong number of arguments"); @@ -117,7 +117,7 @@ static LUAG_FUNC(lane_join) Lane* const _lane{ ToLane(L_, StackIndex{ 1 }) }; std::chrono::time_point _until{ std::chrono::time_point::max() }; - if (luaG_type(L_, StackIndex{ 2 }) == LuaType::NUMBER) { // we don't want to use lua_isnumber() because of autocoercion + if (luaW_type(L_, StackIndex{ 2 }) == LuaType::NUMBER) { // we don't want to use lua_isnumber() because of autocoercion lua_Duration const duration{ lua_tonumber(L_, 2) }; if (duration.count() >= 0.0) { _until = std::chrono::steady_clock::now() + std::chrono::duration_cast(duration); @@ -237,13 +237,13 @@ static int lane_index_string(lua_State* L_) Lane* const _lane{ ToLane(L_, kIdxSelf) }; LUA_ASSERT(L_, lua_gettop(L_) == 2); // L_: lane "key" - std::string_view const _keystr{ luaG_tostring(L_, kIdxKey) }; + std::string_view const _keystr{ luaW_tostring(L_, kIdxKey) }; lua_settop(L_, 2); // keep only our original arguments on the stack // look in metatable first lua_getmetatable(L_, kIdxSelf); // L_: lane "key" mt lua_replace(L_, -3); // L_: mt "key" - if (luaG_rawget(L_, StackIndex{ -2 }) != LuaType::NIL) { // found something? // L_: mt value + if (luaW_rawget(L_, StackIndex{ -2 }) != LuaType::NIL) { // found something? // L_: mt value return 1; // done } @@ -269,7 +269,7 @@ static LUAG_FUNC(lane_index) Lane* const _lane{ ToLane(L_, kIdxSelf) }; LUA_ASSERT(L_, lua_gettop(L_) == 2); - switch (luaG_type(L_, kKey)) { + switch (luaW_type(L_, kKey)) { case LuaType::NUMBER: return lane_index_number(L_); // stack modification is undefined, returned value is at the top @@ -279,19 +279,19 @@ static LUAG_FUNC(lane_index) default: // unknown key lua_getmetatable(L_, kIdxSelf); // L_: mt kCachedError.pushKey(L_); // L_: mt kCachedError - if (luaG_rawget(L_, StackIndex{ -2 }) != LuaType::FUNCTION) { // L_: mt error() - raise_luaL_error(L_, "INTERNAL ERROR: cached error() is a %s, not a function", luaG_typename(L_, kIdxTop).data()); + if (luaW_rawget(L_, StackIndex{ -2 }) != LuaType::FUNCTION) { // L_: mt error() + raise_luaL_error(L_, "INTERNAL ERROR: cached error() is a %s, not a function", luaW_typename(L_, kIdxTop).data()); } - luaG_pushstring(L_, "Unknown key: "); // L_: mt error() "Unknown key: " + luaW_pushstring(L_, "Unknown key: "); // L_: mt error() "Unknown key: " kCachedTostring.pushKey(L_); // L_: mt error() "Unknown key: " kCachedTostring - if (luaG_rawget(L_, StackIndex{ -4 }) != LuaType::FUNCTION) { // L_: mt error() "Unknown key: " tostring() - raise_luaL_error(L_, "INTERNAL ERROR: cached tostring() is a %s, not a function", luaG_typename(L_, kIdxTop).data()); + if (luaW_rawget(L_, StackIndex{ -4 }) != LuaType::FUNCTION) { // L_: mt error() "Unknown key: " tostring() + raise_luaL_error(L_, "INTERNAL ERROR: cached tostring() is a %s, not a function", luaW_typename(L_, kIdxTop).data()); } lua_pushvalue(L_, kKey); // L_: mt error() "Unknown key: " tostring() k lua_call(L_, 1, 1); // L_: mt error() "Unknown key: " "k" lua_concat(L_, 2); // L_: mt error() "Unknown key: " lua_call(L_, 1, 0); // error( "Unknown key: " .. key) -> doesn't return // L_: mt - raise_luaL_error(L_, "%s[%s]: should not get here!", _lane->getDebugName().data(), luaG_typename(L_, kKey).data()); + raise_luaL_error(L_, "%s[%s]: should not get here!", _lane->getDebugName().data(), luaW_typename(L_, kKey).data()); } } @@ -382,7 +382,7 @@ int Lane::LuaErrorHandler(lua_State* L_) // table of { "sourcefile.lua:", ... } // lua_newtable(L_); // L_: some_error {} - StackIndex const kIdxTraceTbl{ luaG_absindex(L_, kIdxTop) }; + StackIndex const kIdxTraceTbl{ luaW_absindex(L_, kIdxTop) }; // Best to start from level 1, but in some cases it might be a C function // and we don't get '.currentline' for that. It's okay - just keep level @@ -393,25 +393,25 @@ int Lane::LuaErrorHandler(lua_State* L_) lua_getinfo(L_, _extended ? "Sln" : "Sl", &_ar); if (_extended) { lua_newtable(L_); // L_: some_error {} {} - StackIndex const kIdxFrameTbl{ luaG_absindex(L_, kIdxTop) }; + StackIndex const kIdxFrameTbl{ luaW_absindex(L_, kIdxTop) }; lua_pushstring(L_, _ar.source); // L_: some_error {} {} source - luaG_setfield(L_, kIdxFrameTbl, std::string_view{ "source" }); // L_: some_error {} {} + luaW_setfield(L_, kIdxFrameTbl, std::string_view{ "source" }); // L_: some_error {} {} lua_pushinteger(L_, _ar.currentline); // L_: some_error {} {} currentline - luaG_setfield(L_, kIdxFrameTbl, std::string_view{ "currentline" }); // L_: some_error {} {} + luaW_setfield(L_, kIdxFrameTbl, std::string_view{ "currentline" }); // L_: some_error {} {} lua_pushstring(L_, _ar.name ? _ar.name : ""); // L_: some_error {} {} name - luaG_setfield(L_, kIdxFrameTbl, std::string_view{ "name" }); // L_: some_error {} {} + luaW_setfield(L_, kIdxFrameTbl, std::string_view{ "name" }); // L_: some_error {} {} lua_pushstring(L_, _ar.namewhat); // L_: some_error {} {} namewhat - luaG_setfield(L_, kIdxFrameTbl, std::string_view{ "namewhat" }); // L_: some_error {} {} + luaW_setfield(L_, kIdxFrameTbl, std::string_view{ "namewhat" }); // L_: some_error {} {} lua_pushstring(L_, _ar.what); // L_: some_error {} {} what - luaG_setfield(L_, kIdxFrameTbl, std::string_view{ "what" }); // L_: some_error {} {} + luaW_setfield(L_, kIdxFrameTbl, std::string_view{ "what" }); // L_: some_error {} {} } else if (_ar.currentline > 0) { - luaG_pushstring(L_, "%s:%d", _ar.short_src, _ar.currentline); // L_: some_error {} "blah:blah" + luaW_pushstring(L_, "%s:%d", _ar.short_src, _ar.currentline); // L_: some_error {} "blah:blah" } else { - luaG_pushstring(L_, "%s:?", _ar.short_src); // L_: some_error {} "blah" + luaW_pushstring(L_, "%s:?", _ar.short_src); // L_: some_error {} "blah" } lua_rawseti(L_, kIdxTraceTbl, static_cast(_n)); // L_: some_error {} } @@ -448,7 +448,7 @@ static int PushStackTrace(lua_State* const L_, Lane::ErrorTraceLevel const error // For cancellation the error message is kCancelError, and a stack trace isn't placed // For other errors, the message can be whatever was thrown, and we should have a stack trace table - LUA_ASSERT(L_, luaG_type(L_, StackIndex{ 1 + stk_base_ }) == (kCancelError.equals(L_, stk_base_) ? LuaType::NIL : LuaType::TABLE)); + LUA_ASSERT(L_, luaW_type(L_, StackIndex{ 1 + stk_base_ }) == (kCancelError.equals(L_, stk_base_) ? LuaType::NIL : LuaType::TABLE)); // Just leaving the stack trace table on the stack is enough to get it through to the master. } else { // any kind of error can be thrown with error(), or through a lane/linda cancellation @@ -460,7 +460,7 @@ static int PushStackTrace(lua_State* const L_, Lane::ErrorTraceLevel const error case LuaError::ERRERR: // error while running the error handler (if any, for example an out-of-memory condition) default: // the Lua core provides a string error message in those situations - LUA_ASSERT(L_, (lua_gettop(L_) == stk_base_) && (luaG_type(L_, stk_base_) == LuaType::STRING)); + LUA_ASSERT(L_, (lua_gettop(L_) == stk_base_) && (luaW_type(L_, stk_base_) == LuaType::STRING)); break; } return lua_gettop(L_) - _top; // either 0 or 1 @@ -509,7 +509,7 @@ static LuaError run_finalizers(Lane* const lane_, Lane::ErrorTraceLevel const er LUA_ASSERT(_L, lua_isfunction(_L, -1)); if (lua_rc_ != LuaError::OK) { // we have , [trace] on the thread stack LUA_ASSERT(_L, lane_->nresults == 1 || lane_->nresults == 2); - //std::string_view const _err_msg{ luaG_tostring(_L, 1) }; + //std::string_view const _err_msg{ luaW_tostring(_L, 1) }; if (lane_->isCoroutine()) { // transfer them on the main state lua_pushvalue(lane_->L, 1); @@ -561,7 +561,7 @@ static LuaError run_finalizers(Lane* const lane_, Lane::ErrorTraceLevel const er if (lane_->isCoroutine()) { // only the coroutine thread should remain on the master state when we are done - LUA_ASSERT(_L, lua_gettop(_L) == 1 && luaG_type(_L, StackIndex{ 1 }) == LuaType::THREAD); + LUA_ASSERT(_L, lua_gettop(_L) == 1 && luaW_type(_L, StackIndex{ 1 }) == LuaType::THREAD); } return _rc; @@ -674,7 +674,7 @@ static void lane_main(Lane* const lane_) do { // starting with Lua 5.4, lua_resume can leave more stuff on the stack below the actual yielded values. // that's why we have lane_->nresults - _rc = luaG_resume(_L, nullptr, _nargs, &lane_->nresults); // L: ... retvals|err... + _rc = luaW_resume(_L, nullptr, _nargs, &lane_->nresults); // L: ... retvals|err... if (_rc == LuaError::YIELD) { // on the stack we find the values pushed by lane:resume() _nargs = lua_gettop(_L); @@ -748,7 +748,7 @@ static void lane_main(Lane* const lane_) // in case of error and if it exists, fetch stack trace from registry and push it lane_->nresults += PushStackTrace(_L, lane_->errorTraceLevel, _rc, StackIndex{ 1 }); // L: retvals|error [trace] - DEBUGSPEW_CODE(DebugSpew(lane_->U) << "Lane " << _L << " body: " << GetErrcodeName(_rc) << " (" << (kCancelError.equals(_L, StackIndex{ 1 }) ? "cancelled" : luaG_typename(_L, StackIndex{ 1 })) << ")" << std::endl); + DEBUGSPEW_CODE(DebugSpew(lane_->U) << "Lane " << _L << " body: " << GetErrcodeName(_rc) << " (" << (kCancelError.equals(_L, StackIndex{ 1 }) ? "cancelled" : luaW_typename(_L, StackIndex{ 1 })) << ")" << std::endl); // Call finalizers, if the script has set them up. // If the lane is not a coroutine, there is only a regular state, so everything is the same whether we use S or L. // If the lane is a coroutine, this has to be done from the master state (S), not the thread (L), because we can't lua_pcall in a thread state @@ -797,7 +797,7 @@ static LUAG_FUNC(lane_close) lua_settop(L_, 1); // L_: lane // no error if the lane body doesn't return a non-nil first value - luaG_pushstring(L_, "close"); // L_: lane "close" + luaW_pushstring(L_, "close"); // L_: lane "close" lua_pushcclosure(L_, LG_lane_join, 1); // L_: lane join() lua_insert(L_, 1); // L_: join() lane lua_call(L_, 1, LUA_MULTRET); // L_: join() results @@ -827,9 +827,9 @@ static LUAG_FUNC(lane_gc) // if there a gc callback? lua_getiuservalue(L_, StackIndex{ 1 }, UserValueIndex{ 1 }); // L_: ud uservalue kLaneGC.pushKey(L_); // L_: ud uservalue __gc - if (luaG_rawget(L_, StackIndex{ -2 }) != LuaType::NIL) { // L_: ud uservalue gc_cb|nil + if (luaW_rawget(L_, StackIndex{ -2 }) != LuaType::NIL) { // L_: ud uservalue gc_cb|nil lua_remove(L_, -2); // L_: ud gc_cb|nil - luaG_pushstring(L_, _lane->getDebugName()); // L_: ud gc_cb name + luaW_pushstring(L_, _lane->getDebugName()); // L_: ud gc_cb name _have_gc_cb = true; } else { lua_pop(L_, 2); // L_: ud @@ -840,7 +840,7 @@ static LUAG_FUNC(lane_gc) // still running: will have to be cleaned up later _lane->selfdestructAdd(); if (_have_gc_cb) { - luaG_pushstring(L_, "selfdestruct"); // L_: ud gc_cb name status + luaW_pushstring(L_, "selfdestruct"); // L_: ud gc_cb name status lua_call(L_, 2, 0); // L_: ud } return 0; @@ -855,7 +855,7 @@ static LUAG_FUNC(lane_gc) // do this after lane cleanup in case the callback triggers an error if (_have_gc_cb) { - luaG_pushstring(L_, "closed"); // L_: ud gc_cb name status + luaW_pushstring(L_, "closed"); // L_: ud gc_cb name status lua_call(L_, 2, 0); // L_: ud } return 0; @@ -900,7 +900,7 @@ void Lane::applyDebugName() const { if constexpr (HAVE_DECODA_SUPPORT()) { // to see VM name in Decoda debugger Virtual Machine window - luaG_pushstring(L, debugName); // L: ... "name" + luaW_pushstring(L, debugName); // L: ... "name" lua_setglobal(L, "decoda_name"); // L: ... } // and finally set the OS thread name @@ -1013,7 +1013,7 @@ void Lane::PushMetatable(lua_State* const L_) { STACK_CHECK_START_REL(L_, 0); if (luaL_newmetatable(L_, kLaneMetatableName.data())) { // L_: mt - luaG_registerlibfuncs(L_, local::sLaneFunctions); + luaW_registerlibfuncs(L_, local::sLaneFunctions); // cache error() and tostring() kCachedError.pushKey(L_); // L_: mt kCachedError lua_getglobal(L_, "error"); // L_: mt kCachedError error() @@ -1022,7 +1022,7 @@ void Lane::PushMetatable(lua_State* const L_) lua_getglobal(L_, "tostring"); // L_: mt kCachedTostring tostring() lua_rawset(L_, -3); // L_: mt // hide the actual metatable from getmetatable() - luaG_pushstring(L_, kLaneMetatableName); // L_: mt "Lane" + luaW_pushstring(L_, kLaneMetatableName); // L_: mt "Lane" lua_setfield(L_, -2, "__metatable"); // L_: mt } STACK_CHECK(L_, 1); @@ -1035,7 +1035,7 @@ void Lane::pushStatusString(lua_State* const L_) const std::string_view const _str{ threadStatusString() }; LUA_ASSERT(L_, !_str.empty()); - luaG_pushstring(L_, _str); + luaW_pushstring(L_, _str); } // ################################################################################################# @@ -1175,7 +1175,7 @@ std::string_view Lane::pushErrorTraceLevel(lua_State* L_) const std::string_view const _str{ errorTraceLevelString() }; LUA_ASSERT(L_, !_str.empty()); - return luaG_pushstring(L_, _str); + return luaW_pushstring(L_, _str); } // ################################################################################################# @@ -1186,7 +1186,7 @@ void Lane::resetResultsStorage(lua_State* const L_, StackIndex const self_idx_) { STACK_GROW(L_, 4); STACK_CHECK_START_REL(L_, 0); - StackIndex const _self_idx{ luaG_absindex(L_, self_idx_) }; + StackIndex const _self_idx{ luaW_absindex(L_, self_idx_) }; LUA_ASSERT(L_, ToLane(L_, _self_idx) == this); // L_: ... self ... // create the new table lua_newtable(L_); // L_: ... self ... {} @@ -1220,7 +1220,7 @@ void Lane::securizeDebugName(lua_State* const L_) lua_newtable(L_); // L_: lane ... {uv} {} { std::lock_guard _guard{ debugNameMutex }; - debugName = luaG_pushstring(L_, debugName); // L_: lane ... {uv} {} name + debugName = luaW_pushstring(L_, debugName); // L_: lane ... {uv} {} name } lua_rawset(L_, -3); // L_: lane ... {uv} lua_pop(L_, 1); // L_: lane @@ -1243,13 +1243,13 @@ void Lane::storeDebugName(std::string_view const& 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... - kLaneNameRegKey.setValue(L, [name = name_](lua_State* L_) { luaG_pushstring(L_, name); }); + kLaneNameRegKey.setValue(L, [name = name_](lua_State* L_) { luaW_pushstring(L_, name); }); STACK_CHECK(L, 0); kLaneNameRegKey.pushValue(L); // L: ... "name" ... // keep a direct view on the stored string { std::lock_guard _guard{ debugNameMutex }; - debugName = luaG_tostring(L, kIdxTop); + debugName = luaW_tostring(L, kIdxTop); } lua_pop(L, 1); STACK_CHECK(L, 0); @@ -1283,7 +1283,7 @@ int Lane::storeResults(lua_State* const L_) default: // this is an internal error, we probably never get here lua_settop(L_, 0); // L_: - luaG_pushstring(L_, "Unexpected status: "); // L_: "Unexpected status: " + luaW_pushstring(L_, "Unexpected status: "); // L_: "Unexpected status: " pushStatusString(L_); // L_: "Unexpected status: " "" lua_concat(L_, 2); // L_: "Unexpected status: " raise_lua_error(L_); @@ -1421,7 +1421,7 @@ bool Lane::waitForJoin(lua_State* const L_, std::chrono::time_pointtimerLinda->push(L_); // L_: duration|nil receive() timerLinda - if (luaG_tostring(L_, StackIndex{ 1 }) == "indefinitely") { + if (luaW_tostring(L_, StackIndex{ 1 }) == "indefinitely") { lua_pushnil(L_); // L_: duration? receive() timerLinda nil } else if (lua_isnoneornil(L_, 1)) { lua_pushnumber(L_, 0); // L_: duration? receive() timerLinda 0 @@ -183,7 +183,7 @@ LUAG_FUNC(sleep) else { lua_pushnumber(L_, lua_tonumber(L_, 1)); // L_: duration? receive() timerLinda duration } - luaG_pushstring(L_, "ac100de1-a696-4619-b2f0-a26de9d58ab8"); // L_: duration? receive() timerLinda duration key + luaW_pushstring(L_, "ac100de1-a696-4619-b2f0-a26de9d58ab8"); // L_: duration? receive() timerLinda duration key STACK_CHECK(L_, 3); // 3 arguments ready lua_call(L_, 3, LUA_MULTRET); // timerLinda:receive(duration,key) // L_: duration? result... return lua_gettop(L_) - 1; @@ -197,7 +197,7 @@ LUAG_FUNC(sleep) // upvalue[1]: _G.require LUAG_FUNC(require) { - std::string_view const _name{ luaG_tostring(L_, StackIndex{ 1 }) }; // L_: "name" ... + std::string_view const _name{ luaW_tostring(L_, StackIndex{ 1 }) }; // L_: "name" ... int const _nargs{ lua_gettop(L_) }; DEBUGSPEW_CODE(Universe * _U{ Universe::Get(L_) }); STACK_CHECK_START_REL(L_, 0); @@ -223,8 +223,8 @@ int lanes_register(lua_State* const L_) if (!_U) { raise_luaL_error(L_, "Lanes is not ready"); } - std::string_view const _name{ luaG_checkstring(L_, StackIndex{ 1 }) }; - LuaType const _mod_type{ luaG_type(L_, StackIndex{ 2 }) }; + std::string_view const _name{ luaW_checkstring(L_, StackIndex{ 1 }) }; + LuaType const _mod_type{ luaW_type(L_, StackIndex{ 2 }) }; // ignore extra arguments, just in case lua_settop(L_, 2); luaL_argcheck(L_, (_mod_type == LuaType::TABLE) || (_mod_type == LuaType::FUNCTION), 2, "unexpected module type"); @@ -292,7 +292,7 @@ LUAG_FUNC(lane_new) Universe* const _U{ Universe::Get(L_) }; DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: setup" << std::endl); - std::optional _libs_str{ lua_isnil(L_, kLibsIdx) ? std::nullopt : std::make_optional(luaG_tostring(L_, kLibsIdx)) }; + std::optional _libs_str{ lua_isnil(L_, kLibsIdx) ? std::nullopt : std::make_optional(luaW_tostring(L_, kLibsIdx)) }; lua_State* const _S{ state::NewLaneState(_U, SourceState{ L_ }, _libs_str) }; // L_: [fixed] ... L2: STACK_CHECK_START_REL(_S, 0); @@ -354,7 +354,7 @@ LUAG_FUNC(lane_new) DEBUGSPEW_CODE(DebugSpew(lane->U) << "lane_new: preparing lane userdata" << std::endl); STACK_CHECK_START_REL(L, 0); // a Lane full userdata needs a single uservalue - Lane** const _ud{ luaG_newuserdatauv(L, UserValueCount{ 1 }) }; // L: ... lane + Lane** const _ud{ luaW_newuserdatauv(L, UserValueCount{ 1 }) }; // L: ... lane *_ud = lane; // don't forget to store the pointer in the userdata! // Set metatable for the userdata @@ -378,25 +378,25 @@ LUAG_FUNC(lane_new) lua_setiuservalue(L, StackIndex{ -2 }, UserValueIndex{ 1 }); // L: ... lane StackIndex const _name_idx{ lua_isnoneornil(L, kNameIdx) ? kIdxNone : kNameIdx }; - std::string_view _debugName{ (_name_idx > 0) ? luaG_tostring(L, _name_idx) : std::string_view{} }; + std::string_view _debugName{ (_name_idx > 0) ? luaW_tostring(L, _name_idx) : std::string_view{} }; if (!_debugName.empty()) { if (_debugName == "auto") { - if (luaG_type(L, kFuncIdx) == LuaType::STRING) { + if (luaW_type(L, kFuncIdx) == LuaType::STRING) { lua_Debug _ar; if (lua_getstack(L, 2, &_ar) == 0) { // 0 is here, 1 is lanes.gen, 2 is its caller lua_getstack(L, 1, &_ar); // level 2 may not exist with LuaJIT, try again with level 1 } lua_getinfo(L, "Sl", &_ar); - luaG_pushstring(L, "%s:%d", _ar.short_src, _ar.currentline); // L: ... lane "" + luaW_pushstring(L, "%s:%d", _ar.short_src, _ar.currentline); // L: ... lane "" } else { lua_Debug _ar; lua_pushvalue(L, kFuncIdx); // L: ... lane func lua_getinfo(L, ">S", &_ar); // L: ... lane - luaG_pushstring(L, "%s:%d", _ar.short_src, _ar.linedefined); // L: ... lane "" + luaW_pushstring(L, "%s:%d", _ar.short_src, _ar.linedefined); // L: ... lane "" } lua_replace(L, _name_idx); // L: ... lane - _debugName = luaG_tostring(L, _name_idx); + _debugName = luaW_tostring(L, _name_idx); } lane->storeDebugName(_debugName); } @@ -461,17 +461,17 @@ LUAG_FUNC(lane_new) DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: process 'required' list" << std::endl); DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); // should not happen, was checked in lanes.lua before calling lane_new() - if (luaG_type(L_, _required_idx) != LuaType::TABLE) { + if (luaW_type(L_, _required_idx) != LuaType::TABLE) { raise_luaL_error(L_, "expected required module list as a table, got %s", luaL_typename(L_, _required_idx)); } lua_pushnil(L_); // L_: [fixed] args... nil L2: while (lua_next(L_, _required_idx) != 0) { // L_: [fixed] args... n "modname" L2: - if (luaG_type(L_, kIdxTop) != LuaType::STRING || luaG_type(L_, StackIndex{ -2 }) != LuaType::NUMBER || lua_tonumber(L_, -2) != _nbRequired) { + if (luaW_type(L_, kIdxTop) != LuaType::STRING || luaW_type(L_, StackIndex{ -2 }) != LuaType::NUMBER || lua_tonumber(L_, -2) != _nbRequired) { raise_luaL_error(L_, "required module list should be a list of strings"); } else { // require the module in the target state, and populate the lookup table there too - std::string_view const _name{ luaG_tostring(L_, kIdxTop) }; + std::string_view const _name{ luaW_tostring(L_, kIdxTop) }; DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: require '" << _name << "'" << std::endl); // require the module in the target lane @@ -480,7 +480,7 @@ LUAG_FUNC(lane_new) lua_pop(_L2, 1); // L_: [fixed] args... n "modname" L2: raise_luaL_error(L_, "cannot pre-require modules without loading 'package' library first"); } else { - luaG_pushstring(_L2, _name); // L_: [fixed] args... n "modname" L2: require() name + luaW_pushstring(_L2, _name); // L_: [fixed] args... n "modname" L2: require() name LuaError const _rc{ lua_pcall(_L2, 1, 1, 0) }; // L_: [fixed] args... n "modname" L2: ret/errcode if (_rc != LuaError::OK) { // propagate error to main state if any @@ -515,7 +515,7 @@ LUAG_FUNC(lane_new) lua_pushnil(L_); // L_: [fixed] args... nil L2: // Lua 5.2 wants us to push the globals table on the stack InterCopyContext _c{ _U, DestState{ _L2 }, SourceState{ L_ }, {}, {}, {}, {}, {} }; - luaG_pushglobaltable(_L2); // L_: [fixed] args... nil L2: _G + luaW_pushglobaltable(_L2); // L_: [fixed] args... nil L2: _G while (lua_next(L_, _globals_idx)) { // L_: [fixed] args... k v L2: _G std::ignore = _c.interCopy(2); // L_: [fixed] args... k v L2: _G k v // assign it in L2's globals table @@ -529,7 +529,7 @@ LUAG_FUNC(lane_new) // Lane main function [[maybe_unused]] int const _errorHandlerCount{ _lane->pushErrorHandler() }; // L_: [fixed] args... L2: eh? - LuaType const _func_type{ luaG_type(L_, kFuncIdx) }; + LuaType const _func_type{ luaW_type(L_, kFuncIdx) }; if (_func_type == LuaType::FUNCTION) { DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: transfer lane body" << std::endl); DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); @@ -546,7 +546,7 @@ LUAG_FUNC(lane_new) raise_luaL_error(L_, "error when parsing lane function code"); } } else { - raise_luaL_error(L_, "Expected function, got %s", luaG_typename(L_, _func_type).data()); + raise_luaL_error(L_, "Expected function, got %s", luaW_typename(L_, _func_type).data()); } STACK_CHECK(L_, 0); STACK_CHECK(_L2, _errorHandlerCount + 1); @@ -634,7 +634,7 @@ LUAG_FUNC(wakeup_conv) STACK_CHECK_START_REL(L_, 0); auto _readInteger = [L = L_](std::string_view const& name_) { - std::ignore = luaG_getfield(L, StackIndex{ 1 }, name_); + std::ignore = luaW_getfield(L, StackIndex{ 1 }, name_); lua_Integer const val{ lua_tointeger(L, -1) }; lua_pop(L, 1); return static_cast(val); @@ -650,7 +650,7 @@ LUAG_FUNC(wakeup_conv) // If Lua table has '.isdst' we trust that. If it does not, we'll let // 'mktime' decide on whether the time is within DST or not (value -1). // - int const _isdst{ (luaG_getfield(L_, StackIndex{ 1 }, "isdst") == LuaType::BOOLEAN) ? lua_toboolean(L_, -1) : -1 }; + int const _isdst{ (luaW_getfield(L_, StackIndex{ 1 }, "isdst") == LuaType::BOOLEAN) ? lua_toboolean(L_, -1) : -1 }; lua_pop(L_, 1); STACK_CHECK(L_, 0); @@ -715,8 +715,8 @@ LUAG_FUNC(configure) Universe* _U{ Universe::Get(L_) }; bool const _from_master_state{ _U == nullptr }; - std::string_view const _name{ luaG_checkstring(L_, StackIndex{ lua_upvalueindex(1) }) }; - LUA_ASSERT(L_, luaG_type(L_, StackIndex{ 1 }) == LuaType::TABLE); + std::string_view const _name{ luaW_checkstring(L_, StackIndex{ lua_upvalueindex(1) }) }; + LUA_ASSERT(L_, luaW_type(L_, StackIndex{ 1 }) == LuaType::TABLE); STACK_GROW(L_, 4); STACK_CHECK_START_ABS(L_, 1); // L_: settings @@ -726,7 +726,7 @@ LUAG_FUNC(configure) if (_U == nullptr) { // 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... - kLaneNameRegKey.setValue(L_, [](lua_State* L_) { luaG_pushstring(L_, "main"); }); + kLaneNameRegKey.setValue(L_, [](lua_State* L_) { luaW_pushstring(L_, "main"); }); // create the universe _U = Universe::Create(L_); // L_: settings universe @@ -742,7 +742,7 @@ LUAG_FUNC(configure) lua_pushnil(L_); // L_: settings M nil lua_setfield(L_, -2, "configure"); // L_: settings M // add functions to the module's table - luaG_registerlibfuncs(L_, local::sLanesFunctions); + luaW_registerlibfuncs(L_, local::sLanesFunctions); // register core.threads() only if settings say it should be available if (_U->tracker.isActive()) { @@ -767,7 +767,7 @@ LUAG_FUNC(configure) lua_pushcclosure(L_, LG_require, 1); // L_: settings M lanes.require lua_setfield(L_, -2, "require"); // L_: settings M - luaG_pushstring( + luaW_pushstring( L_, "%d.%d.%d", LANES_VERSION_MAJOR, @@ -799,7 +799,7 @@ LUAG_FUNC(configure) // don't do this when called during the initialization of a new lane, // because we will do it after on_state_create() is called, // and we don't want to skip _G because of caching in case globals are created then - luaG_pushglobaltable(L_); // L_: settings M _G + luaW_pushglobaltable(L_); // L_: settings M _G tools::PopulateFuncLookupTable(L_, kIdxTop, {}); lua_pop(L_, 1); // L_: settings M } @@ -879,10 +879,10 @@ LANES_API int luaopen_lanes_core(lua_State* const L_) // Prevent PUC-Lua/LuaJIT mismatch. Hopefully this works for MoonJIT too if constexpr (LUAJIT_FLAVOR() == 0) { - if (luaG_getmodule(L_, LUA_JITLIBNAME) != LuaType::NIL) + if (luaW_getmodule(L_, LUA_JITLIBNAME) != LuaType::NIL) raise_luaL_error(L_, "Lanes is built for PUC-Lua, don't run from LuaJIT"); } else { - if (luaG_getmodule(L_, LUA_JITLIBNAME) == LuaType::NIL) + if (luaW_getmodule(L_, LUA_JITLIBNAME) == LuaType::NIL) raise_luaL_error(L_, "Lanes is built for LuaJIT, don't run from PUC-Lua"); } lua_pop(L_, 1); // L_: diff --git a/src/linda.cpp b/src/linda.cpp index 5fb8279..75d1748 100644 --- a/src/linda.cpp +++ b/src/linda.cpp @@ -47,7 +47,7 @@ namespace { { STACK_CHECK_START_REL(L_, 0); for (StackIndex const _i : std::ranges::iota_view{ start_, StackIndex{ end_ + 1 } }) { - LuaType const _t{ luaG_type(L_, _i) }; + LuaType const _t{ luaW_type(L_, _i) }; switch (_t) { case LuaType::BOOLEAN: case LuaType::NUMBER: @@ -109,13 +109,13 @@ namespace { { Linda* const _linda{ ToLinda(L_, idx_) }; if (_linda != nullptr) { - luaG_pushstring(L_, "Linda: "); + luaW_pushstring(L_, "Linda: "); std::string_view const _lindaName{ _linda->getName() }; if (!_lindaName.empty()) { - luaG_pushstring(L_, _lindaName); + luaW_pushstring(L_, _lindaName); } else { // obfuscate the pointer so that we can't read the value with our eyes out of a script - luaG_pushstring(L_, "%p", _linda->obfuscated()); + luaW_pushstring(L_, "%p", _linda->obfuscated()); } lua_concat(L_, 2); return 1; @@ -132,7 +132,7 @@ namespace { StackIndex _key_i{ 2 }; // index of first slot, if timeout not there std::chrono::time_point _until{ std::chrono::time_point::max() }; - if (luaG_type(L_, StackIndex{ 2 }) == LuaType::NUMBER) { // we don't want to use lua_isnumber() because of autocoercion + if (luaW_type(L_, StackIndex{ 2 }) == LuaType::NUMBER) { // we don't want to use lua_isnumber() because of autocoercion lua_Duration const _duration{ lua_tonumber(L_, 2) }; if (_duration.count() >= 0.0) { _until = std::chrono::steady_clock::now() + std::chrono::duration_cast(_duration); @@ -279,7 +279,7 @@ namespace { if (_nbPushed == 0) { // not enough data in the linda slot to fulfill the request, return nil, "timeout" lua_pushnil(L_); - luaG_pushstring(L_, "timeout"); + luaW_pushstring(L_, "timeout"); return 2; } return _nbPushed; @@ -350,16 +350,16 @@ Linda* Linda::CreateTimerLinda(lua_State* const L_) // Initialize 'timerLinda'; a common Linda object shared by all states lua_pushcfunction(L_, LG_linda); // L_: lanes.linda lua_createtable(L_, 0, 3); // L_: lanes.linda {} - luaG_pushstring(L_, "lanes-timer"); // L_: lanes.linda {} "lanes-timer" - luaG_setfield(L_, StackIndex{ -2 }, std::string_view{ "name" }); // L_: lanes.linda { .name="lanes-timer" } + luaW_pushstring(L_, "lanes-timer"); // L_: lanes.linda {} "lanes-timer" + luaW_setfield(L_, StackIndex{ -2 }, std::string_view{ "name" }); // L_: lanes.linda { .name="lanes-timer" } lua_pushinteger(L_, 0); // L_: lanes.linda { .name="lanes-timer" } 0 - luaG_setfield(L_, StackIndex{ -2 }, std::string_view{ "group" }); // L_: lanes.linda { .name="lanes-timer" .group = 0 } + luaW_setfield(L_, StackIndex{ -2 }, std::string_view{ "group" }); // L_: lanes.linda { .name="lanes-timer" .group = 0 } // note that wake_period is not set (will default to the value in the universe) lua_call(L_, 1, 1); // L_: linda STACK_CHECK(L_, 1); // Proxy userdata contents is only a 'DeepPrelude*' pointer - auto const _timerLinda{ *luaG_tofulluserdata(L_, kIdxTop) }; + auto const _timerLinda{ *luaW_tofulluserdata(L_, kIdxTop) }; // increment refcount so that this linda remains alive as long as the universe exists. _timerLinda->refcount.fetch_add(1, std::memory_order_relaxed); lua_pop(L_, 1); // L_: @@ -452,7 +452,7 @@ int Linda::ProtectedCall(lua_State* const L_, lua_CFunction const f_) void Linda::pushCancelString(lua_State* L_) const { - luaG_pushstring(L_, cancelStatus == Status::Cancelled ? "cancelled" : "active"); + luaW_pushstring(L_, cancelStatus == Status::Cancelled ? "cancelled" : "active"); } // ################################################################################################# @@ -504,7 +504,7 @@ void Linda::setName(std::string_view const& name_) LUAG_FUNC(linda_cancel) { Linda* const _linda{ ToLinda(L_, StackIndex{ 1 }) }; - std::string_view const _who{ luaG_optstring(L_, StackIndex{ 2 }, "both") }; + std::string_view const _who{ luaW_optstring(L_, StackIndex{ 2 }, "both") }; // make sure we got 2 arguments: the linda and the cancellation mode luaL_argcheck(L_, lua_gettop(L_) <= 2, 2, "wrong number of arguments"); @@ -592,13 +592,13 @@ static int linda_index_string(lua_State* L_) Linda* const _linda{ ToLinda(L_, kIdxSelf) }; LUA_ASSERT(L_, lua_gettop(L_) == 2); // L_: linda "key" - std::string_view const _keystr{ luaG_tostring(L_, kIdxKey) }; + std::string_view const _keystr{ luaW_tostring(L_, kIdxKey) }; lua_settop(L_, 2); // keep only our original arguments on the stack // look in metatable first lua_getmetatable(L_, kIdxSelf); // L_: linda "key" mt lua_replace(L_, -3); // L_: mt "key" - if (luaG_rawget(L_, StackIndex{ -2 }) != LuaType::NIL) { // found something? // L_: mt value + if (luaW_rawget(L_, StackIndex{ -2 }) != LuaType::NIL) { // found something? // L_: mt value return 1; // done } @@ -618,12 +618,12 @@ static LUAG_FUNC(linda_index) static constexpr StackIndex kIdxKey{ 2 }; LUA_ASSERT(L_, lua_gettop(L_) == 2); - switch (luaG_type(L_, kIdxKey)) { + switch (luaW_type(L_, kIdxKey)) { case LuaType::STRING: return linda_index_string(L_); // stack modification is undefined, returned value is at the top default: // unknown key - raise_luaL_error(L_, "Unsupported linda indexing key type %s", luaG_typename(L_, kIdxKey).data()); + raise_luaL_error(L_, "Unsupported linda indexing key type %s", luaW_typename(L_, kIdxKey).data()); } } @@ -766,7 +766,7 @@ LUAG_FUNC(linda_limit) int const _nargs{ lua_gettop(L_) }; luaL_argcheck(L_, _nargs == 2 || _nargs == 3, 2, "wrong number of arguments"); // make sure we got a numeric limit, or "unlimited", (or nothing) - bool const _unlimited{ luaG_tostring(L_, StackIndex{ 3 }) == "unlimited" }; + bool const _unlimited{ luaW_tostring(L_, StackIndex{ 3 }) == "unlimited" }; LindaLimit const _val{ _unlimited ? std::numeric_limits::max() : static_cast(luaL_optinteger(L_, 3, 0)) }; if (_val < 0) { raise_luaL_argerror(L_, StackIndex{ 3 }, "limit must be >= 0"); @@ -777,23 +777,23 @@ LUAG_FUNC(linda_limit) KeeperCallResult _pushed; if (_linda->cancelStatus == Linda::Active) { if (_unlimited) { - LUA_ASSERT(L_, lua_gettop(L_) == 3 && luaG_tostring(L_, StackIndex{ 3 }) == "unlimited"); + LUA_ASSERT(L_, lua_gettop(L_) == 3 && luaW_tostring(L_, StackIndex{ 3 }) == "unlimited"); // inside the Keeper, unlimited is signified with a -1 limit (can't use nil because of nil kNilSentinel conversions!) lua_pop(L_, 1); // L_: linda slot lua_pushinteger(L_, -1); // L_: linda slot nil } Keeper* const _keeper{ _linda->whichKeeper() }; _pushed = keeper_call(_keeper->K, KEEPER_API(limit), L_, _linda, StackIndex{ 2 }); - LUA_ASSERT(L_, _pushed.has_value() && (_pushed.value() == 2) && luaG_type(L_, kIdxTop) == LuaType::STRING); + LUA_ASSERT(L_, _pushed.has_value() && (_pushed.value() == 2) && luaW_type(L_, kIdxTop) == LuaType::STRING); if (_nargs == 3) { // 3 args: setting the limit // changing the limit: no error, boolean value saying if we should wake blocked writer threads - LUA_ASSERT(L_, luaG_type(L_, StackIndex{ -2 }) == LuaType::BOOLEAN); // L_: bool string + LUA_ASSERT(L_, luaW_type(L_, StackIndex{ -2 }) == LuaType::BOOLEAN); // L_: bool string if (lua_toboolean(L_, -2)) { _linda->readHappened.notify_all(); // To be done from within the 'K' locking area } } else { // 2 args: reading the limit // reading the limit: a number >=0 or "unlimited" - LUA_ASSERT(L_, luaG_type(L_, StackIndex{ -2 }) == LuaType::NUMBER || luaG_tostring(L_, StackIndex{ -2 }) == "unlimited"); + LUA_ASSERT(L_, luaW_type(L_, StackIndex{ -2 }) == LuaType::NUMBER || luaW_tostring(L_, StackIndex{ -2 }) == "unlimited"); } } else { // linda is cancelled // do nothing and return nil,lanes.cancel_error @@ -849,7 +849,7 @@ LUAG_FUNC(linda_restrict) int const _nargs{ lua_gettop(L_) }; luaL_argcheck(L_, _nargs == 2 || _nargs == 3, 2, "wrong number of arguments"); // make sure we got a known restrict mode, (or nothing) - std::string_view const _mode{ luaG_tostring(L_, StackIndex{ 3 }) }; + std::string_view const _mode{ luaW_tostring(L_, StackIndex{ 3 }) }; if (!_mode.empty() && (_mode != "none" && _mode != "set/get" && _mode != "send/receive")) { raise_luaL_argerror(L_, StackIndex{ 3 }, "unknown restrict mode"); } @@ -861,7 +861,7 @@ LUAG_FUNC(linda_restrict) Keeper* const _keeper{ _linda->whichKeeper() }; _pushed = keeper_call(_keeper->K, KEEPER_API(restrict), L_, _linda, StackIndex{ 2 }); // we should get a single return value: the string describing the previous restrict mode - LUA_ASSERT(L_, _pushed.has_value() && (_pushed.value() == 1) && luaG_type(L_, kIdxTop) == LuaType::STRING); + LUA_ASSERT(L_, _pushed.has_value() && (_pushed.value() == 1) && luaW_type(L_, kIdxTop) == LuaType::STRING); } else { // linda is cancelled // do nothing and return nil,lanes.cancel_error lua_pushnil(L_); @@ -981,7 +981,7 @@ LUAG_FUNC(linda_send) } else { // not enough room in the Linda slot to fulfill the request, return nil, "timeout" lua_pushnil(L_); - luaG_pushstring(L_, "timeout"); + luaW_pushstring(L_, "timeout"); return 2; } } @@ -1016,7 +1016,7 @@ LUAG_FUNC(linda_set) if (kRestrictedChannel.equals(L_, kIdxTop)) { raise_luaL_error(L_, "Key is restricted"); } - LUA_ASSERT(L_, _pushed.value() == 2 && luaG_type(L_, kIdxTop) == LuaType::STRING && luaG_type(L_, StackIndex{ -2 }) == LuaType::BOOLEAN); + LUA_ASSERT(L_, _pushed.value() == 2 && luaW_type(L_, kIdxTop) == LuaType::STRING && luaW_type(L_, StackIndex{ -2 }) == LuaType::BOOLEAN); if (_has_data) { // we put some data in the slot, tell readers that they should wake @@ -1078,7 +1078,7 @@ LUAG_FUNC(linda_towatch) LUAG_FUNC(linda_wake) { Linda* const _linda{ ToLinda(L_, StackIndex{ 1 }) }; - std::string_view const _who{ luaG_optstring(L_, StackIndex{ 2 }, "both") }; + std::string_view const _who{ luaW_optstring(L_, StackIndex{ 2 }, "both") }; // make sure we got 2 arguments: the linda and the wake targets luaL_argcheck(L_, lua_gettop(L_) <= 2, 2, "wrong number of arguments"); @@ -1154,8 +1154,8 @@ LUAG_FUNC(linda) if (lua_isnil(L_, kIdxTop)) { lua_pop(L_, 1); lua_pushnumber(L_, _U->lindaWakePeriod.count()); - } else if (luaG_type(L_, kIdxTop) == LuaType::STRING) { - if (luaG_tostring(L_, kIdxTop) != "never") { + } else if (luaW_type(L_, kIdxTop) == LuaType::STRING) { + if (luaW_tostring(L_, kIdxTop) != "never") { luaL_argerror(L_, 1, "invalid wake_period"); } else { lua_pop(L_, 1); @@ -1177,7 +1177,7 @@ LUAG_FUNC(linda) #if LUA_VERSION_NUM >= 504 // to-be-closed support starts with Lua 5.4 lua_getfield(L_, 1, "close_handler"); // L_: {} wake_period group close_handler - LuaType const _handlerType{ luaG_type(L_, kIdxTop) }; + LuaType const _handlerType{ luaW_type(L_, kIdxTop) }; if (_handlerType == LuaType::NIL) { lua_pop(L_, 1); // L_: {} wake_period group } else if (_handlerType == LuaType::USERDATA || _handlerType == LuaType::TABLE) { @@ -1188,7 +1188,7 @@ LUAG_FUNC(linda) } #endif // LUA_VERSION_NUM >= 504 - auto const _nameType{ luaG_getfield(L_, StackIndex{ 1 }, "name") }; // L_: {} wake_period group [close_handler] name + auto const _nameType{ luaW_getfield(L_, StackIndex{ 1 }, "name") }; // L_: {} wake_period group [close_handler] name luaL_argcheck(L_, _nameType == LuaType::NIL || _nameType == LuaType::STRING, 1, "name is not a string"); lua_replace(L_, 1); // L_: name wake_period group [close_handler] } diff --git a/src/lindafactory.cpp b/src/lindafactory.cpp index 4eab0c1..483037f 100644 --- a/src/lindafactory.cpp +++ b/src/lindafactory.cpp @@ -47,22 +47,22 @@ void LindaFactory::createMetatable(lua_State* L_) const lua_newtable(L_); // L_: mt // protect metatable from external access - luaG_pushstring(L_, kLindaMetatableName); // L_: mt "" + luaW_pushstring(L_, kLindaMetatableName); // L_: mt "" lua_setfield(L_, -2, "__metatable"); // L_: mt // the linda functions - luaG_registerlibfuncs(L_, mLindaMT); + luaW_registerlibfuncs(L_, mLindaMT); kNilSentinel.pushKey(L_); // L_: mt kNilSentinel lua_setfield(L_, -2, "null"); // L_: mt // if the metatable contains __index, leave it as is - if (luaG_getfield(L_, kIdxTop, kIndex) != LuaType::NIL) { // L_: mt __index + if (luaW_getfield(L_, kIdxTop, kIndex) != LuaType::NIL) { // L_: mt __index lua_pop(L_, 1); // L_: mt __index } else { // metatable is its own index lua_pushvalue(L_, kIdxTop); // L_: mt mt - luaG_setfield(L_, StackIndex{ -2 }, kIndex); // L_: mt + luaW_setfield(L_, StackIndex{ -2 }, kIndex); // L_: mt } STACK_CHECK(L_, 1); @@ -110,7 +110,7 @@ DeepPrelude* LindaFactory::newDeepObjectInternal(lua_State* const L_) const { STACK_CHECK_START_REL(L_, 0); // we always expect name, wake_period, group at the bottom of the stack (either can be nil). any extra stuff we ignore and keep unmodified - std::string_view _linda_name{ luaG_tostring(L_, StackIndex{ 1 }) }; + std::string_view _linda_name{ luaW_tostring(L_, StackIndex{ 1 }) }; auto const _wake_period{ static_cast(lua_tonumber(L_, 2)) }; LindaGroup const _linda_group{ static_cast(lua_tointeger(L_, 3)) }; @@ -119,12 +119,12 @@ DeepPrelude* LindaFactory::newDeepObjectInternal(lua_State* const L_) const lua_Debug _ar; if (lua_getstack(L_, 1, &_ar) == 1) { // 1 because we want the name of the function that called lanes.linda (where we currently are) lua_getinfo(L_, "Sln", &_ar); - _linda_name = luaG_pushstring(L_, "%s:%d", _ar.short_src, _ar.currentline); + _linda_name = luaW_pushstring(L_, "%s:%d", _ar.short_src, _ar.currentline); } else { - _linda_name = luaG_pushstring(L_, ""); + _linda_name = luaW_pushstring(L_, ""); } // since the name is not empty, it is at slot 1, and we can replace "auto" with the result, just in case - LUA_ASSERT(L_, luaG_tostring(L_, StackIndex{ 1 }) == "auto"); + LUA_ASSERT(L_, luaW_tostring(L_, StackIndex{ 1 }) == "auto"); lua_replace(L_, 1); } diff --git a/src/nameof.cpp b/src/nameof.cpp index f236f73..992569b 100644 --- a/src/nameof.cpp +++ b/src/nameof.cpp @@ -52,25 +52,25 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_ static constexpr auto _pushNameOnFQN = [](lua_State* const L_) { STACK_CHECK_START_REL(L_, 0); lua_pushvalue(L_, -2); // L_: o "r" {c} {fqn} ... k v k - auto const _keyType{ luaG_type(L_, kIdxTop) }; + auto const _keyType{ luaW_type(L_, kIdxTop) }; if (_keyType != LuaType::STRING) { lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... k v - luaG_pushstring(L_, "<%s>", luaG_typename(L_, _keyType).data()); // L_: o "r" {c} {fqn} ... k v "" + luaW_pushstring(L_, "<%s>", luaW_typename(L_, _keyType).data()); // L_: o "r" {c} {fqn} ... k v "" } else { // decorate the key string with something that tells us the type of the value - switch (luaG_type(L_, StackIndex{ -2 })) { + switch (luaW_type(L_, StackIndex{ -2 })) { default: LUA_ASSERT(L_, false); // there is something wrong if we end up here - luaG_pushstring(L_, "??"); // L_: o "r" {c} {fqn} ... k v "k" "??" + luaW_pushstring(L_, "??"); // L_: o "r" {c} {fqn} ... k v "k" "??" break; case LuaType::FUNCTION: - luaG_pushstring(L_, "()"); // L_: o "r" {c} {fqn} ... k v "k" "()" + luaW_pushstring(L_, "()"); // L_: o "r" {c} {fqn} ... k v "k" "()" break; case LuaType::TABLE: - luaG_pushstring(L_, "[]"); // L_: o "r" {c} {fqn} ... k v "k" "[]" + luaW_pushstring(L_, "[]"); // L_: o "r" {c} {fqn} ... k v "k" "[]" break; case LuaType::USERDATA: - luaG_pushstring(L_, "<>"); // L_: o "r" {c} {fqn} ... k v "k" "<>" + luaW_pushstring(L_, "<>"); // L_: o "r" {c} {fqn} ... k v "k" "<>" break; } lua_concat(L_, 2); // L_: o "r" {c} {fqn} ... k v "k??" @@ -92,7 +92,7 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_ static constexpr auto _recurseThenPop = [](lua_State* const L_, FqnLength const shortest_) -> FqnLength { STACK_CHECK_START_REL(L_, 0); // L_: o "r" {c} {fqn} ... <> FqnLength r_{ shortest_ }; - auto const _type{ luaG_type(L_, kIdxTop) }; + auto const _type{ luaW_type(L_, kIdxTop) }; if (_type == LuaType::TABLE || _type == LuaType::USERDATA || _type == LuaType::FUNCTION) { r_ = DiscoverObjectNameRecur(L_, shortest_); STACK_CHECK(L_, 0); @@ -113,7 +113,7 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_ STACK_CHECK_START_REL(L_, 0); // L_: o "r" {c} {fqn} ... k v // filter out uninteresting values - auto const _valType{ luaG_type(L_, kIdxTop) }; + auto const _valType{ luaW_type(L_, kIdxTop) }; if (_valType == LuaType::NIL || _valType == LuaType::BOOLEAN || _valType == LuaType::LIGHTUSERDATA || _valType == LuaType::NUMBER || _valType == LuaType::STRING) { lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... k return _r; @@ -177,7 +177,7 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_ UserValueIndex _uvi{ 0 }; while (lua_getiuservalue(L_, kIdxTop, ++_uvi) != LUA_TNONE) { // L_: o "r" {c} {fqn} ... U uv - luaG_pushstring(L_, "", _uvi); // L_: o "r" {c} {fqn} ... U uv name + luaW_pushstring(L_, "", _uvi); // L_: o "r" {c} {fqn} ... U uv name lua_insert(L_, -2); // L_: o "r" {c} {fqn} ... U name uv r_ = _processKeyValue(L_, r_); // L_: o "r" {c} {fqn} ... U name lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... U @@ -200,7 +200,7 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_ _upname = ""; } - luaG_pushstring(L_, "upvalue:%s", _upname); // L_: o "r" {c} {fqn} ... F up name + luaW_pushstring(L_, "upvalue:%s", _upname); // L_: o "r" {c} {fqn} ... F up name lua_insert(L_, -2); // L_: o "r" {c} {fqn} ... F name up r_ = _processKeyValue(L_, r_); // L_: o "r" {c} {fqn} ... F name lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... F @@ -213,7 +213,7 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_ STACK_GROW(L_, 2); STACK_CHECK_START_REL(L_, 0); // stack top contains the location to search in (table, function, userdata) - [[maybe_unused]] auto const _typeWhere{ luaG_type(L_, kIdxTop) }; + [[maybe_unused]] auto const _typeWhere{ luaW_type(L_, kIdxTop) }; LUA_ASSERT(L_, _typeWhere == LuaType::TABLE || _typeWhere == LuaType::USERDATA || _typeWhere == LuaType::FUNCTION); lua_pushvalue(L_, kIdxTop); // L_: o "r" {c} {fqn} ... <> <> lua_rawget(L_, kCache); // L_: o "r" {c} {fqn} ... <> nil/N @@ -263,12 +263,12 @@ LUAG_FUNC(nameof) // nil, boolean, light userdata, number and string aren't identifiable static constexpr auto _isIdentifiable = [](lua_State* const L_) { - auto const _valType{ luaG_type(L_, kIdxTop) }; + auto const _valType{ luaW_type(L_, kIdxTop) }; return _valType == LuaType::TABLE || _valType == LuaType::FUNCTION || _valType == LuaType::USERDATA || _valType == LuaType::THREAD; }; if (!_isIdentifiable(L_)) { - luaG_pushstring(L_, luaG_typename(L_, kIdxTop)); // L_: o "type" + luaW_pushstring(L_, luaW_typename(L_, kIdxTop)); // L_: o "type" lua_insert(L_, -2); // L_: "type" o return 2; } @@ -282,15 +282,15 @@ LUAG_FUNC(nameof) // push a table whose contents are strings that, when concatenated, produce unique name lua_newtable(L_); // L_: o nil {c} {fqn} // {fqn}[1] = "_G" - luaG_pushstring(L_, LUA_GNAME); // L_: o nil {c} {fqn} "_G" + luaW_pushstring(L_, LUA_GNAME); // L_: o nil {c} {fqn} "_G" lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} // this is where we start the search - luaG_pushglobaltable(L_); // L_: o nil {c} {fqn} _G + luaW_pushglobaltable(L_); // L_: o nil {c} {fqn} _G auto const _foundInG{ DiscoverObjectNameRecur(L_, FqnLength{ std::numeric_limits::max() }) }; if (lua_isnil(L_, 2)) { // try again with registry, just in case... LUA_ASSERT(L_, _foundInG == std::numeric_limits::max()); lua_pop(L_, 1); // L_: o nil {c} {fqn} - luaG_pushstring(L_, "_R"); // L_: o nil {c} {fqn} "_R" + luaW_pushstring(L_, "_R"); // L_: o nil {c} {fqn} "_R" lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} lua_pushvalue(L_, kIdxRegistry); // L_: o nil {c} {fqn} _R [[maybe_unused]] auto const _foundInR{ DiscoverObjectNameRecur(L_, FqnLength{ std::numeric_limits::max() }) }; diff --git a/src/state.cpp b/src/state.cpp index fc7f5ef..2f64194 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -166,7 +166,7 @@ namespace state { }; if (_L == nullptr) { - raise_luaL_error(from_, "luaG_newstate() failed while creating state; out of memory"); + raise_luaL_error(from_, "luaW_newstate() failed while creating state; out of memory"); } return _L; } @@ -202,11 +202,11 @@ namespace state { // neither libs (not even 'base') nor special init func: we are done if (!libs_.has_value() && std::holds_alternative(U_->onStateCreateFunc)) { - DEBUGSPEW_CODE(DebugSpew(U_) << "luaG_newstate(nullptr)" << std::endl); + DEBUGSPEW_CODE(DebugSpew(U_) << "luaW_newstate(nullptr)" << std::endl); return _L; } - DEBUGSPEW_CODE(DebugSpew(U_) << "luaG_newstate()" << std::endl); + DEBUGSPEW_CODE(DebugSpew(U_) << "luaW_newstate()" << std::endl); DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U_ }); // copy settings (for example because it may contain a Lua on_state_create function) @@ -239,7 +239,7 @@ namespace state { lua_pop(_L, 1); } else { lua_pushcfunction(_L, luaopen_base); - luaG_pushstring(_L, ""); + luaW_pushstring(_L, ""); lua_call(_L, 1, 0); } } @@ -274,7 +274,7 @@ namespace state { STACK_CHECK(_L, 0); // after all this, register everything we find in our name<->function database - luaG_pushglobaltable(_L); // L: _G + luaW_pushglobaltable(_L); // L: _G tools::PopulateFuncLookupTable(_L, kIdxTop, {}); lua_pop(_L, 1); // L: STACK_CHECK(_L, 0); @@ -286,19 +286,19 @@ namespace state { kLookupRegKey.pushValue(_L); // L: {} lua_pushnil(_L); // L: {} nil while (lua_next(_L, -2)) { // L: {} k v - luaG_pushstring(_L, "["); // L: {} k v "[" + luaW_pushstring(_L, "["); // L: {} k v "[" lua_getglobal(_L, "tostring"); // L: {} k v "[" tostring lua_pushvalue(_L, -4); // L: {} k v "[" tostring k lua_call(_L, 1, 1); // L: {} k v "[" 'k' - luaG_pushstring(_L, "] = "); // L: {} k v "[" 'k' "] = " + luaW_pushstring(_L, "] = "); // L: {} k v "[" 'k' "] = " lua_getglobal(_L, "tostring"); // L: {} k v "[" 'k' "] = " tostring lua_pushvalue(_L, -5); // L: {} k v "[" 'k' "] = " tostring v lua_call(_L, 1, 1); // L: {} k v "[" 'k' "] = " 'v' lua_concat(_L, 4); // L: {} k v "[k] = v" - DEBUGSPEW_CODE(DebugSpew(U_) << luaG_tostring(_L, kIdxTop) << std::endl); + DEBUGSPEW_CODE(DebugSpew(U_) << luaW_tostring(_L, kIdxTop) << std::endl); lua_pop(_L, 2); // L: {} k } // lua_next() // L: {} lua_pop(_L, 1); // L: @@ -317,7 +317,7 @@ namespace state { lua_newtable(L_); // L_: out for (luaL_Reg const& _entry : local::sLibs) { lua_pushboolean(L_, 1); // L_: out true - luaG_setfield(L_, StackIndex{ -2 }, std::string_view{ _entry.name }); // out[name] = true // L_: out + luaW_setfield(L_, StackIndex{ -2 }, std::string_view{ _entry.name }); // out[name] = true // L_: out } STACK_CHECK(L_, 1); return 1; diff --git a/src/threading.cpp b/src/threading.cpp index efca7eb..4b27bed 100644 --- a/src/threading.cpp +++ b/src/threading.cpp @@ -109,11 +109,11 @@ void Win32Invoke(lua_State* const L_, std::string_view const& where_, F& f_, ARG std::string_view const _funcname{ StripFuncName(where_) }; #if defined(PLATFORM_XBOX) - luaG_pushstring(L_, "%s() failed with code %d", _funcname.data(), _rc); + luaW_pushstring(L_, "%s() failed with code %d", _funcname.data(), _rc); #else // PLATFORM_XBOX char _buf[256]; FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, _rc, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), _buf, 256, nullptr); - luaG_pushstring(L_, "%s() failed with code %d '%s'", _funcname.data(), _rc, _buf); + luaW_pushstring(L_, "%s() failed with code %d '%s'", _funcname.data(), _rc, _buf); #endif // PLATFORM_XBOX raise_lua_error(L_); } diff --git a/src/tools.cpp b/src/tools.cpp index cbfefb0..25949e4 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -63,26 +63,26 @@ static int dummy_writer([[maybe_unused]] lua_State* const L_, [[maybe_unused]] v * +-----------------+-------------------+------------+----------+ * | lua_tocfunction | nullptr | | nullptr | * +-----------------+-------------------+------------+----------+ - * | luaG_dump | kWriterReturnCode | 1 | 1 | + * | luaW_dump | kWriterReturnCode | 1 | 1 | * +-----------------+-------------------+------------+----------+ */ [[nodiscard]] -FuncSubType luaG_getfuncsubtype(lua_State* const L_, StackIndex const i_) +FuncSubType luaW_getfuncsubtype(lua_State* const L_, StackIndex const i_) { if (lua_tocfunction(L_, i_)) { // nullptr for LuaJIT-fast && bytecode functions return FuncSubType::Native; } - // luaG_dump expects the function at the top of the stack - int const _popCount{ (luaG_absindex(L_, i_) == lua_gettop(L_)) ? 0 : (lua_pushvalue(L_, i_), 1) }; + // luaW_dump expects the function at the top of the stack + int const _popCount{ (luaW_absindex(L_, i_) == lua_gettop(L_)) ? 0 : (lua_pushvalue(L_, i_), 1) }; // here we either have a Lua bytecode or a LuaJIT-compiled function - int const _dumpres{ luaG_dump(L_, dummy_writer, nullptr, 0) }; + int const _dumpres{ luaW_dump(L_, dummy_writer, nullptr, 0) }; if (_popCount > 0) { lua_pop(L_, _popCount); } if (_dumpres == kWriterReturnCode) { - // anytime we get kWriterReturnCode, this means that luaG_dump() attempted a dump + // anytime we get kWriterReturnCode, this means that luaW_dump() attempted a dump return FuncSubType::Bytecode; } // we didn't try to dump, therefore this is a LuaJIT-fast function @@ -115,7 +115,7 @@ namespace tools { // &b is popped at that point (-> replaced by the result) luaL_pushresult(&_b); // L_: ... {} ... "" STACK_CHECK(L_, 1); - return luaG_tostring(L_, kIdxTop); + return luaW_tostring(L_, kIdxTop); } } // namespace tools @@ -145,10 +145,10 @@ static void update_lookup_entry(lua_State* const L_, StackIndex const ctxBase_, // first, raise an error if the function is already known lua_pushvalue(L_, -1); // L_: ... {bfc} k o o lua_rawget(L_, _dest); // L_: ... {bfc} k o name? - std::string_view const _prevName{ luaG_tostring(L_, kIdxTop) }; // nullptr if we got nil (first encounter of this object) + std::string_view const _prevName{ luaW_tostring(L_, kIdxTop) }; // nullptr if we got nil (first encounter of this object) // push name in fqn stack (note that concatenation will crash if name is a not string or a number) lua_pushvalue(L_, -3); // L_: ... {bfc} k o name? k - LUA_ASSERT(L_, luaG_type(L_, kIdxTop) == LuaType::NUMBER || luaG_type(L_, kIdxTop) == LuaType::STRING); + LUA_ASSERT(L_, luaW_type(L_, kIdxTop) == LuaType::NUMBER || luaW_type(L_, kIdxTop) == LuaType::STRING); TableIndex const _deeper{ depth_ + 1 }; lua_rawseti(L_, _fqn, _deeper); // L_: ... {bfc} k o name? // generate name @@ -161,7 +161,7 @@ static void update_lookup_entry(lua_State* const L_, StackIndex const ctxBase_, // Therefore, when we encounter an object for which a name was previously registered, we need to select a single name // based on some sorting order so that we end up with the same name in all databases whatever order the table walk yielded if (!_prevName.empty() && ((_prevName.size() < _newName.size()) || (_prevName <= _newName))) { - DEBUGSPEW_CODE(DebugSpew(_U) << luaG_typename(L_, StackIndex{ -3 }) << " '" << _newName << "' remains named '" << _prevName << "'" << std::endl); + DEBUGSPEW_CODE(DebugSpew(_U) << luaW_typename(L_, StackIndex{ -3 }) << " '" << _newName << "' remains named '" << _prevName << "'" << std::endl); // the previous name is 'smaller' than the one we just generated: keep it! lua_pop(L_, 3); // L_: ... {bfc} k } else { @@ -175,7 +175,7 @@ static void update_lookup_entry(lua_State* const L_, StackIndex const ctxBase_, } else { lua_remove(L_, -2); // L_: ... {bfc} k o "f.q.n" } - DEBUGSPEW_CODE(DebugSpew(_U) << luaG_typename(L_, StackIndex{ -2 }) << " '" << _newName << "'" << std::endl); + DEBUGSPEW_CODE(DebugSpew(_U) << luaW_typename(L_, StackIndex{ -2 }) << " '" << _newName << "'" << std::endl); // prepare the stack for database feed lua_pushvalue(L_, -1); // L_: ... {bfc} k o "f.q.n" "f.q.n" lua_pushvalue(L_, -3); // L_: ... {bfc} k o "f.q.n" "f.q.n" o @@ -210,7 +210,7 @@ static void populate_lookup_table_recur(lua_State* const L_, StackIndex const db STACK_CHECK_START_REL(L_, 0); // L_: ... {i_} // if object is a userdata, replace it by its metatable - if (luaG_type(L_, i_) == LuaType::USERDATA) { + if (luaW_type(L_, i_) == LuaType::USERDATA) { lua_getmetatable(L_, i_); // L_: ... {i_} mt lua_replace(L_, i_); // L_: ... {i_} } @@ -239,7 +239,7 @@ static void populate_lookup_table_recur(lua_State* const L_, StackIndex const db lua_pushnil(L_); // L_: ... {i_} {bfc} nil while (lua_next(L_, i_) != 0) { // L_: ... {i_} {bfc} k v // just for debug, not actually needed - // std::string_view const _key{ (luaG_type(L_, -2) == LuaType::STRING) ? luaG_tostring(L_, -2) : "not a string" }; + // std::string_view const _key{ (luaW_type(L_, -2) == LuaType::STRING) ? luaW_tostring(L_, -2) : "not a string" }; // subtable: process it recursively if (lua_istable(L_, kIdxTop)) { // L_: ... {i_} {bfc} k {} // increment visit count to make sure we will actually scan it at this recursive level @@ -256,11 +256,11 @@ static void populate_lookup_table_recur(lua_State* const L_, StackIndex const db lua_rawset(L_, _breadthFirstCache); // L_: ... {i_} {bfc} k {} // generate a name, and if we already had one name, keep whichever is the shorter update_lookup_entry(L_, dbIdx_, depth_); // L_: ... {i_} {bfc} k - } else if (lua_isfunction(L_, kIdxTop) && (luaG_getfuncsubtype(L_, kIdxTop) != FuncSubType::Bytecode)) { + } else if (lua_isfunction(L_, kIdxTop) && (luaW_getfuncsubtype(L_, kIdxTop) != FuncSubType::Bytecode)) { // generate a name, and if we already had one name, keep whichever is the shorter // this pops the function from the stack update_lookup_entry(L_, dbIdx_, depth_); // L_: ... {i_} {bfc} k - } else if (luaG_type(L_, kIdxTop) == LuaType::USERDATA) { + } else if (luaW_type(L_, kIdxTop) == LuaType::USERDATA) { // generate a name, and if we already had one name, keep whichever is the shorter // this pops the userdata from the stack update_lookup_entry(L_, dbIdx_, depth_); // L_: ... {i_} {bfc} k @@ -273,13 +273,13 @@ static void populate_lookup_table_recur(lua_State* const L_, StackIndex const db TableIndex const _deeper{ depth_ + 1 }; lua_pushnil(L_); // L_: ... {i_} {bfc} nil while (lua_next(L_, _breadthFirstCache) != 0) { // L_: ... {i_} {bfc} k {} - DEBUGSPEW_CODE(std::string_view const _key{ (luaG_type(L_, StackIndex{ -2 }) == LuaType::STRING) ? luaG_tostring(L_, StackIndex{ -2 }) : std::string_view{ "" } }); + DEBUGSPEW_CODE(std::string_view const _key{ (luaW_type(L_, StackIndex{ -2 }) == LuaType::STRING) ? luaW_tostring(L_, StackIndex{ -2 }) : std::string_view{ "" } }); DEBUGSPEW_CODE(DebugSpew(_U) << "table '"<< _key <<"'" << std::endl); DEBUGSPEW_CODE(DebugSpewIndentScope _scope2{ _U }); // un-visit this table in case we do need to process it lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} lua_rawget(L_, _cache); // L_: ... {i_} {bfc} k {} n - LUA_ASSERT(L_, luaG_type(L_, kIdxTop) == LuaType::NUMBER); + LUA_ASSERT(L_, luaW_type(L_, kIdxTop) == LuaType::NUMBER); _visit_count = lua_tointeger(L_, -1) - 1; lua_pop(L_, 1); // L_: ... {i_} {bfc} k {} lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} @@ -312,7 +312,7 @@ namespace tools { // create a "fully.qualified.name" <-> function equivalence database void PopulateFuncLookupTable(lua_State* const L_, StackIndex const i_, std::string_view const& name_) { - StackIndex const _in_base{ luaG_absindex(L_, i_) }; + StackIndex const _in_base{ luaW_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); @@ -323,24 +323,24 @@ namespace tools { StackIndex const _dbIdx{ lua_gettop(L_) }; STACK_CHECK(L_, 1); LUA_ASSERT(L_, lua_istable(L_, -1)); - LuaType const _moduleType{ luaG_type(L_, _in_base) }; + LuaType const _moduleType{ luaW_type(L_, _in_base) }; if ((_moduleType == LuaType::FUNCTION) || (_moduleType == LuaType::USERDATA)) { // for example when a module is a simple function if (_name.empty()) { _name = "nullptr"; } lua_pushvalue(L_, _in_base); // L_: {} f - luaG_pushstring(L_, _name); // L_: {} f name_ + luaW_pushstring(L_, _name); // L_: {} f name_ lua_rawset(L_, -3); // L_: {} - luaG_pushstring(L_, _name); // L_: {} name_ + luaW_pushstring(L_, _name); // L_: {} name_ lua_pushvalue(L_, _in_base); // L_: {} name_ f lua_rawset(L_, -3); // L_: {} lua_pop(L_, 1); // L_: - } else if (luaG_type(L_, _in_base) == LuaType::TABLE) { + } else if (luaW_type(L_, _in_base) == LuaType::TABLE) { lua_newtable(L_); // L_: {} {fqn} TableIndex _startDepth{ 0 }; if (!_name.empty()) { STACK_CHECK(L_, 2); - luaG_pushstring(L_, _name); // L_: {} {fqn} "name" + luaW_pushstring(L_, _name); // L_: {} {fqn} "name" // generate a name, and if we already had one name, keep whichever is the shorter lua_pushvalue(L_, _in_base); // L_: {} {fqn} "name" t update_lookup_entry(L_, _dbIdx, _startDepth); // L_: {} {fqn} "name" @@ -355,7 +355,7 @@ namespace tools { lua_pop(L_, 3); // L_: } else { lua_pop(L_, 1); // L_: - raise_luaL_error(L_, "unsupported module type %s", luaG_typename(L_, _in_base).data()); + raise_luaL_error(L_, "unsupported module type %s", luaW_typename(L_, _in_base).data()); } STACK_CHECK(L_, 0); } @@ -373,7 +373,7 @@ namespace tools { +[](lua_State* L_) { int const _args{ lua_gettop(L_) }; // L_: args... - //[[maybe_unused]] std::string_view const _modname{ luaG_checkstring(L_, 1) }; + //[[maybe_unused]] std::string_view const _modname{ luaW_checkstring(L_, 1) }; STACK_GROW(L_, 1); diff --git a/src/tools.hpp b/src/tools.hpp index 420b5f8..14f9855 100644 --- a/src/tools.hpp +++ b/src/tools.hpp @@ -21,7 +21,7 @@ enum class [[nodiscard]] FuncSubType }; [[nodiscard]] -FuncSubType luaG_getfuncsubtype(lua_State* L_, StackIndex i_); +FuncSubType luaW_getfuncsubtype(lua_State* L_, StackIndex i_); // ################################################################################################# diff --git a/src/tracker.cpp b/src/tracker.cpp index 8b06522..34866dd 100644 --- a/src/tracker.cpp +++ b/src/tracker.cpp @@ -96,7 +96,7 @@ int LaneTracker::pushThreadsTable(lua_State* L_) const while (_lane != TRACKING_END) { // insert a { name='', status='' } tuple, so that several lanes with the same name can't clobber each other lua_createtable(L_, 0, 2); // L_: {} {} - luaG_pushstring(L_, _lane->getDebugName()); // L_: {} {} "name" + luaW_pushstring(L_, _lane->getDebugName()); // L_: {} {} "name" lua_setfield(L_, -2, "name"); // L_: {} {} _lane->pushStatusString(L_); // L_: {} {} "" lua_setfield(L_, -2, "status"); // L_: {} {} diff --git a/src/uniquekey.hpp b/src/uniquekey.hpp index 4c9eb58..ace21c4 100644 --- a/src/uniquekey.hpp +++ b/src/uniquekey.hpp @@ -80,7 +80,7 @@ class RegistryUniqueKey final STACK_GROW(L_, 1); STACK_CHECK_START_REL(L_, 0); pushValue(L_); // L_: ... {}|nil - T* const value{ luaG_tolightuserdata(L_, kIdxTop) }; + T* const value{ luaW_tolightuserdata(L_, kIdxTop) }; lua_pop(L_, 1); // L_: ... STACK_CHECK(L_, 0); return value; @@ -125,8 +125,8 @@ class RegistryUniqueKey final if (!mode_.empty()) { STACK_GROW(L_, 3); lua_createtable(L_, 0, 1); // L_: {} mt - luaG_pushstring(L_, "__mode"); // L_: {} mt "__mode" - luaG_pushstring(L_, mode_); // L_: {} mt "__mode" mode + luaW_pushstring(L_, "__mode"); // L_: {} mt "__mode" + luaW_pushstring(L_, mode_); // L_: {} mt "__mode" mode lua_rawset(L_, -3); // L_: {} mt lua_setmetatable(L_, -2); // L_: {} } diff --git a/src/universe.cpp b/src/universe.cpp index 3255c7f..044c841 100644 --- a/src/universe.cpp +++ b/src/universe.cpp @@ -111,18 +111,18 @@ void Universe::callOnStateCreate(lua_State* const L_, lua_State* const from_, Lo } kConfigRegKey.pushValue(L_); // L_: config STACK_CHECK(L_, 1); - LuaType const _funcType{ luaG_getfield(L_, kIdxTop, kOnStateCreate) }; // L_: config on_state_create() + LuaType const _funcType{ luaW_getfield(L_, kIdxTop, kOnStateCreate) }; // L_: config on_state_create() if (_funcType != LuaType::FUNCTION) { - raise_luaL_error(L_, "INTERNAL ERROR: %s is a %s, not a function", kOnStateCreate.data(), luaG_typename(L_, _funcType).data()); + raise_luaL_error(L_, "INTERNAL ERROR: %s is a %s, not a function", kOnStateCreate.data(), luaW_typename(L_, _funcType).data()); } lua_remove(L_, -2); // L_: on_state_create() } STACK_CHECK(L_, 1); // capture error and raise it in caller state std::string_view const _stateType{ mode_ == LookupMode::LaneBody ? "lane" : "keeper" }; - luaG_pushstring(L_, _stateType); // L_: on_state_create() "" + luaW_pushstring(L_, _stateType); // L_: on_state_create() "" if (lua_pcall(L_, 1, 0, 0) != LUA_OK) { - raise_luaL_error(from_, "%s failed in %s: \"%s\"", kOnStateCreate.data(), _stateType.data(), lua_isstring(L_, -1) ? luaG_tostring(L_, kIdxTop).data() : luaG_typename(L_, kIdxTop).data()); + raise_luaL_error(from_, "%s failed in %s: \"%s\"", kOnStateCreate.data(), _stateType.data(), lua_isstring(L_, -1) ? luaW_tostring(L_, kIdxTop).data() : luaW_typename(L_, kIdxTop).data()); } STACK_CHECK(L_, 0); } @@ -137,14 +137,14 @@ Universe* Universe::Create(lua_State* const L_) static constexpr StackIndex kIdxSettings{ 1 }; LUA_ASSERT(L_, lua_gettop(L_) == 1 && lua_istable(L_, 1)); STACK_CHECK_START_REL(L_, 0); // L_: settings - std::ignore = luaG_getfield(L_, kIdxSettings, "nb_user_keepers"); // L_: settings nb_user_keepers + std::ignore = luaW_getfield(L_, kIdxSettings, "nb_user_keepers"); // L_: settings nb_user_keepers int const _nbUserKeepers{ static_cast(lua_tointeger(L_, -1)) + 1}; lua_pop(L_, 1); // L_: settings if (_nbUserKeepers < 1) { raise_luaL_error(L_, "Bad number of additional keepers (%d)", _nbUserKeepers); } STACK_CHECK(L_, 0); - std::ignore = luaG_getfield(L_, kIdxSettings, "keepers_gc_threshold"); // L_: settings keepers_gc_threshold + std::ignore = luaW_getfield(L_, kIdxSettings, "keepers_gc_threshold"); // L_: settings keepers_gc_threshold int const _keepers_gc_threshold{ static_cast(lua_tointeger(L_, -1)) }; lua_pop(L_, 1); // L_: settings STACK_CHECK(L_, 0); @@ -157,30 +157,30 @@ Universe* Universe::Create(lua_State* const L_) DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); lua_createtable(L_, 0, 1); // L_: settings universe {mt} - std::ignore = luaG_getfield(L_, kIdxSettings, "shutdown_timeout"); // L_: settings universe {mt} shutdown_timeout + std::ignore = luaW_getfield(L_, kIdxSettings, "shutdown_timeout"); // L_: settings universe {mt} shutdown_timeout lua_pushcclosure(L_, UniverseGC, 1); // L_: settings universe {mt} UniverseGC lua_setfield(L_, -2, "__gc"); // L_: settings universe {mt} lua_setmetatable(L_, -2); // L_: settings universe lua_pop(L_, 1); // L_: settings - std::ignore = luaG_getfield(L_, kIdxSettings, "linda_wake_period"); // L_: settings linda_wake_period - if (luaG_type(L_, kIdxTop) == LuaType::NUMBER) { + std::ignore = luaW_getfield(L_, kIdxSettings, "linda_wake_period"); // L_: settings linda_wake_period + if (luaW_type(L_, kIdxTop) == LuaType::NUMBER) { _U->lindaWakePeriod = lua_Duration{ lua_tonumber(L_, kIdxTop) }; } else { - LUA_ASSERT(L_, luaG_tostring(L_, kIdxTop) == "never"); + LUA_ASSERT(L_, luaW_tostring(L_, kIdxTop) == "never"); } lua_pop(L_, 1); // L_: settings - std::ignore = luaG_getfield(L_, kIdxSettings, "strip_functions"); // L_: settings strip_functions + std::ignore = luaW_getfield(L_, kIdxSettings, "strip_functions"); // L_: settings strip_functions _U->stripFunctions = lua_toboolean(L_, -1) ? true : false; lua_pop(L_, 1); // L_: settings - std::ignore = luaG_getfield(L_, kIdxSettings, "verbose_errors"); // L_: settings verbose_errors + std::ignore = luaW_getfield(L_, kIdxSettings, "verbose_errors"); // L_: settings verbose_errors _U->verboseErrors = lua_toboolean(L_, -1) ? true : false; lua_pop(L_, 1); // L_: settings // tracking - std::ignore = luaG_getfield(L_, kIdxSettings, "track_lanes"); // L_: settings track_lanes + std::ignore = luaW_getfield(L_, kIdxSettings, "track_lanes"); // L_: settings track_lanes if (lua_toboolean(L_, -1)) { _U->tracker.activate(); } @@ -217,7 +217,7 @@ static void* libc_lua_Alloc([[maybe_unused]] void* const ud_, [[maybe_unused]] v // ################################################################################################# [[nodiscard]] -static int luaG_provide_protected_allocator(lua_State* const L_) +static int luaW_provide_protected_allocator(lua_State* const L_) { Universe* const _U{ Universe::Get(L_) }; // push a new full userdata on the stack, giving access to the universe's protected allocator @@ -245,17 +245,17 @@ void Universe::initializeAllocatorFunction(lua_State* const L_) // start by just grabbing whatever allocator was provided to the master state protectedAllocator.initFrom(L_); STACK_CHECK_START_REL(L_, 1); // L_: settings - switch (luaG_getfield(L_, kIdxTop, "allocator")) { // L_: settings allocator|nil|"protected" + switch (luaW_getfield(L_, kIdxTop, "allocator")) { // L_: settings allocator|nil|"protected" case LuaType::NIL: // nothing else to do break; case LuaType::STRING: - LUA_ASSERT(L_, luaG_tostring(L_, kIdxTop) == "protected"); + LUA_ASSERT(L_, luaW_tostring(L_, kIdxTop) == "protected"); // set the original allocator to call from inside protection by the mutex protectedAllocator.installIn(L_); // before a state is created, this function will be called to obtain the allocator - provideAllocator = luaG_provide_protected_allocator; + provideAllocator = luaW_provide_protected_allocator; break; case LuaType::FUNCTION: @@ -276,14 +276,14 @@ void Universe::initializeAllocatorFunction(lua_State* const L_) break; default: // should be filtered out in lanes.lua - raise_luaL_error(L_, "Bad config.allocator type %s", luaG_typename(L_, kIdxTop).data()); + raise_luaL_error(L_, "Bad config.allocator type %s", luaW_typename(L_, kIdxTop).data()); } lua_pop(L_, 1); // L_: settings STACK_CHECK(L_, 1); - std::ignore = luaG_getfield(L_, kIdxTop, "internal_allocator"); // L_: settings "libc"|"allocator" + std::ignore = luaW_getfield(L_, kIdxTop, "internal_allocator"); // L_: settings "libc"|"allocator" LUA_ASSERT(L_, lua_isstring(L_, kIdxTop)); // should be the case due to lanes.lua parameter validation - std::string_view const _allocator{ luaG_tostring(L_, kIdxTop) }; + std::string_view const _allocator{ luaW_tostring(L_, kIdxTop) }; // use whatever the provider provides. This performs validation of what provideAllocator is giving // we do this even if _allocator == "libc", to have the validation part internalAllocator = resolveAndValidateAllocator(L_, "internal"); @@ -305,7 +305,7 @@ int Universe::InitializeFinalizer(lua_State* const L_) // make sure we are only called from the Master Lua State! kUniverseFullRegKey.pushValue(L_); // L_: f U - if (luaG_type(L_, kIdxTop) != LuaType::USERDATA) { + if (luaW_type(L_, kIdxTop) != LuaType::USERDATA) { raise_luaL_error(L_, "lanes.%s called from inside a lane", kFinally); } lua_pop(L_, 1); // L_: f @@ -321,8 +321,8 @@ int Universe::InitializeFinalizer(lua_State* const L_) void Universe::initializeOnStateCreate(lua_State* const L_) { STACK_CHECK_START_REL(L_, 0); // L_: settings - if (luaG_getfield(L_, kIdxTop, kOnStateCreate) != LuaType::NIL) { // L_: settings on_state_create|nil - LUA_ASSERT(L_, luaG_type(L_, kIdxTop) == LuaType::FUNCTION); // ensured by lanes.lua parameter validation + if (luaW_getfield(L_, kIdxTop, kOnStateCreate) != LuaType::NIL) { // L_: settings on_state_create|nil + LUA_ASSERT(L_, luaW_type(L_, kIdxTop) == LuaType::FUNCTION); // ensured by lanes.lua parameter validation // store C function pointer in an internal variable lua_CFunction const _func{ lua_tocfunction(L_, -1) }; // L_: settings on_state_create if (_func) { @@ -335,7 +335,7 @@ void Universe::initializeOnStateCreate(lua_State* const L_) // remove this C function from the config table so that it doesn't cause problems // when we transfer the config table in newly created Lua states lua_pushnil(L_); // L_: settings on_state_create nil - luaG_setfield(L_, StackIndex{ -3 }, kOnStateCreate); // L_: settings on_state_create + luaW_setfield(L_, StackIndex{ -3 }, kOnStateCreate); // L_: settings on_state_create } else { // the function is still in the config table. we indicate this with the uintptr_t alternative (actual value is irrelevant) onStateCreateFunc.emplace(std::bit_cast(kOnStateCreate.data())); @@ -358,7 +358,7 @@ lanes::AllocatorDefinition Universe::resolveAndValidateAllocator(lua_State* cons STACK_CHECK_START_REL(L_, 0); // here, we have a function we can call to obtain an allocator lua_pushcclosure(L_, provideAllocator, 0); // L_: provideAllocator() - luaG_pushstring(L_, hint_); // L_: provideAllocator() "" + luaW_pushstring(L_, hint_); // L_: provideAllocator() "" lua_call(L_, 1, 1); // L_: result // make sure we have a valid AllocatorDefinition on the stack (an error is raised instead if it is not the case) _ret = lanes::AllocatorDefinition::Validated(L_, kIdxTop); @@ -433,7 +433,7 @@ int Universe::UniverseGC(lua_State* const L_) { lua_Duration const _shutdown_timeout{ lua_tonumber(L_, lua_upvalueindex(1)) }; STACK_CHECK_START_ABS(L_, 1); - Universe* const _U{ luaG_tofulluserdata(L_, StackIndex{ 1 }) }; // L_: U + Universe* const _U{ luaW_tofulluserdata(L_, StackIndex{ 1 }) }; // L_: U // attempt to terminate all lanes with increasingly stronger cancel methods bool const _allLanesTerminated{ @@ -456,7 +456,7 @@ int Universe::UniverseGC(lua_State* const L_) if (lua_isnil(L_, kIdxTop)) { lua_pop(L_, 1); // L_: U // no finalizer, or it returned no value: push some default message on the stack, in case it is necessary - luaG_pushstring(L_, "uncooperative lanes detected at shutdown"); // L_: U "msg" + luaW_pushstring(L_, "uncooperative lanes detected at shutdown"); // L_: U "msg" } STACK_CHECK(L_, 2); @@ -466,7 +466,7 @@ int Universe::UniverseGC(lua_State* const L_) bool const _detectedUncooperativeLanes{ _U->selfdestructFirst != SELFDESTRUCT_END }; if (_detectedUncooperativeLanes) { _U->flagDanglingLanes(); - if (luaG_tostring(L_, kIdxTop) == "freeze") { + if (luaW_tostring(L_, kIdxTop) == "freeze") { std::this_thread::sleep_until(std::chrono::time_point::max()); } else { // take the value returned by the finalizer (or our default message) and throw it as an error diff --git a/src/universe.hpp b/src/universe.hpp index ab49f86..f781e92 100644 --- a/src/universe.hpp +++ b/src/universe.hpp @@ -128,7 +128,7 @@ class Universe final public: [[nodiscard]] - static void* operator new([[maybe_unused]] size_t const size_, lua_State* const L_) noexcept { return luaG_newuserdatauv(L_, UserValueCount{ 0 }); }; + static void* operator new([[maybe_unused]] size_t const size_, lua_State* const L_) noexcept { return luaW_newuserdatauv(L_, UserValueCount{ 0 }); }; // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception static void operator delete([[maybe_unused]] void* const p_, [[maybe_unused]] lua_State* const L_) {} // nothing to do, as nothing is allocated independently -- cgit v1.2.3-55-g6feb