From ee32d4281a5e59ce81d7f38f86a49fa8ff64d2c3 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Fri, 7 Jun 2024 11:46:25 +0200 Subject: Boyscouting some luaG_ functions --- src/cancel.cpp | 2 +- src/compat.h | 43 ++++++++++++++++++++++++++++++++++++++----- src/deep.cpp | 14 +++++++------- src/intercopycontext.cpp | 45 +++++++++++++++++++++++---------------------- src/keeper.cpp | 6 +++--- src/lane.cpp | 22 +++++++++++----------- src/lanes.cpp | 30 ++++++++++++++---------------- src/linda.cpp | 10 +++++----- src/lindafactory.cpp | 10 +++++----- src/macros_and_utils.h | 27 --------------------------- src/nameof.cpp | 2 +- src/state.cpp | 10 +++++----- src/tools.cpp | 16 ++++++++-------- src/tracker.cpp | 2 +- src/uniquekey.h | 2 +- src/universe.cpp | 10 +++++----- src/universe.h | 2 +- 17 files changed, 129 insertions(+), 124 deletions(-) diff --git a/src/cancel.cpp b/src/cancel.cpp index 8845e9d..4205d1f 100644 --- a/src/cancel.cpp +++ b/src/cancel.cpp @@ -186,7 +186,7 @@ CancelOp which_cancel_op(std::string_view const& opString_) [[nodiscard]] static CancelOp which_cancel_op(lua_State* L_, int idx_) { if (luaG_type(L_, idx_) == LuaType::STRING) { - std::string_view const _str{ luaG_tostringview(L_, idx_) }; + std::string_view const _str{ luaG_tostring(L_, idx_) }; CancelOp _op{ which_cancel_op(_str) }; lua_remove(L_, idx_); // argument is processed, remove it if (_op == CancelOp::Invalid) { diff --git a/src/compat.h b/src/compat.h index 24a105f..8963ef7 100644 --- a/src/compat.h +++ b/src/compat.h @@ -11,6 +11,8 @@ extern "C" } #endif // __cplusplus +#include "debug.h" + // try to detect if we are building against LuaJIT or MoonJIT #if defined(LUA_JITLIBNAME) #include "luajit.h" @@ -302,6 +304,14 @@ inline void luaG_newlib(lua_State* const L_, luaL_Reg const (&funcs_)[N]) // ------------------------------------------------------------------------------------------------- +template +[[nodiscard]] T* luaG_newuserdatauv(lua_State* L_, int nuvalue_) +{ + return static_cast(lua_newuserdatauv(L_, sizeof(T), nuvalue_)); +} + +// ------------------------------------------------------------------------------------------------- + inline void luaG_registerlibfuncs(lua_State* L_, luaL_Reg const funcs_[]) { Wrap::luaL_setfuncs(L_, funcs_, 0); @@ -314,27 +324,50 @@ inline void luaG_setmetatable(lua_State* const L_, std::string_view const& tname return Wrap::luaL_setmetatable(L_, tname_); } +// ------------------------------------------------------------------------------------------------- + +// a small helper to extract a full userdata pointer from the stack in a safe way +template +[[nodiscard]] T* luaG_tofulluserdata(lua_State* L_, int index_) +{ + LUA_ASSERT(L_, lua_isnil(L_, index_) || lua_type(L_, index_) == LUA_TUSERDATA); + return static_cast(lua_touserdata(L_, index_)); +} + +// ------------------------------------------------------------------------------------------------- + +template +[[nodiscard]] auto luaG_tolightuserdata(lua_State* L_, int index_) +{ + LUA_ASSERT(L_, lua_isnil(L_, index_) || lua_islightuserdata(L_, index_)); + if constexpr (std::is_pointer_v) { + return static_cast(lua_touserdata(L_, index_)); + } else { + return static_cast(lua_touserdata(L_, index_)); + } +} + // ################################################################################################# // must keep as a macro as long as we do constant string concatenations #define STRINGVIEW_FMT "%.*s" // a replacement of lua_tolstring -[[nodiscard]] inline std::string_view luaG_tostringview(lua_State* const L_, int const idx_) +[[nodiscard]] inline std::string_view luaG_tostring(lua_State* const L_, int const idx_) { size_t _len{ 0 }; char const* _str{ lua_tolstring(L_, idx_, &_len) }; return std::string_view{ _str, _len }; } -[[nodiscard]] inline std::string_view luaG_checkstringview(lua_State* const L_, int const idx_) +[[nodiscard]] inline std::string_view luaG_checkstring(lua_State* const L_, int const idx_) { size_t _len{ 0 }; char const* _str{ luaL_checklstring(L_, idx_, &_len) }; return std::string_view{ _str, _len }; } -[[nodiscard]] inline std::string_view luaG_optstringview(lua_State* const L_, int const idx_, std::string_view const& default_) +[[nodiscard]] inline std::string_view luaG_optstring(lua_State* const L_, int const idx_, std::string_view const& default_) { if (lua_isnoneornil(L_, idx_)) { return default_; @@ -345,13 +378,13 @@ inline void luaG_setmetatable(lua_State* const L_, std::string_view const& tname } template -[[nodiscard]] inline std::string_view luaG_pushstringview(lua_State* const L_, std::string_view const& str_, EXTRA&&... extra_) +[[nodiscard]] inline std::string_view luaG_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_tostringview(L_, -1); + return luaG_tostring(L_, -1); } else { return std::string_view{ lua_pushlstring(L_, str_.data(), str_.size()), str_.size() }; } diff --git a/src/deep.cpp b/src/deep.cpp index 0fdcb31..b6a9a22 100644 --- a/src/deep.cpp +++ b/src/deep.cpp @@ -70,7 +70,7 @@ namespace { */ [[nodiscard]] static int DeepGC(lua_State* const L_) { - DeepPrelude* const* const _proxy{ lua_tofulluserdata(L_, 1) }; + DeepPrelude* const* const _proxy{ luaG_tofulluserdata(L_, 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 @@ -135,7 +135,7 @@ void DeepFactory::DeleteDeepObject(lua_State* const L_, DeepPrelude* const o_) { // when looking inside a keeper, we are 100% sure the object is a deep userdata if (mode_ == LookupMode::FromKeeper) { - DeepPrelude* const _proxy{ *lua_tofulluserdata(L_, index_) }; + DeepPrelude* const _proxy{ *luaG_tofulluserdata(L_, index_) }; // we can (and must) cast and fetch the internally stored factory return &_proxy->factory; } else { @@ -152,7 +152,7 @@ void DeepFactory::DeleteDeepObject(lua_State* const L_, DeepPrelude* const o_) // replace metatable with the factory pointer, if it is actually a deep userdata LookupDeep(L_); // L_: deep ... factory|nil - DeepFactory* const _ret{ lua_tolightuserdata(L_, -1) }; // nullptr if not a userdata + DeepFactory* const _ret{ luaG_tolightuserdata(L_, -1) }; // nullptr if not a userdata lua_pop(L_, 1); STACK_CHECK(L_, 0); return _ret; @@ -188,7 +188,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{ lua_newuserdatauv(L_, nuv_) }; // L_: DPC proxy + DeepPrelude** const _proxy{ luaG_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 @@ -237,7 +237,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, raise_luaL_error(errL_, "lanes receiving deep userdata should register the 'package' library"); } - std::ignore = luaG_pushstringview(L_, _modname); // L_: DPC proxy metatable require() "module" + std::ignore = luaG_pushstring(L_, _modname); // L_: DPC proxy metatable require() "module" if (luaG_getfield(L_, LUA_REGISTRYINDEX, 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_: @@ -256,7 +256,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_tostringview(L_, -1)); + raise_luaL_error(errL_, luaG_tostring(L_, -1)); } } } else { // already loaded, we are happy @@ -368,7 +368,7 @@ DeepPrelude* DeepFactory::toDeep(lua_State* const L_, int const index_) const } STACK_CHECK(L_, 0); - DeepPrelude** const _proxy{ lua_tofulluserdata(L_, index_) }; + DeepPrelude** const _proxy{ luaG_tofulluserdata(L_, index_) }; return *_proxy; } diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index f00b268..8142b6a 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp @@ -100,7 +100,7 @@ THE SOFTWARE. lua_pushvalue(L1, L1_i); // L1: ... v ... {} v lua_rawget(L1, -2); // L1: ... v ... {} "f.q.n" } - std::string_view _fqn{ luaG_tostringview(L1, -1) }; + std::string_view _fqn{ luaG_tostring(L1, -1) }; DEBUGSPEW_CODE(DebugSpew(Universe::Get(L1)) << "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 ... @@ -224,7 +224,7 @@ void InterCopyContext::copy_func() const } { - std::string_view const _bytecode{ luaG_tostringview(L1, -1) }; // L1: ... b + std::string_view const _bytecode{ luaG_tostring(L1, -1) }; // L1: ... b LUA_ASSERT(L1, !_bytecode.empty()); STACK_GROW(L2, 2); // Note: Line numbers seem to be taken precisely from the @@ -313,7 +313,7 @@ void InterCopyContext::lookup_native_func() const case LookupMode::ToKeeper: // push a sentinel closure that holds the lookup name as upvalue - std::ignore = luaG_pushstringview(L2, _fqn); // L1: ... f ... L2: "f.q.n" + std::ignore = luaG_pushstring(L2, _fqn); // L1: ... f ... L2: "f.q.n" lua_pushcclosure(L2, func_lookup_sentinel, 1); // L1: ... f ... L2: f break; @@ -322,7 +322,7 @@ void InterCopyContext::lookup_native_func() const kLookupRegKey.pushValue(L2); // L1: ... f ... L2: {} STACK_CHECK(L2, 1); LUA_ASSERT(L1, lua_istable(L2, -1)); - std::ignore = luaG_pushstringview(L2, _fqn); // L1: ... f ... L2: {} "f.q.n" + std::ignore = luaG_pushstring(L2, _fqn); // L1: ... f ... L2: {} "f.q.n" lua_rawget(L2, -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! @@ -388,7 +388,7 @@ void InterCopyContext::copy_cached_func() const // push a light userdata uniquely representing the function lua_pushlightuserdata(L2, _aspointer); // L2: ... {cache} ... p - //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaG_tostringview(L2, -1) << " >>" << std::endl); + //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaG_tostring(L2, -1) << " >>" << std::endl); lua_pushvalue(L2, -1); // L2: ... {cache} ... p p lua_rawget(L2, L2_cache_i); // L2: ... {cache} ... p function|nil|true @@ -433,7 +433,7 @@ void InterCopyContext::copy_cached_func() const case LookupMode::ToKeeper: // push a sentinel closure that holds the lookup name as upvalue - std::ignore = luaG_pushstringview(L2, _fqn); // L1: ... t ... L2: "f.q.n" + std::ignore = luaG_pushstring(L2, _fqn); // L1: ... t ... L2: "f.q.n" lua_pushcclosure(L2, table_lookup_sentinel, 1); // L1: ... t ... L2: f break; @@ -442,7 +442,7 @@ void InterCopyContext::copy_cached_func() const kLookupRegKey.pushValue(L2); // L1: ... t ... L2: {} STACK_CHECK(L2, 1); LUA_ASSERT(L1, lua_istable(L2, -1)); - std::ignore = luaG_pushstringview(L2, _fqn); // L2: {} "f.q.n" + std::ignore = luaG_pushstring(L2, _fqn); // L2: {} "f.q.n" lua_rawget(L2, -2); // L2: {} t // 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! @@ -492,7 +492,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const 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_tostringview(L1, _key_i) }; + std::string_view const _key{ luaG_tostring(L1, _key_i) }; size_t const _bufLen{ strlen(name) + _key.size() + 2 }; // +2 for separator dot and terminating 0 _valPath = static_cast(alloca(_bufLen)); sprintf(_valPath, "%s." STRINGVIEW_FMT, name, (int) _key.size(), _key.data()); @@ -597,7 +597,7 @@ void InterCopyContext::inter_copy_keyvaluepair() 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_tostringview(L2, -1) << " >>" << std::endl); + //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaG_tostring(L2, -1) << " >>" << std::endl); lua_rawget(L2, L2_cache_i); // L1: ... t ... L2: ... {cached|nil} bool const _not_found_in_cache{ lua_isnil(L2, -1) }; @@ -723,7 +723,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const // Returns false if not a deep userdata, else true (unless an error occured) [[nodiscard]] bool InterCopyContext::tryCopyDeep() const { - DeepFactory* const _factory{ DeepFactory::LookupFactory(L1, L1_i, mode) }; + DeepFactory* const _factory{ DeepFactory::LookupFactory(L1, L1_i, mode) }; // L1: ... deep ... if (_factory == nullptr) { return false; // not a deep userdata } @@ -733,30 +733,31 @@ void InterCopyContext::inter_copy_keyvaluepair() const // extract all uservalues of the source. unfortunately, the only way to know their count is to iterate until we fail int _nuv{ 0 }; - while (lua_getiuservalue(L1, L1_i, _nuv + 1) != LUA_TNONE) { // L1: ... u [uv]* nil + while (lua_getiuservalue(L1, L1_i, _nuv + 1) != LUA_TNONE) { // L1: ... deep ... [uv]* nil ++_nuv; } // last call returned TNONE and pushed nil, that we don't need - lua_pop(L1, 1); // L1: ... u [uv]* + lua_pop(L1, 1); // L1: ... deep ... [uv]* STACK_CHECK(L1, _nuv); - DeepPrelude* const _u{ *lua_tofulluserdata(L1, L1_i) }; - DeepFactory::PushDeepProxy(L2, _u, _nuv, mode, getErrL()); // L1: ... u [uv]* L2: u + DeepPrelude* const _deep{ *luaG_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 { InterCopyContext _c{ U, L2, L1, L2_cache_i, {}, VT::NORMAL, mode, name }; int const _clone_i{ lua_gettop(L2) }; + // TODO: STACK_GROW(L2, _nuv), and same for L1 above and everywhere we use lua_getiuservalue while (_nuv) { _c.L1_i = SourceIndex{ luaG_absindex(L1, -1) }; - if (!_c.inter_copy_one()) { // L1: ... u [uv]* L2: u uv + if (!_c.inter_copy_one()) { // L1: ... deep ... [uv]* L2: deep uv raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); } - lua_pop(L1, 1); // L1: ... u [uv]* + lua_pop(L1, 1); // L1: ... deep ... [uv]* // this pops the value from the stack - lua_setiuservalue(L2, _clone_i, _nuv); // L2: u + lua_setiuservalue(L2, _clone_i, _nuv); // L2: deep --_nuv; - } + } // loop done: no uv remains on L1 stack // L1: ... deep ... } STACK_CHECK(L2, 1); @@ -940,9 +941,9 @@ void InterCopyContext::inter_copy_keyvaluepair() const [[nodiscard]] bool InterCopyContext::inter_copy_string() const { - std::string_view const _s{ luaG_tostringview(L1, L1_i) }; + std::string_view const _s{ luaG_tostring(L1, L1_i) }; DEBUGSPEW_CODE(DebugSpew(nullptr) << "'" << _s << "'" << std::endl); - std::ignore = luaG_pushstringview(L2, _s); + std::ignore = luaG_pushstring(L2, _s); return true; } @@ -1188,7 +1189,7 @@ namespace { STACK_CHECK_START_REL(L1, 0); if (luaG_type(L1, L1_i) != LuaType::TABLE) { - std::string_view const _msg{ luaG_pushstringview(L1, "expected package as table, got a %s", luaL_typename(L1, L1_i)) }; + std::string_view const _msg{ luaG_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) { @@ -1224,7 +1225,7 @@ namespace { if (_result == InterCopyResult::Success) { lua_setfield(L2, -2, _entry.data()); // set package[entry] } else { - std::string_view const _msg{ luaG_pushstringview(L1, "failed to copy package.%s", _entry.data()) }; + std::string_view const _msg{ luaG_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 87f5505..22bd67e 100644 --- a/src/keeper.cpp +++ b/src/keeper.cpp @@ -69,7 +69,7 @@ class KeyUD int limit{ -1 }; // 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 lua_newuserdatauv(L_, 1); } + [[nodiscard]] static void* operator new([[maybe_unused]] size_t size_, KeeperState L_) noexcept { return luaG_newuserdatauv(L_, 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"); } @@ -117,7 +117,7 @@ KeyUD* KeyUD::Create(KeeperState const K_) KeyUD* KeyUD::GetPtr(KeeperState const K_, int idx_) { - return lua_tofulluserdata(K_, idx_); + return luaG_tofulluserdata(K_, idx_); } // ################################################################################################# @@ -824,7 +824,7 @@ void Keepers::initialize(Universe& U_, lua_State* L_, int const nbKeepers_, int keeper_.K = _K; // Give a name to the state - std::ignore = luaG_pushstringview(_K, "Keeper #%d", i_ + 1); // L_: settings _K: "Keeper #n" + std::ignore = luaG_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" diff --git a/src/lane.cpp b/src/lane.cpp index ea3edb0..de513c2 100644 --- a/src/lane.cpp +++ b/src/lane.cpp @@ -46,7 +46,7 @@ static LUAG_FUNC(get_debug_threadname) { Lane* const _lane{ ToLane(L_, 1) }; luaL_argcheck(L_, lua_gettop(L_) == 1, 2, "too many arguments"); - std::ignore = luaG_pushstringview(L_, _lane->debugName); + std::ignore = luaG_pushstring(L_, _lane->debugName); return 1; } @@ -80,7 +80,7 @@ static LUAG_FUNC(set_finalizer) static LUAG_FUNC(set_debug_threadname) { // C s_lane structure is a light userdata upvalue - Lane* const _lane{ lua_tolightuserdata(L_, lua_upvalueindex(1)) }; + Lane* const _lane{ luaG_tolightuserdata(L_, 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 lua_settop(L_, 1); STACK_CHECK_START_REL(L_, 0); @@ -300,7 +300,7 @@ static int thread_index_string(lua_State* L_) Lane* const _lane{ ToLane(L_, kSelf) }; LUA_ASSERT(L_, lua_gettop(L_) == 2); // L_: lane "key" - std::string_view const _keystr{ luaG_tostringview(L_, kKey) }; + std::string_view const _keystr{ luaG_tostring(L_, kKey) }; lua_settop(L_, 2); // keep only our original arguments on the stack if (_keystr == "status") { std::ignore = _lane->pushThreadStatus(L_); // L_: lane "key" "" @@ -462,9 +462,9 @@ static constexpr RegistryUniqueKey kStackTraceRegKey{ 0x3F327747CACAA904ull }; lua_pushstring(L_, _ar.what); // L_: some_error {} {} what lua_setfield(L_, -2, "what"); // L_: some_error {} {} } else if (_ar.currentline > 0) { - std::ignore = luaG_pushstringview(L_, "%s:%d", _ar.short_src, _ar.currentline); // L_: some_error {} "blah:blah" + std::ignore = luaG_pushstring(L_, "%s:%d", _ar.short_src, _ar.currentline); // L_: some_error {} "blah:blah" } else { - std::ignore = luaG_pushstringview(L_, "%s:?", _ar.short_src); // L_: some_error {} "blah" + std::ignore = luaG_pushstring(L_, "%s:?", _ar.short_src); // L_: some_error {} "blah" } lua_rawseti(L_, -2, static_cast(_n)); // L_: some_error {} } @@ -551,7 +551,7 @@ static void push_stack_trace(lua_State* L_, Lane::ErrorTraceLevel errorTraceLeve LUA_ASSERT(L_, lua_isfunction(L_, -1)); if (lua_rc_ != LuaError::OK) { // we have an error message and an optional stack trace at the bottom of the stack LUA_ASSERT(L_, _finalizers_index == 2 || _finalizers_index == 3); - //std::string_view const _err_msg{ luaG_tostringview(L_, 1) }; + //std::string_view const _err_msg{ luaG_tostring(L_, 1) }; lua_pushvalue(L_, 1); // L_: ... finalizers lane_error finalizer err_msg // note we don't always have a stack trace for example when kCancelError, or when we got an error that doesn't call our handler, such as LUA_ERRMEM if (_finalizers_index == 3) { @@ -745,7 +745,7 @@ static void lane_main(Lane* lane_) lua_rawget(L_, -2); // L_: ud uservalue gc_cb|nil if (!lua_isnil(L_, -1)) { lua_remove(L_, -2); // L_: ud gc_cb|nil - std::ignore = luaG_pushstringview(L_, _lane->debugName); // L_: ud gc_cb name + std::ignore = luaG_pushstring(L_, _lane->debugName); // L_: ud gc_cb name _have_gc_cb = true; } else { lua_pop(L_, 2); // L_: ud @@ -810,7 +810,7 @@ void Lane::changeDebugName(int const nameIdx_) // 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, [idx = _nameIdx](lua_State* L_) { lua_pushvalue(L_, idx); }); // L: ... "name" ... // keep a direct pointer on the string - debugName = luaG_tostringview(L, _nameIdx); + debugName = luaG_tostring(L, _nameIdx); if constexpr (HAVE_DECODA_SUPPORT()) { // to see VM name in Decoda debugger Virtual Machine window lua_pushvalue(L, _nameIdx); // L: ... "name" ... "name" @@ -897,7 +897,7 @@ void Lane::PushMetatable(lua_State* L_) std::string_view const _str{ threadStatusString() }; LUA_ASSERT(L_, !_str.empty()); - return luaG_pushstringview(L_, _str); + return luaG_pushstring(L_, _str); } // ################################################################################################# @@ -907,7 +907,7 @@ void Lane::PushMetatable(lua_State* L_) std::string_view const _str{ errorTraceLevelString() }; LUA_ASSERT(L_, !_str.empty()); - return luaG_pushstringview(L_, _str); + return luaG_pushstring(L_, _str); } // ################################################################################################# @@ -922,7 +922,7 @@ void Lane::securizeDebugName(lua_State* L_) LUA_ASSERT(L_, lua_istable(L_, -1)); // we don't care about the actual key, so long as it's unique and can't collide with anything. lua_newtable(L_); // L_: lane ... {uv} {} - debugName = luaG_pushstringview(L_, debugName); // L_: lane ... {uv} {} name + debugName = luaG_pushstring(L_, debugName); // L_: lane ... {uv} {} name lua_rawset(L_, -3); // L_: lane ... {uv} lua_pop(L_, 1); // L_: lane STACK_CHECK(L_, 0); diff --git a/src/lanes.cpp b/src/lanes.cpp index 96d4ecd..a7631bb 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp @@ -169,7 +169,7 @@ LUAG_FUNC(sleep) lua_pushcfunction(L_, LG_linda_receive); // L_: duration|nil receive() STACK_CHECK_START_REL(L_, 0); // we pushed the function we intend to call, now prepare the arguments _U->timerLinda->push(L_); // L_: duration|nil receive() timerLinda - if (luaG_tostringview(L_, 1) == "indefinitely") { + if (luaG_tostring(L_, 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 @@ -179,7 +179,7 @@ LUAG_FUNC(sleep) else { lua_pushnumber(L_, lua_tonumber(L_, 1)); // L_: duration? receive() timerLinda duration } - std::ignore = luaG_pushstringview(L_, "ac100de1-a696-4619-b2f0-a26de9d58ab8"); // L_: duration? receive() timerLinda duration key + std::ignore = luaG_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; @@ -193,7 +193,7 @@ LUAG_FUNC(sleep) // upvalue[1]: _G.require LUAG_FUNC(require) { - std::string_view const _name{ luaG_tostringview(L_, 1) }; // L_: "name" ... + std::string_view const _name{ luaG_tostring(L_, 1) }; // L_: "name" ... int const _nargs{ lua_gettop(L_) }; DEBUGSPEW_CODE(Universe * _U{ Universe::Get(L_) }); STACK_CHECK_START_REL(L_, 0); @@ -215,7 +215,7 @@ LUAG_FUNC(require) // lanes.register( "modname", module) LUAG_FUNC(register) { - std::string_view const _name{ luaG_checkstringview(L_, 1) }; + std::string_view const _name{ luaG_checkstring(L_, 1) }; LuaType const _mod_type{ luaG_type(L_, 2) }; // ignore extra parameters, just in case lua_settop(L_, 2); @@ -265,7 +265,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_tostringview(L_, kLibsIdx)) }; + std::optional _libs_str{ lua_isnil(L_, kLibsIdx) ? std::nullopt : std::make_optional(luaG_tostring(L_, kLibsIdx)) }; lua_State* const _L2{ state::NewLaneState(_U, SourceState{ L_ }, _libs_str) }; // L_: [fixed] ... L2: STACK_CHECK_START_REL(_L2, 0); @@ -318,7 +318,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{ lua_newuserdatauv(L, 1) }; // L: ... lane + Lane** const _ud{ luaG_newuserdatauv(L, 1) }; // L: ... lane *_ud = lane; // don't forget to store the pointer in the userdata! // Set metatable for the userdata @@ -344,18 +344,16 @@ LUAG_FUNC(lane_new) lua_State* _L2{ lane->L }; STACK_CHECK_START_REL(_L2, 0); int const _name_idx{ lua_isnoneornil(L, kNameIdx) ? 0 : kNameIdx }; - std::string_view const _debugName{ (_name_idx > 0) ? luaG_tostringview(L, _name_idx) : std::string_view{} }; + std::string_view const _debugName{ (_name_idx > 0) ? luaG_tostring(L, _name_idx) : std::string_view{} }; if (!_debugName.empty()) { if (_debugName != "auto") { - std::ignore = luaG_pushstringview(_L2, _debugName); // L: ... lane L2: "" + std::ignore = luaG_pushstring(_L2, _debugName); // L: ... lane L2: "" } else { lua_Debug _ar; lua_pushvalue(L, 1); // L: ... lane func lua_getinfo(L, ">S", &_ar); // L: ... lane - std::ignore = luaG_pushstringview( - _L2, "%s:%d", _ar.short_src, _ar.linedefined - ); // L: ... lane L2: "" + std::ignore = luaG_pushstring(_L2, "%s:%d", _ar.short_src, _ar.linedefined); // L: ... lane L2: "" } lane->changeDebugName(-1); lua_pop(_L2, 1); // L: ... lane L2: @@ -424,7 +422,7 @@ LUAG_FUNC(lane_new) 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_tostringview(L_, -1) }; + std::string_view const _name{ luaG_tostring(L_, -1) }; DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: require '" << _name << "'" << std::endl); // require the module in the target lane @@ -433,7 +431,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 { - std::ignore = luaG_pushstringview(_L2, _name); // L_: [fixed] args... n "modname" L2: require() name + std::ignore = luaG_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 @@ -656,7 +654,7 @@ LUAG_FUNC(configure) Universe* _U{ Universe::Get(L_) }; bool const _from_master_state{ _U == nullptr }; - std::string_view const _name{ luaG_checkstringview(L_, lua_upvalueindex(1)) }; + std::string_view const _name{ luaG_checkstring(L_, lua_upvalueindex(1)) }; LUA_ASSERT(L_, luaG_type(L_, 1) == LuaType::TABLE); STACK_GROW(L_, 4); @@ -667,7 +665,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_) { std::ignore = luaG_pushstringview(L_, "main"); }); + kLaneNameRegKey.setValue(L_, [](lua_State* L_) { std::ignore = luaG_pushstring(L_, "main"); }); // create the universe _U = Universe::Create(L_); // L_: settings universe @@ -707,7 +705,7 @@ LUAG_FUNC(configure) lua_pushcclosure(L_, LG_require, 1); // L_: settings M lanes.require lua_setfield(L_, -2, "require"); // L_: settings M - std::ignore = luaG_pushstringview( + std::ignore = luaG_pushstring( L_, "%d.%d.%d", LANES_VERSION_MAJOR, diff --git a/src/linda.cpp b/src/linda.cpp index 031eea0..e4ae3f4 100644 --- a/src/linda.cpp +++ b/src/linda.cpp @@ -81,13 +81,13 @@ template { Linda* const _linda{ ToLinda(L_, idx_) }; if (_linda != nullptr) { - std::ignore = luaG_pushstringview(L_, "Linda: "); + std::ignore = luaG_pushstring(L_, "Linda: "); std::string_view const _lindaName{ _linda->getName() }; if (!_lindaName.empty()) { - std::ignore = luaG_pushstringview(L_, _lindaName); + std::ignore = luaG_pushstring(L_, _lindaName); } else { // obfuscate the pointer so that we can't read the value with our eyes out of a script - std::ignore = luaG_pushstringview(L_, "%p", std::bit_cast(_linda) ^ kConfigRegKey.storage); + std::ignore = luaG_pushstring(L_, "%p", std::bit_cast(_linda) ^ kConfigRegKey.storage); } lua_concat(L_, 2); return 1; @@ -252,7 +252,7 @@ void Linda::setName(std::string_view const& name_) LUAG_FUNC(linda_cancel) { Linda* const _linda{ ToLinda(L_, 1) }; - std::string_view const _who{ luaG_optstringview(L_, 2, "both") }; + std::string_view const _who{ luaG_optstring(L_, 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"); @@ -564,7 +564,7 @@ LUAG_FUNC(linda_receive) if (_nbPushed == 0) { // not enough data in the linda slot to fulfill the request, return nil, "timeout" lua_pushnil(L_); - std::ignore = luaG_pushstringview(L_, "timeout"); + std::ignore = luaG_pushstring(L_, "timeout"); return 2; } return _nbPushed; diff --git a/src/lindafactory.cpp b/src/lindafactory.cpp index 68cb471..8622c12 100644 --- a/src/lindafactory.cpp +++ b/src/lindafactory.cpp @@ -114,14 +114,14 @@ DeepPrelude* LindaFactory::newDeepObjectInternal(lua_State* const L_) const case 1: // 1 parameter, either a name or a group if (luaG_type(L_, -1) == LuaType::STRING) { - _linda_name = luaG_tostringview(L_, -1); + _linda_name = luaG_tostring(L_, -1); } else { _linda_group = LindaGroup{ static_cast(lua_tointeger(L_, -1)) }; } break; case 2: // 2 parameters, a name and group, in that order - _linda_name = luaG_tostringview(L_, -2); + _linda_name = luaG_tostring(L_, -2); _linda_group = LindaGroup{ static_cast(lua_tointeger(L_, -1)) }; break; } @@ -131,12 +131,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_pushstringview(L_, "%s:%d", _ar.short_src, _ar.currentline); + _linda_name = luaG_pushstring(L_, "%s:%d", _ar.short_src, _ar.currentline); } else { - _linda_name = luaG_pushstringview(L_, ""); + _linda_name = luaG_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_tostringview(L_, 1) == "auto"); + LUA_ASSERT(L_, luaG_tostring(L_, 1) == "auto"); lua_replace(L_, 1); } diff --git a/src/macros_and_utils.h b/src/macros_and_utils.h index 338e389..3e0b425 100644 --- a/src/macros_and_utils.h +++ b/src/macros_and_utils.h @@ -31,33 +31,6 @@ inline void STACK_GROW(lua_State* L_, int n_) // ################################################################################################# -// a small helper to extract a full userdata pointer from the stack in a safe way -template -[[nodiscard]] T* lua_tofulluserdata(lua_State* L_, int index_) -{ - LUA_ASSERT(L_, lua_isnil(L_, index_) || lua_type(L_, index_) == LUA_TUSERDATA); - return static_cast(lua_touserdata(L_, index_)); -} - -template -[[nodiscard]] auto lua_tolightuserdata(lua_State* L_, int index_) -{ - LUA_ASSERT(L_, lua_isnil(L_, index_) || lua_islightuserdata(L_, index_)); - if constexpr (std::is_pointer_v) { - return static_cast(lua_touserdata(L_, index_)); - } else { - return static_cast(lua_touserdata(L_, index_)); - } -} - -template -[[nodiscard]] T* lua_newuserdatauv(lua_State* L_, int nuvalue_) -{ - return static_cast(lua_newuserdatauv(L_, sizeof(T), nuvalue_)); -} - -// ################################################################################################# - using lua_Duration = std::chrono::template duration; // ################################################################################################# diff --git a/src/nameof.cpp b/src/nameof.cpp index 8e79fda..6c968d5 100644 --- a/src/nameof.cpp +++ b/src/nameof.cpp @@ -60,7 +60,7 @@ THE SOFTWARE. // scan table contents lua_pushnil(L_); // L_: o "r" {c} {fqn} ... {?} nil while (lua_next(L_, -2)) { // L_: o "r" {c} {fqn} ... {?} k v - // std::string_view const _strKey{ (luaG_type(L_, -2) == LuaType::STRING) ? luaG_tostringview(L_, -2) : "" }; // only for debugging + // std::string_view const _strKey{ (luaG_type(L_, -2) == LuaType::STRING) ? luaG_tostring(L_, -2) : "" }; // only for debugging // lua_Number const numKey = (luaG_type(L_, -2) == LuaType::NUMBER) ? lua_tonumber(L_, -2) : -6666; // only for debugging STACK_CHECK(L_, 2); // append key name to fqn stack diff --git a/src/state.cpp b/src/state.cpp index 47e31c3..cafabf1 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -183,7 +183,7 @@ namespace state { STACK_CHECK(L_, 1); // capture error and raise it in caller state std::string_view const _stateType{ mode_ == LookupMode::LaneBody ? "lane" : "keeper" }; - std::ignore = luaG_pushstringview(L_, _stateType); // L_: on_state_create() "" + std::ignore = luaG_pushstring(L_, _stateType); // L_: on_state_create() "" if (lua_pcall(L_, 1, 0, 0) != LUA_OK) { raise_luaL_error(from_, "%s failed: \"%s\"", kOnStateCreate, lua_isstring(L_, -1) ? lua_tostring(L_, -1) : luaG_typename(L_, luaG_type(L_, -1))); } @@ -204,7 +204,7 @@ namespace state { if (U->provideAllocator != nullptr) { // we have a function we can call to obtain an allocator lua_pushcclosure(from, U->provideAllocator, 0); lua_call(from, 0, 1); - AllocatorDefinition* const _def{ lua_tofulluserdata(from, -1) }; + AllocatorDefinition* const _def{ luaG_tofulluserdata(from, -1) }; lua_State* const _L{ lua_newstate(_def->allocF, _def->allocUD) }; lua_pop(from, 1); return _L; @@ -364,19 +364,19 @@ namespace state { kLookupRegKey.pushValue(_L); // L: {} lua_pushnil(_L); // L: {} nil while (lua_next(_L, -2)) { // L: {} k v - std::ignore = luaG_pushstringview(_L, "["); // L: {} k v "[" + std::ignore = luaG_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' - std::ignore = luaG_pushstringview(_L, "] = "); // L: {} k v "[" 'k' "] = " + std::ignore = luaG_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_tostringview(_L, -1) << std::endl); + DEBUGSPEW_CODE(DebugSpew(U_) << luaG_tostring(_L, -1) << std::endl); lua_pop(_L, 2); // L: {} k } // lua_next() // L: {} lua_pop(_L, 1); // L: diff --git a/src/tools.cpp b/src/tools.cpp index 1afc2b8..efded98 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -112,7 +112,7 @@ namespace tools { // &b is popped at that point (-> replaced by the result) luaL_pushresult(&_b); // L_: ... {} ... "" STACK_CHECK(L_, 1); - return luaG_tostringview(L_, -1); + return luaG_tostring(L_, -1); } } // namespace tools @@ -142,7 +142,7 @@ static void update_lookup_entry(lua_State* L_, int ctxBase_, int depth_) // 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_tostringview(L_, -1) }; // nullptr if we got nil (first encounter of this object) + std::string_view const _prevName{ luaG_tostring(L_, -1) }; // 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_, -1) == LuaType::NUMBER || luaG_type(L_, -1) == LuaType::STRING); @@ -237,7 +237,7 @@ static void populate_func_lookup_table_recur(lua_State* L_, int dbIdx_, int i_, 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_tostringview(L_, -2) : "not a string" }; + // std::string_view const _key{ (luaG_type(L_, -2) == LuaType::STRING) ? luaG_tostring(L_, -2) : "not a string" }; // subtable: process it recursively if (lua_istable(L_, -1)) { // L_: ... {i_} {bfc} k {} // increment visit count to make sure we will actually scan it at this recursive level @@ -267,7 +267,7 @@ static void populate_func_lookup_table_recur(lua_State* L_, int dbIdx_, int i_, ++depth_; 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_, -2) == LuaType::STRING) ? luaG_tostringview(L_, -2) : std::string_view{ "" } }); + DEBUGSPEW_CODE(std::string_view const _key{ (luaG_type(L_, -2) == LuaType::STRING) ? luaG_tostring(L_, -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 @@ -323,9 +323,9 @@ namespace tools { _name = "nullptr"; } lua_pushvalue(L_, _in_base); // L_: {} f - std::ignore = luaG_pushstringview(L_, _name); // L_: {} f name_ + std::ignore = luaG_pushstring(L_, _name); // L_: {} f name_ lua_rawset(L_, -3); // L_: {} - std::ignore = luaG_pushstringview(L_, _name); // L_: {} name_ + std::ignore = luaG_pushstring(L_, _name); // L_: {} name_ lua_pushvalue(L_, _in_base); // L_: {} name_ f lua_rawset(L_, -3); // L_: {} lua_pop(L_, 1); // L_: @@ -334,7 +334,7 @@ namespace tools { int _startDepth{ 0 }; if (!_name.empty()) { STACK_CHECK(L_, 2); - std::ignore = luaG_pushstringview(L_, _name); // L_: {} {fqn} "name" + std::ignore = luaG_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" @@ -367,7 +367,7 @@ namespace tools { +[](lua_State* L_) { int const _args{ lua_gettop(L_) }; // L_: args... - //[[maybe_unused]] std::string_view const _modname{ luaG_checkstringview(L_, 1) }; + //[[maybe_unused]] std::string_view const _modname{ luaG_checkstring(L_, 1) }; STACK_GROW(L_, 1); diff --git a/src/tracker.cpp b/src/tracker.cpp index 24e8d01..ae4d116 100644 --- a/src/tracker.cpp +++ b/src/tracker.cpp @@ -94,7 +94,7 @@ void LaneTracker::tracking_add(Lane* lane_) 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_: {} {} - std::ignore = luaG_pushstringview(L_, _lane->debugName); // L_: {} {} "name" + std::ignore = luaG_pushstring(L_, _lane->debugName); // L_: {} {} "name" lua_setfield(L_, -2, "name"); // L_: {} {} std::ignore = _lane->pushThreadStatus(L_); // L_: {} {} "status" lua_setfield(L_, -2, "status"); // L_: {} {} diff --git a/src/uniquekey.h b/src/uniquekey.h index 114d22e..94c09c7 100644 --- a/src/uniquekey.h +++ b/src/uniquekey.h @@ -70,7 +70,7 @@ class RegistryUniqueKey STACK_GROW(L_, 1); STACK_CHECK_START_REL(L_, 0); pushValue(L_); - T* const value{ lua_tolightuserdata(L_, -1) }; // lightuserdata/nil + T* const value{ luaG_tolightuserdata(L_, -1) }; // lightuserdata/nil lua_pop(L_, 1); STACK_CHECK(L_, 0); return value; diff --git a/src/universe.cpp b/src/universe.cpp index 116c8e3..9ab6019 100644 --- a/src/universe.cpp +++ b/src/universe.cpp @@ -135,13 +135,13 @@ Universe::Universe() // Initialize 'timerLinda'; a common Linda object shared by all states lua_pushcfunction(L_, LG_linda); // L_: settings lanes.linda - std::ignore = luaG_pushstringview(L_, "lanes-timer"); // L_: settings lanes.linda "lanes-timer" + std::ignore = luaG_pushstring(L_, "lanes-timer"); // L_: settings lanes.linda "lanes-timer" lua_pushinteger(L_, 0); // L_: settings lanes.linda "lanes-timer" 0 lua_call(L_, 2, 1); // L_: settings linda STACK_CHECK(L_, 1); // Proxy userdata contents is only a 'DeepPrelude*' pointer - _U->timerLinda = *lua_tofulluserdata(L_, -1); + _U->timerLinda = *luaG_tofulluserdata(L_, -1); // increment refcount so that this linda remains alive as long as the universe exists. _U->timerLinda->refcount.fetch_add(1, std::memory_order_relaxed); lua_pop(L_, 1); // L_: settings @@ -210,7 +210,7 @@ void Universe::initializeAllocatorFunction(lua_State* const L_) STACK_CHECK(L_, 1); std::ignore = luaG_getfield(L_, -1, "internal_allocator"); // L_: settings "libc"|"allocator" - std::string_view const _allocator{ luaG_tostringview(L_, -1) }; + std::string_view const _allocator{ luaG_tostring(L_, -1) }; if (_allocator == "libc") { internalAllocator = AllocatorDefinition{ libc_lua_Alloc, nullptr }; } else if (provideAllocator == luaG_provide_protected_allocator) { @@ -317,9 +317,9 @@ void Universe::terminateFreeRunningLanes(lua_State* const L_, lua_Duration const LUAG_FUNC(universe_gc) { lua_Duration const _shutdown_timeout{ lua_tonumber(L_, lua_upvalueindex(1)) }; - std::string_view const _op_string{ luaG_tostringview(L_, lua_upvalueindex(2)) }; + std::string_view const _op_string{ luaG_tostring(L_, lua_upvalueindex(2)) }; STACK_CHECK_START_ABS(L_, 1); - Universe* const _U{ lua_tofulluserdata(L_, 1) }; // L_: U + Universe* const _U{ luaG_tofulluserdata(L_, 1) }; // L_: U _U->terminateFreeRunningLanes(L_, _shutdown_timeout, which_cancel_op(_op_string)); // invoke the function installed by lanes.finally() diff --git a/src/universe.h b/src/universe.h index 6f03ed3..2b8cdf2 100644 --- a/src/universe.h +++ b/src/universe.h @@ -171,7 +171,7 @@ class Universe std::atomic selfdestructingCount{ 0 }; public: - [[nodiscard]] static void* operator new([[maybe_unused]] size_t size_, lua_State* L_) noexcept { return lua_newuserdatauv(L_, 0); }; + [[nodiscard]] static void* operator new([[maybe_unused]] size_t size_, lua_State* L_) noexcept { return luaG_newuserdatauv(L_, 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* p_, [[maybe_unused]] lua_State* L_) {} // nothing to do, as nothing is allocated independently -- cgit v1.2.3-55-g6feb