diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2025-07-04 13:50:53 +0200 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2025-07-04 13:50:53 +0200 |
| commit | 042055968ab0c48faec607889814e38c50c09efa (patch) | |
| tree | 4ec067a03ffcb720d8bf38968d5f84ccec8230d0 /src | |
| parent | 963afcbb3d9dac47b84552ed11e53a0641ad924d (diff) | |
| download | lanes-042055968ab0c48faec607889814e38c50c09efa.tar.gz lanes-042055968ab0c48faec607889814e38c50c09efa.tar.bz2 lanes-042055968ab0c48faec607889814e38c50c09efa.zip | |
Changed lua wrapper prefixes from luaG_ to luaW_ (w as in wrapper!)
Diffstat (limited to 'src')
| -rw-r--r-- | src/allocator.cpp | 2 | ||||
| -rw-r--r-- | src/cancel.cpp | 14 | ||||
| -rw-r--r-- | src/compat.cpp | 12 | ||||
| -rw-r--r-- | src/compat.hpp | 66 | ||||
| -rw-r--r-- | src/deep.cpp | 28 | ||||
| -rw-r--r-- | src/intercopycontext.cpp | 142 | ||||
| -rw-r--r-- | src/keeper.cpp | 50 | ||||
| -rw-r--r-- | src/lane.cpp | 92 | ||||
| -rw-r--r-- | src/lanes.cpp | 58 | ||||
| -rw-r--r-- | src/linda.cpp | 60 | ||||
| -rw-r--r-- | src/lindafactory.cpp | 16 | ||||
| -rw-r--r-- | src/nameof.cpp | 34 | ||||
| -rw-r--r-- | src/state.cpp | 18 | ||||
| -rw-r--r-- | src/threading.cpp | 4 | ||||
| -rw-r--r-- | src/tools.cpp | 50 | ||||
| -rw-r--r-- | src/tools.hpp | 2 | ||||
| -rw-r--r-- | src/tracker.cpp | 2 | ||||
| -rw-r--r-- | src/uniquekey.hpp | 6 | ||||
| -rw-r--r-- | src/universe.cpp | 56 | ||||
| -rw-r--r-- | src/universe.hpp | 2 |
20 files changed, 357 insertions, 357 deletions
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 | |||
| 35 | { | 35 | { |
| 36 | AllocatorDefinition& AllocatorDefinition::Validated(lua_State* const L_, StackIndex const idx_) | 36 | AllocatorDefinition& AllocatorDefinition::Validated(lua_State* const L_, StackIndex const idx_) |
| 37 | { | 37 | { |
| 38 | lanes::AllocatorDefinition* const _def{ luaG_tofulluserdata<lanes::AllocatorDefinition>(L_, idx_) }; | 38 | lanes::AllocatorDefinition* const _def{ luaW_tofulluserdata<lanes::AllocatorDefinition>(L_, idx_) }; |
| 39 | // raise an error and don't return if the full userdata at the specified index is not a valid AllocatorDefinition | 39 | // raise an error and don't return if the full userdata at the specified index is not a valid AllocatorDefinition |
| 40 | if (!_def) { | 40 | if (!_def) { |
| 41 | raise_luaL_error(L_, "Bad config.allocator function, provided value is not a userdata"); | 41 | 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 { | |||
| 70 | [[nodiscard]] | 70 | [[nodiscard]] |
| 71 | static CancelOp WhichCancelOp(lua_State* const L_, StackIndex const idx_) | 71 | static CancelOp WhichCancelOp(lua_State* const L_, StackIndex const idx_) |
| 72 | { | 72 | { |
| 73 | if (luaG_type(L_, idx_) == LuaType::STRING) { | 73 | if (luaW_type(L_, idx_) == LuaType::STRING) { |
| 74 | std::string_view const _str{ luaG_tostring(L_, idx_) }; | 74 | std::string_view const _str{ luaW_tostring(L_, idx_) }; |
| 75 | auto const _op{ WhichCancelOp(_str) }; | 75 | auto const _op{ WhichCancelOp(_str) }; |
| 76 | lua_remove(L_, idx_); // argument is processed, remove it | 76 | lua_remove(L_, idx_); // argument is processed, remove it |
| 77 | if (!_op.has_value()) { | 77 | if (!_op.has_value()) { |
| @@ -123,7 +123,7 @@ LUAG_FUNC(cancel_test) | |||
| 123 | if (_test == CancelRequest::None) { | 123 | if (_test == CancelRequest::None) { |
| 124 | lua_pushboolean(L_, 0); | 124 | lua_pushboolean(L_, 0); |
| 125 | } else { | 125 | } else { |
| 126 | luaG_pushstring(L_, (_test == CancelRequest::Soft) ? "soft" : "hard"); | 126 | luaW_pushstring(L_, (_test == CancelRequest::Soft) ? "soft" : "hard"); |
| 127 | } | 127 | } |
| 128 | return 1; | 128 | return 1; |
| 129 | } | 129 | } |
| @@ -158,7 +158,7 @@ LUAG_FUNC(lane_cancel) | |||
| 158 | // the caller shouldn't have provided a hook count in that case | 158 | // the caller shouldn't have provided a hook count in that case |
| 159 | return 0; | 159 | return 0; |
| 160 | } | 160 | } |
| 161 | if (luaG_type(L_, StackIndex{ 2 }) != LuaType::NUMBER) { | 161 | if (luaW_type(L_, StackIndex{ 2 }) != LuaType::NUMBER) { |
| 162 | raise_luaL_error(L_, "Hook count expected"); | 162 | raise_luaL_error(L_, "Hook count expected"); |
| 163 | } | 163 | } |
| 164 | auto const _hook_count{ static_cast<int>(lua_tointeger(L_, 2)) }; | 164 | auto const _hook_count{ static_cast<int>(lua_tointeger(L_, 2)) }; |
| @@ -170,7 +170,7 @@ LUAG_FUNC(lane_cancel) | |||
| 170 | }) }; | 170 | }) }; |
| 171 | 171 | ||
| 172 | std::chrono::time_point<std::chrono::steady_clock> _until{ std::chrono::time_point<std::chrono::steady_clock>::max() }; | 172 | std::chrono::time_point<std::chrono::steady_clock> _until{ std::chrono::time_point<std::chrono::steady_clock>::max() }; |
| 173 | if (luaG_type(L_, StackIndex{ 2 }) == LuaType::NUMBER) { // we don't want to use lua_isnumber() because of autocoercion | 173 | if (luaW_type(L_, StackIndex{ 2 }) == LuaType::NUMBER) { // we don't want to use lua_isnumber() because of autocoercion |
| 174 | lua_Duration const duration{ lua_tonumber(L_, 2) }; | 174 | lua_Duration const duration{ lua_tonumber(L_, 2) }; |
| 175 | if (duration.count() >= 0.0) { | 175 | if (duration.count() >= 0.0) { |
| 176 | _until = std::chrono::steady_clock::now() + std::chrono::duration_cast<std::chrono::steady_clock::duration>(duration); | 176 | _until = std::chrono::steady_clock::now() + std::chrono::duration_cast<std::chrono::steady_clock::duration>(duration); |
| @@ -186,7 +186,7 @@ LUAG_FUNC(lane_cancel) | |||
| 186 | WakeLane _wake_lane{ (_op.mode == CancelRequest::Hard) ? WakeLane::Yes : WakeLane::No }; | 186 | WakeLane _wake_lane{ (_op.mode == CancelRequest::Hard) ? WakeLane::Yes : WakeLane::No }; |
| 187 | if (lua_gettop(L_) >= 2) { | 187 | if (lua_gettop(L_) >= 2) { |
| 188 | if (!lua_isboolean(L_, 2)) { | 188 | if (!lua_isboolean(L_, 2)) { |
| 189 | raise_luaL_error(L_, "Boolean expected for wake_lane argument, got %s", luaG_typename(L_, StackIndex{ 2 }).data()); | 189 | raise_luaL_error(L_, "Boolean expected for wake_lane argument, got %s", luaW_typename(L_, StackIndex{ 2 }).data()); |
| 190 | } | 190 | } |
| 191 | _wake_lane = lua_toboolean(L_, 2) ? WakeLane::Yes : WakeLane::No; | 191 | _wake_lane = lua_toboolean(L_, 2) ? WakeLane::Yes : WakeLane::No; |
| 192 | lua_remove(L_, 2); // argument is processed, remove it // L_: lane | 192 | lua_remove(L_, 2); // argument is processed, remove it // L_: lane |
| @@ -206,7 +206,7 @@ LUAG_FUNC(lane_cancel) | |||
| 206 | 206 | ||
| 207 | case CancelResult::Timeout: | 207 | case CancelResult::Timeout: |
| 208 | lua_pushboolean(L_, 0); // L_: false | 208 | lua_pushboolean(L_, 0); // L_: false |
| 209 | luaG_pushstring(L_, "timeout"); // L_: false "timeout" | 209 | luaW_pushstring(L_, "timeout"); // L_: false "timeout" |
| 210 | break; | 210 | break; |
| 211 | 211 | ||
| 212 | case CancelResult::Cancelled: | 212 | 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 @@ | |||
| 5 | 5 | ||
| 6 | // ################################################################################################# | 6 | // ################################################################################################# |
| 7 | 7 | ||
| 8 | UserValueCount luaG_getalluservalues(lua_State* const L_, StackIndex const idx_) | 8 | UserValueCount luaW_getalluservalues(lua_State* const L_, StackIndex const idx_) |
| 9 | { | 9 | { |
| 10 | STACK_CHECK_START_REL(L_, 0); | 10 | STACK_CHECK_START_REL(L_, 0); |
| 11 | StackIndex const _idx{ luaG_absindex(L_, idx_) }; | 11 | StackIndex const _idx{ luaW_absindex(L_, idx_) }; |
| 12 | UserValueIndex _nuv{ 0 }; | 12 | UserValueIndex _nuv{ 0 }; |
| 13 | do { | 13 | do { |
| 14 | // we don't know how many uservalues we are going to extract, there might be a lot... | 14 | // 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_) | |||
| 24 | // ################################################################################################# | 24 | // ################################################################################################# |
| 25 | 25 | ||
| 26 | // a small helper to obtain a module's table from the registry instead of relying on the presence of _G["<name>"] | 26 | // a small helper to obtain a module's table from the registry instead of relying on the presence of _G["<name>"] |
| 27 | LuaType luaG_getmodule(lua_State* const L_, std::string_view const& name_) | 27 | LuaType luaW_getmodule(lua_State* const L_, std::string_view const& name_) |
| 28 | { | 28 | { |
| 29 | STACK_CHECK_START_REL(L_, 0); | 29 | STACK_CHECK_START_REL(L_, 0); |
| 30 | LuaType _type{ luaG_getfield(L_, kIdxRegistry, LUA_LOADED_TABLE) }; // L_: _R._LOADED|nil | 30 | LuaType _type{ luaW_getfield(L_, kIdxRegistry, LUA_LOADED_TABLE) }; // L_: _R._LOADED|nil |
| 31 | if (_type != LuaType::TABLE) { // L_: _R._LOADED|nil | 31 | if (_type != LuaType::TABLE) { // L_: _R._LOADED|nil |
| 32 | STACK_CHECK(L_, 1); | 32 | STACK_CHECK(L_, 1); |
| 33 | return _type; | 33 | return _type; |
| 34 | } | 34 | } |
| 35 | _type = luaG_getfield(L_, kIdxTop, name_); // L_: _R._LOADED {module}|nil | 35 | _type = luaW_getfield(L_, kIdxTop, name_); // L_: _R._LOADED {module}|nil |
| 36 | lua_remove(L_, -2); // L_: {module}|nil | 36 | lua_remove(L_, -2); // L_: {module}|nil |
| 37 | STACK_CHECK(L_, 1); | 37 | STACK_CHECK(L_, 1); |
| 38 | return _type; | 38 | return _type; |
| @@ -52,7 +52,7 @@ int luaL_getsubtable(lua_State* const L_, StackIndex const idx_, char const* fna | |||
| 52 | return 1; /* table already there */ | 52 | return 1; /* table already there */ |
| 53 | } else { | 53 | } else { |
| 54 | lua_pop(L_, 1); /* remove previous result */ | 54 | lua_pop(L_, 1); /* remove previous result */ |
| 55 | StackIndex const _absidx{ luaG_absindex(L_, idx_) }; | 55 | StackIndex const _absidx{ luaW_absindex(L_, idx_) }; |
| 56 | lua_newtable(L_); | 56 | lua_newtable(L_); |
| 57 | lua_pushvalue(L_, -1); /* copy to be left at top */ | 57 | lua_pushvalue(L_, -1); /* copy to be left at top */ |
| 58 | lua_setfield(L_, _absidx, fname_); /* assign new table to field */ | 58 | 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_) | |||
| 136 | 136 | ||
| 137 | // break lexical order for that one because it's needed below | 137 | // break lexical order for that one because it's needed below |
| 138 | [[nodiscard]] | 138 | [[nodiscard]] |
| 139 | inline LuaType luaG_type(lua_State* const L_, StackIndex const idx_) | 139 | inline LuaType luaW_type(lua_State* const L_, StackIndex const idx_) |
| 140 | { | 140 | { |
| 141 | return static_cast<LuaType>(lua_type(L_, idx_)); | 141 | return static_cast<LuaType>(lua_type(L_, idx_)); |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | // ################################################################################################# | 144 | // ################################################################################################# |
| 145 | // ################################################################################################# | 145 | // ################################################################################################# |
| 146 | // All the compatibility wrappers we expose start with luaG_ | 146 | // All the compatibility wrappers we expose start with luaW_ |
| 147 | // ################################################################################################# | 147 | // ################################################################################################# |
| 148 | // ################################################################################################# | 148 | // ################################################################################################# |
| 149 | 149 | ||
| @@ -152,7 +152,7 @@ inline LuaType luaG_type(lua_State* const L_, StackIndex const idx_) | |||
| 152 | 152 | ||
| 153 | // a replacement of lua_tolstring | 153 | // a replacement of lua_tolstring |
| 154 | [[nodiscard]] | 154 | [[nodiscard]] |
| 155 | inline std::string_view luaG_tostring(lua_State* const L_, StackIndex const idx_) | 155 | inline std::string_view luaW_tostring(lua_State* const L_, StackIndex const idx_) |
| 156 | { | 156 | { |
| 157 | size_t _len{ 0 }; | 157 | size_t _len{ 0 }; |
| 158 | char const* _str{ lua_tolstring(L_, idx_, &_len) }; | 158 | 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_ | |||
| 160 | } | 160 | } |
| 161 | 161 | ||
| 162 | [[nodiscard]] | 162 | [[nodiscard]] |
| 163 | inline std::string_view luaG_checkstring(lua_State* const L_, StackIndex const idx_) | 163 | inline std::string_view luaW_checkstring(lua_State* const L_, StackIndex const idx_) |
| 164 | { | 164 | { |
| 165 | size_t _len{ 0 }; | 165 | size_t _len{ 0 }; |
| 166 | char const* _str{ luaL_checklstring(L_, idx_, &_len) }; | 166 | 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 | |||
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | [[nodiscard]] | 170 | [[nodiscard]] |
| 171 | inline std::string_view luaG_optstring(lua_State* const L_, StackIndex const idx_, std::string_view const& default_) | 171 | inline std::string_view luaW_optstring(lua_State* const L_, StackIndex const idx_, std::string_view const& default_) |
| 172 | { | 172 | { |
| 173 | if (lua_isnoneornil(L_, idx_)) { | 173 | if (lua_isnoneornil(L_, idx_)) { |
| 174 | return default_; | 174 | return default_; |
| @@ -179,13 +179,13 @@ inline std::string_view luaG_optstring(lua_State* const L_, StackIndex const idx | |||
| 179 | } | 179 | } |
| 180 | 180 | ||
| 181 | template <typename... EXTRA> | 181 | template <typename... EXTRA> |
| 182 | inline std::string_view luaG_pushstring(lua_State* const L_, std::string_view const& str_, EXTRA&&... extra_) | 182 | inline std::string_view luaW_pushstring(lua_State* const L_, std::string_view const& str_, EXTRA&&... extra_) |
| 183 | { | 183 | { |
| 184 | if constexpr (sizeof...(EXTRA) == 0) { | 184 | if constexpr (sizeof...(EXTRA) == 0) { |
| 185 | if constexpr (LUA_VERSION_NUM == 501) { | 185 | if constexpr (LUA_VERSION_NUM == 501) { |
| 186 | // lua_pushlstring doesn't return a value in Lua 5.1 | 186 | // lua_pushlstring doesn't return a value in Lua 5.1 |
| 187 | lua_pushlstring(L_, str_.data(), str_.size()); | 187 | lua_pushlstring(L_, str_.data(), str_.size()); |
| 188 | return luaG_tostring(L_, kIdxTop); | 188 | return luaW_tostring(L_, kIdxTop); |
| 189 | } else { | 189 | } else { |
| 190 | return std::string_view{ lua_pushlstring(L_, str_.data(), str_.size()), str_.size() }; | 190 | return std::string_view{ lua_pushlstring(L_, str_.data(), str_.size()), str_.size() }; |
| 191 | } | 191 | } |
| @@ -198,7 +198,7 @@ inline std::string_view luaG_pushstring(lua_State* const L_, std::string_view co | |||
| 198 | // ################################################################################################# | 198 | // ################################################################################################# |
| 199 | 199 | ||
| 200 | // use this in place of lua_absindex to save a function call | 200 | // use this in place of lua_absindex to save a function call |
| 201 | inline StackIndex luaG_absindex(lua_State* const L_, StackIndex const idx_) | 201 | inline StackIndex luaW_absindex(lua_State* const L_, StackIndex const idx_) |
| 202 | { | 202 | { |
| 203 | return StackIndex{ (idx_ >= 0 || idx_ <= kIdxRegistry) ? idx_ : StackIndex{ lua_gettop(L_) + idx_ + 1 } }; | 203 | return StackIndex{ (idx_ >= 0 || idx_ <= kIdxRegistry) ? idx_ : StackIndex{ lua_gettop(L_) + idx_ + 1 } }; |
| 204 | } | 204 | } |
| @@ -227,14 +227,14 @@ static inline int WrapLuaDump(LUA_DUMP f_, lua_State* const L_, lua_Writer const | |||
| 227 | 227 | ||
| 228 | // ------------------------------------------------------------------------------------------------- | 228 | // ------------------------------------------------------------------------------------------------- |
| 229 | 229 | ||
| 230 | static inline int luaG_dump(lua_State* const L_, lua_Writer const writer_, void* const data_, int const strip_) | 230 | static inline int luaW_dump(lua_State* const L_, lua_Writer const writer_, void* const data_, int const strip_) |
| 231 | { | 231 | { |
| 232 | return WrapLuaDump(lua_dump, L_, writer_, data_, strip_); | 232 | return WrapLuaDump(lua_dump, L_, writer_, data_, strip_); |
| 233 | } | 233 | } |
| 234 | 234 | ||
| 235 | // ################################################################################################# | 235 | // ################################################################################################# |
| 236 | 236 | ||
| 237 | UserValueCount luaG_getalluservalues(lua_State* L_, StackIndex idx_); | 237 | UserValueCount luaW_getalluservalues(lua_State* L_, StackIndex idx_); |
| 238 | 238 | ||
| 239 | // ################################################################################################# | 239 | // ################################################################################################# |
| 240 | 240 | ||
| @@ -272,7 +272,7 @@ static inline int WrapLuaGetField(LUA_GETFIELD f_, lua_State* const L_, StackInd | |||
| 272 | // ------------------------------------------------------------------------------------------------- | 272 | // ------------------------------------------------------------------------------------------------- |
| 273 | 273 | ||
| 274 | [[nodiscard]] | 274 | [[nodiscard]] |
| 275 | static inline LuaType luaG_getfield(lua_State* const L_, StackIndex const idx_, std::string_view const& name_) | 275 | static inline LuaType luaW_getfield(lua_State* const L_, StackIndex const idx_, std::string_view const& name_) |
| 276 | { | 276 | { |
| 277 | return static_cast<LuaType>(WrapLuaGetField(lua_getfield, L_, idx_, name_)); | 277 | return static_cast<LuaType>(WrapLuaGetField(lua_getfield, L_, idx_, name_)); |
| 278 | } | 278 | } |
| @@ -280,21 +280,21 @@ static inline LuaType luaG_getfield(lua_State* const L_, StackIndex const idx_, | |||
| 280 | // ################################################################################################# | 280 | // ################################################################################################# |
| 281 | 281 | ||
| 282 | [[nodiscard]] | 282 | [[nodiscard]] |
| 283 | LuaType luaG_getmodule(lua_State* L_, std::string_view const& name_); | 283 | LuaType luaW_getmodule(lua_State* L_, std::string_view const& name_); |
| 284 | 284 | ||
| 285 | // ################################################################################################# | 285 | // ################################################################################################# |
| 286 | 286 | ||
| 287 | template<typename ENUM> | 287 | template<typename ENUM> |
| 288 | requires std::is_enum_v<ENUM> | 288 | requires std::is_enum_v<ENUM> |
| 289 | [[nodiscard]] | 289 | [[nodiscard]] |
| 290 | ENUM luaG_optenum(lua_State* const L_, StackIndex const idx_, ENUM const def_) | 290 | ENUM luaW_optenum(lua_State* const L_, StackIndex const idx_, ENUM const def_) |
| 291 | { | 291 | { |
| 292 | return static_cast<ENUM>(luaL_optinteger(L_, idx_, static_cast<std::underlying_type_t<ENUM>>(def_))); | 292 | return static_cast<ENUM>(luaL_optinteger(L_, idx_, static_cast<std::underlying_type_t<ENUM>>(def_))); |
| 293 | } | 293 | } |
| 294 | 294 | ||
| 295 | // ################################################################################################# | 295 | // ################################################################################################# |
| 296 | 296 | ||
| 297 | inline void luaG_registerlibfuncs(lua_State* const L_, luaL_Reg const* funcs_) | 297 | inline void luaW_registerlibfuncs(lua_State* const L_, luaL_Reg const* funcs_) |
| 298 | { | 298 | { |
| 299 | // fake externs to make clang happy... | 299 | // fake externs to make clang happy... |
| 300 | extern void luaL_register(lua_State*, char const*, luaL_Reg const*); // Lua 5.1 | 300 | 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 | |||
| 353 | // ------------------------------------------------------------------------------------------------- | 353 | // ------------------------------------------------------------------------------------------------- |
| 354 | 354 | ||
| 355 | [[nodiscard]] | 355 | [[nodiscard]] |
| 356 | static inline LuaError luaG_resume(lua_State* const L_, lua_State* const from_, int const nargs_, int* const nresults_) | 356 | static inline LuaError luaW_resume(lua_State* const L_, lua_State* const from_, int const nargs_, int* const nresults_) |
| 357 | { | 357 | { |
| 358 | return ToLuaError(WrapLuaResume(lua_resume, L_, from_, nargs_, nresults_)); | 358 | return ToLuaError(WrapLuaResume(lua_resume, L_, from_, nargs_, nresults_)); |
| 359 | } | 359 | } |
| @@ -368,7 +368,7 @@ static inline LuaType WrapLuaRawget(LUA_RAWGET lua_rawget_, lua_State* const L_, | |||
| 368 | { | 368 | { |
| 369 | // until Lua 5.3, lua_rawget -> void | 369 | // until Lua 5.3, lua_rawget -> void |
| 370 | lua_rawget_(L_, idx_); | 370 | lua_rawget_(L_, idx_); |
| 371 | return luaG_type(L_, kIdxTop); | 371 | return luaW_type(L_, kIdxTop); |
| 372 | } | 372 | } |
| 373 | 373 | ||
| 374 | // ------------------------------------------------------------------------------------------------- | 374 | // ------------------------------------------------------------------------------------------------- |
| @@ -385,42 +385,42 @@ static inline LuaType WrapLuaRawget(LUA_RAWGET lua_rawget_, lua_State* const L_, | |||
| 385 | 385 | ||
| 386 | // ------------------------------------------------------------------------------------------------- | 386 | // ------------------------------------------------------------------------------------------------- |
| 387 | 387 | ||
| 388 | static inline LuaType luaG_rawget(lua_State* const L_, StackIndex const idx_) | 388 | static inline LuaType luaW_rawget(lua_State* const L_, StackIndex const idx_) |
| 389 | { | 389 | { |
| 390 | return WrapLuaRawget(lua_rawget, L_, idx_); | 390 | return WrapLuaRawget(lua_rawget, L_, idx_); |
| 391 | } | 391 | } |
| 392 | 392 | ||
| 393 | // ################################################################################################# | 393 | // ################################################################################################# |
| 394 | 394 | ||
| 395 | static inline LuaType luaG_rawgetfield(lua_State* const L_, StackIndex const idx_, std::string_view const& name_) | 395 | static inline LuaType luaW_rawgetfield(lua_State* const L_, StackIndex const idx_, std::string_view const& name_) |
| 396 | { | 396 | { |
| 397 | auto const _absIdx{ luaG_absindex(L_, idx_) }; | 397 | auto const _absIdx{ luaW_absindex(L_, idx_) }; |
| 398 | luaG_pushstring(L_, name_); // L_: ... t ... name_ | 398 | luaW_pushstring(L_, name_); // L_: ... t ... name_ |
| 399 | lua_rawget(L_, _absIdx); // L_: ... t ... <field> | 399 | lua_rawget(L_, _absIdx); // L_: ... t ... <field> |
| 400 | return luaG_type(L_, kIdxTop); | 400 | return luaW_type(L_, kIdxTop); |
| 401 | } | 401 | } |
| 402 | 402 | ||
| 403 | // ################################################################################################# | 403 | // ################################################################################################# |
| 404 | 404 | ||
| 405 | template <size_t N> | 405 | template <size_t N> |
| 406 | static inline void luaG_newlib(lua_State* const L_, luaL_Reg const (&funcs_)[N]) | 406 | static inline void luaW_newlib(lua_State* const L_, luaL_Reg const (&funcs_)[N]) |
| 407 | { | 407 | { |
| 408 | lua_createtable(L_, 0, N - 1); | 408 | lua_createtable(L_, 0, N - 1); |
| 409 | luaG_registerlibfuncs(L_, funcs_); | 409 | luaW_registerlibfuncs(L_, funcs_); |
| 410 | } | 410 | } |
| 411 | 411 | ||
| 412 | // ################################################################################################# | 412 | // ################################################################################################# |
| 413 | 413 | ||
| 414 | template <typename T> | 414 | template <typename T> |
| 415 | [[nodiscard]] | 415 | [[nodiscard]] |
| 416 | T* luaG_newuserdatauv(lua_State* const L_, UserValueCount const nuvalue_) | 416 | T* luaW_newuserdatauv(lua_State* const L_, UserValueCount const nuvalue_) |
| 417 | { | 417 | { |
| 418 | return static_cast<T*>(lua_newuserdatauv(L_, sizeof(T), nuvalue_)); | 418 | return static_cast<T*>(lua_newuserdatauv(L_, sizeof(T), nuvalue_)); |
| 419 | } | 419 | } |
| 420 | 420 | ||
| 421 | // ################################################################################################# | 421 | // ################################################################################################# |
| 422 | 422 | ||
| 423 | inline void luaG_pushglobaltable(lua_State* const L_) | 423 | inline void luaW_pushglobaltable(lua_State* const L_) |
| 424 | { | 424 | { |
| 425 | #ifdef LUA_GLOBALSINDEX // All flavors of Lua 5.1 | 425 | #ifdef LUA_GLOBALSINDEX // All flavors of Lua 5.1 |
| 426 | ::lua_pushvalue(L_, LUA_GLOBALSINDEX); | 426 | ::lua_pushvalue(L_, LUA_GLOBALSINDEX); |
| @@ -431,15 +431,15 @@ inline void luaG_pushglobaltable(lua_State* const L_) | |||
| 431 | 431 | ||
| 432 | // ################################################################################################# | 432 | // ################################################################################################# |
| 433 | 433 | ||
| 434 | inline void luaG_setfield(lua_State* const L_, StackIndex const idx_, char const* const k_) = delete; | 434 | inline void luaW_setfield(lua_State* const L_, StackIndex const idx_, char const* const k_) = delete; |
| 435 | inline void luaG_setfield(lua_State* const L_, StackIndex const idx_, std::string_view const& k_) | 435 | inline void luaW_setfield(lua_State* const L_, StackIndex const idx_, std::string_view const& k_) |
| 436 | { | 436 | { |
| 437 | lua_setfield(L_, idx_, k_.data()); | 437 | lua_setfield(L_, idx_, k_.data()); |
| 438 | } | 438 | } |
| 439 | 439 | ||
| 440 | // ################################################################################################# | 440 | // ################################################################################################# |
| 441 | 441 | ||
| 442 | inline void luaG_setmetatable(lua_State* const L_, std::string_view const& tname_) | 442 | inline void luaW_setmetatable(lua_State* const L_, std::string_view const& tname_) |
| 443 | { | 443 | { |
| 444 | // fake externs to make clang happy... | 444 | // fake externs to make clang happy... |
| 445 | if constexpr (LUA_VERSION_NUM > 501) { | 445 | if constexpr (LUA_VERSION_NUM > 501) { |
| @@ -456,7 +456,7 @@ inline void luaG_setmetatable(lua_State* const L_, std::string_view const& tname | |||
| 456 | // a small helper to extract a full userdata pointer from the stack in a safe way | 456 | // a small helper to extract a full userdata pointer from the stack in a safe way |
| 457 | template <typename T> | 457 | template <typename T> |
| 458 | [[nodiscard]] | 458 | [[nodiscard]] |
| 459 | T* luaG_tofulluserdata(lua_State* const L_, StackIndex const index_) | 459 | T* luaW_tofulluserdata(lua_State* const L_, StackIndex const index_) |
| 460 | { | 460 | { |
| 461 | LUA_ASSERT(L_, lua_isnil(L_, index_) || lua_type(L_, index_) == LUA_TUSERDATA); | 461 | LUA_ASSERT(L_, lua_isnil(L_, index_) || lua_type(L_, index_) == LUA_TUSERDATA); |
| 462 | return static_cast<T*>(lua_touserdata(L_, index_)); | 462 | return static_cast<T*>(lua_touserdata(L_, index_)); |
| @@ -466,7 +466,7 @@ T* luaG_tofulluserdata(lua_State* const L_, StackIndex const index_) | |||
| 466 | 466 | ||
| 467 | template <typename T> | 467 | template <typename T> |
| 468 | [[nodiscard]] | 468 | [[nodiscard]] |
| 469 | auto luaG_tolightuserdata(lua_State* const L_, StackIndex const index_) | 469 | auto luaW_tolightuserdata(lua_State* const L_, StackIndex const index_) |
| 470 | { | 470 | { |
| 471 | LUA_ASSERT(L_, lua_isnil(L_, index_) || lua_islightuserdata(L_, index_)); | 471 | LUA_ASSERT(L_, lua_isnil(L_, index_) || lua_islightuserdata(L_, index_)); |
| 472 | if constexpr (std::is_pointer_v<T>) { | 472 | if constexpr (std::is_pointer_v<T>) { |
| @@ -479,7 +479,7 @@ auto luaG_tolightuserdata(lua_State* const L_, StackIndex const index_) | |||
| 479 | // ------------------------------------------------------------------------------------------------- | 479 | // ------------------------------------------------------------------------------------------------- |
| 480 | 480 | ||
| 481 | [[nodiscard]] | 481 | [[nodiscard]] |
| 482 | inline std::string_view luaG_typename(lua_State* const L_, LuaType const t_) | 482 | inline std::string_view luaW_typename(lua_State* const L_, LuaType const t_) |
| 483 | { | 483 | { |
| 484 | return lua_typename(L_, static_cast<int>(t_)); | 484 | return lua_typename(L_, static_cast<int>(t_)); |
| 485 | } | 485 | } |
| @@ -487,7 +487,7 @@ inline std::string_view luaG_typename(lua_State* const L_, LuaType const t_) | |||
| 487 | // ------------------------------------------------------------------------------------------------- | 487 | // ------------------------------------------------------------------------------------------------- |
| 488 | 488 | ||
| 489 | [[nodiscard]] | 489 | [[nodiscard]] |
| 490 | inline std::string_view luaG_typename(lua_State* const L_, StackIndex const idx_) | 490 | inline std::string_view luaW_typename(lua_State* const L_, StackIndex const idx_) |
| 491 | { | 491 | { |
| 492 | return luaG_typename(L_, luaG_type(L_, idx_)); | 492 | return luaW_typename(L_, luaW_type(L_, idx_)); |
| 493 | } | 493 | } |
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 { | |||
| 75 | lua_rawget(L_, -2); // L_: {} b | 75 | lua_rawget(L_, -2); // L_: {} b |
| 76 | } | 76 | } |
| 77 | lua_remove(L_, -2); // L_: a|b | 77 | lua_remove(L_, -2); // L_: a|b |
| 78 | LuaType const _type{ luaG_type(L_, kIdxTop) }; | 78 | LuaType const _type{ luaW_type(L_, kIdxTop) }; |
| 79 | if (_type != LuaType::NIL && _type != expectedType_) { | 79 | if (_type != LuaType::NIL && _type != expectedType_) { |
| 80 | raise_luaL_error(L_, "INTERNAL ERROR: Unexpected value."); | 80 | raise_luaL_error(L_, "INTERNAL ERROR: Unexpected value."); |
| 81 | } | 81 | } |
| @@ -103,7 +103,7 @@ namespace { | |||
| 103 | [[nodiscard]] | 103 | [[nodiscard]] |
| 104 | int DeepFactory::DeepGC(lua_State* const L_) | 104 | int DeepFactory::DeepGC(lua_State* const L_) |
| 105 | { | 105 | { |
| 106 | DeepPrelude* const* const _proxy{ luaG_tofulluserdata<DeepPrelude*>(L_, StackIndex{ 1 }) }; | 106 | DeepPrelude* const* const _proxy{ luaW_tofulluserdata<DeepPrelude*>(L_, StackIndex{ 1 }) }; |
| 107 | DeepPrelude* const _p{ *_proxy }; | 107 | DeepPrelude* const _p{ *_proxy }; |
| 108 | 108 | ||
| 109 | // can work without a universe if creating a deep userdata from some external C module when Lanes isn't loaded | 109 | // 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 | |||
| 150 | { | 150 | { |
| 151 | // when looking inside a keeper, we are 100% sure the object is a deep userdata | 151 | // when looking inside a keeper, we are 100% sure the object is a deep userdata |
| 152 | if (mode_ == LookupMode::FromKeeper) { | 152 | if (mode_ == LookupMode::FromKeeper) { |
| 153 | DeepPrelude* const _proxy{ *luaG_tofulluserdata<DeepPrelude*>(L_, index_) }; | 153 | DeepPrelude* const _proxy{ *luaW_tofulluserdata<DeepPrelude*>(L_, index_) }; |
| 154 | // we can (and must) cast and fetch the internally stored factory | 154 | // we can (and must) cast and fetch the internally stored factory |
| 155 | return &_proxy->factory; | 155 | return &_proxy->factory; |
| 156 | } else { | 156 | } else { |
| @@ -167,7 +167,7 @@ DeepFactory* DeepFactory::LookupFactory(lua_State* const L_, StackIndex const in | |||
| 167 | // replace metatable with the factory pointer, if it is actually a deep userdata | 167 | // replace metatable with the factory pointer, if it is actually a deep userdata |
| 168 | LookupDeep(L_, LuaType::LIGHTUSERDATA); // L_: deep ... factory|nil | 168 | LookupDeep(L_, LuaType::LIGHTUSERDATA); // L_: deep ... factory|nil |
| 169 | 169 | ||
| 170 | DeepFactory* const _ret{ luaG_tolightuserdata<DeepFactory>(L_, kIdxTop) }; // nullptr if not a userdata | 170 | DeepFactory* const _ret{ luaW_tolightuserdata<DeepFactory>(L_, kIdxTop) }; // nullptr if not a userdata |
| 171 | lua_pop(L_, 1); | 171 | lua_pop(L_, 1); |
| 172 | STACK_CHECK(L_, 0); | 172 | STACK_CHECK(L_, 0); |
| 173 | return _ret; | 173 | return _ret; |
| @@ -190,7 +190,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
| 190 | 190 | ||
| 191 | // Check if a proxy already exists | 191 | // Check if a proxy already exists |
| 192 | lua_pushlightuserdata(L_, prelude_); // L_: DPC deep | 192 | lua_pushlightuserdata(L_, prelude_); // L_: DPC deep |
| 193 | if (luaG_rawget(L_, StackIndex{ -2 }) != LuaType::NIL) { // L_: DPC proxy | 193 | if (luaW_rawget(L_, StackIndex{ -2 }) != LuaType::NIL) { // L_: DPC proxy |
| 194 | lua_remove(L_, -2); // L_: proxy | 194 | lua_remove(L_, -2); // L_: proxy |
| 195 | STACK_CHECK(L_, 1); | 195 | STACK_CHECK(L_, 1); |
| 196 | return; | 196 | return; |
| @@ -202,7 +202,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
| 202 | STACK_GROW(L_, 7); | 202 | STACK_GROW(L_, 7); |
| 203 | 203 | ||
| 204 | // a new full userdata, fitted with the specified number of uservalue slots (always 1 for Lua < 5.4) | 204 | // a new full userdata, fitted with the specified number of uservalue slots (always 1 for Lua < 5.4) |
| 205 | DeepPrelude** const _proxy{ luaG_newuserdatauv<DeepPrelude*>(L_, nuv_) }; // L_: DPC proxy | 205 | DeepPrelude** const _proxy{ luaW_newuserdatauv<DeepPrelude*>(L_, nuv_) }; // L_: DPC proxy |
| 206 | LUA_ASSERT(L_, _proxy); | 206 | LUA_ASSERT(L_, _proxy); |
| 207 | *_proxy = prelude_; | 207 | *_proxy = prelude_; |
| 208 | prelude_->refcount.fetch_add(1, std::memory_order_relaxed); // one more proxy pointing to this deep data | 208 | 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_, | |||
| 223 | raise_luaL_error(errL_, "Bad DeepFactory::createMetatable overload: unexpected pushed value"); | 223 | raise_luaL_error(errL_, "Bad DeepFactory::createMetatable overload: unexpected pushed value"); |
| 224 | } | 224 | } |
| 225 | // if the metatable contains a __gc, we will call it from our own | 225 | // if the metatable contains a __gc, we will call it from our own |
| 226 | std::ignore = luaG_rawgetfield(L_, kIdxTop, "__gc"); // L_: DPC proxy metatable __gc | 226 | std::ignore = luaW_rawgetfield(L_, kIdxTop, "__gc"); // L_: DPC proxy metatable __gc |
| 227 | } else { | 227 | } else { |
| 228 | // keepers need a minimal metatable that only contains our own __gc | 228 | // keepers need a minimal metatable that only contains our own __gc |
| 229 | lua_createtable(L_, 0, 1); // L_: DPC proxy metatable | 229 | lua_createtable(L_, 0, 1); // L_: DPC proxy metatable |
| @@ -251,8 +251,8 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
| 251 | raise_luaL_error(errL_, "lanes receiving deep userdata should register the 'package' library"); | 251 | raise_luaL_error(errL_, "lanes receiving deep userdata should register the 'package' library"); |
| 252 | } | 252 | } |
| 253 | 253 | ||
| 254 | luaG_pushstring(L_, _modname); // L_: DPC proxy metatable require() "module" | 254 | luaW_pushstring(L_, _modname); // L_: DPC proxy metatable require() "module" |
| 255 | if (luaG_getfield(L_, kIdxRegistry, LUA_LOADED_TABLE) != LuaType::TABLE) { // L_: DPC proxy metatable require() "module" _R._LOADED | 255 | if (luaW_getfield(L_, kIdxRegistry, LUA_LOADED_TABLE) != LuaType::TABLE) { // L_: DPC proxy metatable require() "module" _R._LOADED |
| 256 | // no L.registry._LOADED; can this ever happen? | 256 | // no L.registry._LOADED; can this ever happen? |
| 257 | lua_pop(L_, 6); // L_: | 257 | lua_pop(L_, 6); // L_: |
| 258 | raise_luaL_error(errL_, "unexpected error while requiring a module identified by DeepFactory::moduleName"); | 258 | 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_, | |||
| 270 | LuaError const _require_result{ lua_pcall(L_, 1, 0, 0) }; // L_: DPC proxy metatable error? | 270 | LuaError const _require_result{ lua_pcall(L_, 1, 0, 0) }; // L_: DPC proxy metatable error? |
| 271 | if (_require_result != LuaError::OK) { | 271 | if (_require_result != LuaError::OK) { |
| 272 | // failed, raise the error in the proper state | 272 | // failed, raise the error in the proper state |
| 273 | raise_luaL_error(errL_, luaG_tostring(L_, kIdxTop)); | 273 | raise_luaL_error(errL_, luaW_tostring(L_, kIdxTop)); |
| 274 | } | 274 | } |
| 275 | } | 275 | } |
| 276 | } else { // already loaded, we are happy | 276 | } else { // already loaded, we are happy |
| @@ -279,7 +279,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
| 279 | } | 279 | } |
| 280 | } | 280 | } |
| 281 | STACK_CHECK(L_, 3); // L_: DPC proxy metatable | 281 | STACK_CHECK(L_, 3); // L_: DPC proxy metatable |
| 282 | LUA_ASSERT(L_, luaG_type(L_, StackIndex{ -2 }) == LuaType::USERDATA); | 282 | LUA_ASSERT(L_, luaW_type(L_, StackIndex{ -2 }) == LuaType::USERDATA); |
| 283 | LUA_ASSERT(L_, lua_istable(L_, -1)); | 283 | LUA_ASSERT(L_, lua_istable(L_, -1)); |
| 284 | lua_setmetatable(L_, -2); // L_: DPC proxy | 284 | lua_setmetatable(L_, -2); // L_: DPC proxy |
| 285 | 285 | ||
| @@ -288,7 +288,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
| 288 | lua_pushvalue(L_, -2); // L_: DPC proxy deep proxy | 288 | lua_pushvalue(L_, -2); // L_: DPC proxy deep proxy |
| 289 | lua_rawset(L_, -4); // L_: DPC proxy | 289 | lua_rawset(L_, -4); // L_: DPC proxy |
| 290 | lua_remove(L_, -2); // L_: proxy | 290 | lua_remove(L_, -2); // L_: proxy |
| 291 | LUA_ASSERT(L_, luaG_type(L_, kIdxTop) == LuaType::USERDATA); | 291 | LUA_ASSERT(L_, luaW_type(L_, kIdxTop) == LuaType::USERDATA); |
| 292 | STACK_CHECK(L_, 1); | 292 | STACK_CHECK(L_, 1); |
| 293 | } | 293 | } |
| 294 | 294 | ||
| @@ -305,7 +305,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
| 305 | * Reference counting and true userdata proxying are taken care of for the actual data type. | 305 | * Reference counting and true userdata proxying are taken care of for the actual data type. |
| 306 | * | 306 | * |
| 307 | * Types using the deep userdata system (and only those!) can be passed between | 307 | * Types using the deep userdata system (and only those!) can be passed between |
| 308 | * separate Lua states via 'luaG_inter_move()'. | 308 | * separate Lua states via 'luaW_inter_move()'. |
| 309 | * | 309 | * |
| 310 | * Returns: 'proxy' userdata for accessing the deep data via 'DeepFactory::toDeep()' | 310 | * Returns: 'proxy' userdata for accessing the deep data via 'DeepFactory::toDeep()' |
| 311 | */ | 311 | */ |
| @@ -382,7 +382,7 @@ DeepPrelude* DeepFactory::toDeep(lua_State* const L_, StackIndex const index_) c | |||
| 382 | } | 382 | } |
| 383 | STACK_CHECK(L_, 0); | 383 | STACK_CHECK(L_, 0); |
| 384 | 384 | ||
| 385 | DeepPrelude** const _proxy{ luaG_tofulluserdata<DeepPrelude*>(L_, index_) }; | 385 | DeepPrelude** const _proxy{ luaW_tofulluserdata<DeepPrelude*>(L_, index_) }; |
| 386 | return *_proxy; | 386 | return *_proxy; |
| 387 | } | 387 | } |
| 388 | 388 | ||
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_) | |||
| 93 | [[nodiscard]] | 93 | [[nodiscard]] |
| 94 | std::string_view InterCopyContext::findLookupName() const | 94 | std::string_view InterCopyContext::findLookupName() const |
| 95 | { | 95 | { |
| 96 | LUA_ASSERT(L1, lua_isfunction(L1, L1_i) || lua_istable(L1, L1_i) || luaG_type(L1, L1_i) == LuaType::USERDATA); | 96 | LUA_ASSERT(L1, lua_isfunction(L1, L1_i) || lua_istable(L1, L1_i) || luaW_type(L1, L1_i) == LuaType::USERDATA); |
| 97 | STACK_CHECK_START_REL(L1, 0); // L1: ... v ... | 97 | STACK_CHECK_START_REL(L1, 0); // L1: ... v ... |
| 98 | STACK_GROW(L1, 3); // up to 3 slots are necessary on error | 98 | STACK_GROW(L1, 3); // up to 3 slots are necessary on error |
| 99 | if (mode == LookupMode::FromKeeper) { | 99 | if (mode == LookupMode::FromKeeper) { |
| @@ -114,7 +114,7 @@ std::string_view InterCopyContext::findLookupName() const | |||
| 114 | lua_pushvalue(L1, L1_i); // L1: ... v ... {} v | 114 | lua_pushvalue(L1, L1_i); // L1: ... v ... {} v |
| 115 | lua_rawget(L1, -2); // L1: ... v ... {} "f.q.n" | 115 | lua_rawget(L1, -2); // L1: ... v ... {} "f.q.n" |
| 116 | } | 116 | } |
| 117 | std::string_view _fqn{ luaG_tostring(L1, kIdxTop) }; | 117 | std::string_view _fqn{ luaW_tostring(L1, kIdxTop) }; |
| 118 | DEBUGSPEW_CODE(DebugSpew(U) << "function [C] " << _fqn << std::endl); | 118 | DEBUGSPEW_CODE(DebugSpew(U) << "function [C] " << _fqn << std::endl); |
| 119 | // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database | 119 | // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database |
| 120 | lua_pop(L1, (mode == LookupMode::FromKeeper) ? 1 : 2); // L1: ... v ... | 120 | lua_pop(L1, (mode == LookupMode::FromKeeper) ? 1 : 2); // L1: ... v ... |
| @@ -122,12 +122,12 @@ std::string_view InterCopyContext::findLookupName() const | |||
| 122 | if (_fqn.empty() && !lua_istable(L1, L1_i)) { // raise an error if we try to send an unknown function/userdata (but not for tables) | 122 | if (_fqn.empty() && !lua_istable(L1, L1_i)) { // raise an error if we try to send an unknown function/userdata (but not for tables) |
| 123 | // try to discover the name of the function/userdata we want to send | 123 | // try to discover the name of the function/userdata we want to send |
| 124 | kLaneNameRegKey.pushValue(L1); // L1: ... v ... lane_name | 124 | kLaneNameRegKey.pushValue(L1); // L1: ... v ... lane_name |
| 125 | std::string_view const _from{ luaG_tostring(L1, kIdxTop) }; | 125 | std::string_view const _from{ luaW_tostring(L1, kIdxTop) }; |
| 126 | lua_pushcfunction(L1, LG_nameof); // L1: ... v ... lane_name LG_nameof | 126 | lua_pushcfunction(L1, LG_nameof); // L1: ... v ... lane_name LG_nameof |
| 127 | lua_pushvalue(L1, L1_i); // L1: ... v ... lane_name LG_nameof t | 127 | lua_pushvalue(L1, L1_i); // L1: ... v ... lane_name LG_nameof t |
| 128 | lua_call(L1, 1, 2); // L1: ... v ... lane_name "type" "name"|nil | 128 | lua_call(L1, 1, 2); // L1: ... v ... lane_name "type" "name"|nil |
| 129 | StackIndex const _indexTypeWhat{ -2 }; | 129 | StackIndex const _indexTypeWhat{ -2 }; |
| 130 | std::string_view const _typewhat{ (luaG_type(L1, _indexTypeWhat) == LuaType::STRING) ? luaG_tostring(L1, _indexTypeWhat) : luaG_typename(L1, _indexTypeWhat) }; | 130 | std::string_view const _typewhat{ (luaW_type(L1, _indexTypeWhat) == LuaType::STRING) ? luaW_tostring(L1, _indexTypeWhat) : luaW_typename(L1, _indexTypeWhat) }; |
| 131 | // second return value can be nil if the table was not found | 131 | // second return value can be nil if the table was not found |
| 132 | // probable reason: the function was removed from the source Lua state before Lanes was required. | 132 | // probable reason: the function was removed from the source Lua state before Lanes was required. |
| 133 | std::string_view _what, _gotchaA, _gotchaB; | 133 | std::string_view _what, _gotchaA, _gotchaB; |
| @@ -139,7 +139,7 @@ std::string_view InterCopyContext::findLookupName() const | |||
| 139 | _gotchaA = ""; | 139 | _gotchaA = ""; |
| 140 | _gotchaB = ""; | 140 | _gotchaB = ""; |
| 141 | StackIndex const _indexWhat{ kIdxTop }; | 141 | StackIndex const _indexWhat{ kIdxTop }; |
| 142 | _what = (luaG_type(L1, _indexWhat) == LuaType::STRING) ? luaG_tostring(L1, _indexWhat) : luaG_typename(L1, _indexWhat); | 142 | _what = (luaW_type(L1, _indexWhat) == LuaType::STRING) ? luaW_tostring(L1, _indexWhat) : luaW_typename(L1, _indexWhat); |
| 143 | } | 143 | } |
| 144 | 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()); | 144 | 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()); |
| 145 | } | 145 | } |
| @@ -158,7 +158,7 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull }; | |||
| 158 | [[nodiscard]] | 158 | [[nodiscard]] |
| 159 | static lua_Integer get_mt_id(Universe* const U_, lua_State* const L_, StackIndex const idx_) | 159 | static lua_Integer get_mt_id(Universe* const U_, lua_State* const L_, StackIndex const idx_) |
| 160 | { | 160 | { |
| 161 | StackIndex const _absidx{ luaG_absindex(L_, idx_) }; | 161 | StackIndex const _absidx{ luaW_absindex(L_, idx_) }; |
| 162 | 162 | ||
| 163 | STACK_GROW(L_, 3); | 163 | STACK_GROW(L_, 3); |
| 164 | 164 | ||
| @@ -199,7 +199,7 @@ void InterCopyContext::copyFunction() const | |||
| 199 | STACK_GROW(L1, 2); | 199 | STACK_GROW(L1, 2); |
| 200 | STACK_CHECK_START_REL(L1, 0); | 200 | STACK_CHECK_START_REL(L1, 0); |
| 201 | 201 | ||
| 202 | // 'luaG_dump()' needs the function at top of stack | 202 | // 'luaW_dump()' needs the function at top of stack |
| 203 | // if already on top of the stack, no need to push again | 203 | // if already on top of the stack, no need to push again |
| 204 | bool const _needToPush{ L1_i != lua_gettop(L1) }; | 204 | bool const _needToPush{ L1_i != lua_gettop(L1) }; |
| 205 | if (_needToPush) { | 205 | if (_needToPush) { |
| @@ -212,7 +212,7 @@ void InterCopyContext::copyFunction() const | |||
| 212 | // not sure this could ever fail but for memory shortage reasons | 212 | // not sure this could ever fail but for memory shortage reasons |
| 213 | // last argument is Lua 5.4-specific (no stripping) | 213 | // last argument is Lua 5.4-specific (no stripping) |
| 214 | luaL_Buffer B{}; | 214 | luaL_Buffer B{}; |
| 215 | if (luaG_dump(L1, buf_writer, &B, U->stripFunctions) != 0) { | 215 | if (luaW_dump(L1, buf_writer, &B, U->stripFunctions) != 0) { |
| 216 | raise_luaL_error(getErrL(), "internal error: function dump failed."); | 216 | raise_luaL_error(getErrL(), "internal error: function dump failed."); |
| 217 | } | 217 | } |
| 218 | 218 | ||
| @@ -240,7 +240,7 @@ void InterCopyContext::copyFunction() const | |||
| 240 | } | 240 | } |
| 241 | 241 | ||
| 242 | { | 242 | { |
| 243 | std::string_view const _bytecode{ luaG_tostring(L1, kIdxTop) }; // L1: ... b | 243 | std::string_view const _bytecode{ luaW_tostring(L1, kIdxTop) }; // L1: ... b |
| 244 | LUA_ASSERT(L1, !_bytecode.empty()); | 244 | LUA_ASSERT(L1, !_bytecode.empty()); |
| 245 | STACK_GROW(L2, 2); | 245 | STACK_GROW(L2, 2); |
| 246 | // Note: Line numbers seem to be taken precisely from the | 246 | // Note: Line numbers seem to be taken precisely from the |
| @@ -278,12 +278,12 @@ void InterCopyContext::copyFunction() const | |||
| 278 | { | 278 | { |
| 279 | InterCopyContext _c{ U, L2, L1, L2_cache_i, {}, VT::NORMAL, mode, {} }; | 279 | InterCopyContext _c{ U, L2, L1, L2_cache_i, {}, VT::NORMAL, mode, {} }; |
| 280 | // if we encounter an upvalue equal to the global table in the source, bind it to the destination's global table | 280 | // if we encounter an upvalue equal to the global table in the source, bind it to the destination's global table |
| 281 | luaG_pushglobaltable(L1); // L1: ... _G | 281 | luaW_pushglobaltable(L1); // L1: ... _G |
| 282 | for (char const* _upname{}; (_upname = lua_getupvalue(L1, L1_i, 1 + _n)); ++_n) { // L1: ... _G up[n] | 282 | for (char const* _upname{}; (_upname = lua_getupvalue(L1, L1_i, 1 + _n)); ++_n) { // L1: ... _G up[n] |
| 283 | DEBUGSPEW_CODE(DebugSpew(U) << "UPNAME[" << _n << "]: " << _c.name << " -> "); | 283 | DEBUGSPEW_CODE(DebugSpew(U) << "UPNAME[" << _n << "]: " << _c.name << " -> "); |
| 284 | if (lua_rawequal(L1, -1, -2)) { // is the upvalue equal to the global table? | 284 | if (lua_rawequal(L1, -1, -2)) { // is the upvalue equal to the global table? |
| 285 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "pushing destination global scope" << std::endl); | 285 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "pushing destination global scope" << std::endl); |
| 286 | luaG_pushglobaltable(L2); // L2: ... {cache} ... function <upvalues> | 286 | luaW_pushglobaltable(L2); // L2: ... {cache} ... function <upvalues> |
| 287 | } else { | 287 | } else { |
| 288 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "copying value" << std::endl); | 288 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "copying value" << std::endl); |
| 289 | _c.name = _upname; | 289 | _c.name = _upname; |
| @@ -327,7 +327,7 @@ void InterCopyContext::lookupNativeFunction() const | |||
| 327 | 327 | ||
| 328 | case LookupMode::ToKeeper: | 328 | case LookupMode::ToKeeper: |
| 329 | // push a sentinel closure that holds the lookup name as upvalue | 329 | // push a sentinel closure that holds the lookup name as upvalue |
| 330 | luaG_pushstring(L2, _fqn); // L1: ... f ... L2: "f.q.n" | 330 | luaW_pushstring(L2, _fqn); // L1: ... f ... L2: "f.q.n" |
| 331 | lua_pushcclosure(L2, func_lookup_sentinel, 1); // L1: ... f ... L2: f | 331 | lua_pushcclosure(L2, func_lookup_sentinel, 1); // L1: ... f ... L2: f |
| 332 | break; | 332 | break; |
| 333 | 333 | ||
| @@ -336,16 +336,16 @@ void InterCopyContext::lookupNativeFunction() const | |||
| 336 | kLookupRegKey.pushValue(L2); // L1: ... f ... L2: {} | 336 | kLookupRegKey.pushValue(L2); // L1: ... f ... L2: {} |
| 337 | STACK_CHECK(L2, 1); | 337 | STACK_CHECK(L2, 1); |
| 338 | LUA_ASSERT(L1, lua_istable(L2, -1)); | 338 | LUA_ASSERT(L1, lua_istable(L2, -1)); |
| 339 | luaG_pushstring(L2, _fqn); // L1: ... f ... L2: {} "f.q.n" | 339 | luaW_pushstring(L2, _fqn); // L1: ... f ... L2: {} "f.q.n" |
| 340 | LuaType const _objType{ luaG_rawget(L2, StackIndex{ -2 }) }; // L1: ... f ... L2: {} f | 340 | LuaType const _objType{ luaW_rawget(L2, StackIndex{ -2 }) }; // L1: ... f ... L2: {} f |
| 341 | // nil means we don't know how to transfer stuff: user should do something | 341 | // nil means we don't know how to transfer stuff: user should do something |
| 342 | // anything other than function or table should not happen! | 342 | // anything other than function or table should not happen! |
| 343 | if (_objType != LuaType::FUNCTION && _objType != LuaType::TABLE && _objType != LuaType::USERDATA) { | 343 | if (_objType != LuaType::FUNCTION && _objType != LuaType::TABLE && _objType != LuaType::USERDATA) { |
| 344 | kLaneNameRegKey.pushValue(L1); // L1: ... f ... lane_name | 344 | kLaneNameRegKey.pushValue(L1); // L1: ... f ... lane_name |
| 345 | std::string_view const _from{ luaG_tostring(L1, kIdxTop) }; | 345 | std::string_view const _from{ luaW_tostring(L1, kIdxTop) }; |
| 346 | lua_pop(L1, 1); // L1: ... f ... | 346 | lua_pop(L1, 1); // L1: ... f ... |
| 347 | kLaneNameRegKey.pushValue(L2); // L1: ... f ... L2: {} f lane_name | 347 | kLaneNameRegKey.pushValue(L2); // L1: ... f ... L2: {} f lane_name |
| 348 | std::string_view const _to{ luaG_tostring(L2, kIdxTop) }; | 348 | std::string_view const _to{ luaW_tostring(L2, kIdxTop) }; |
| 349 | lua_pop(L2, 1); // L2: {} f | 349 | lua_pop(L2, 1); // L2: {} f |
| 350 | raise_luaL_error( | 350 | raise_luaL_error( |
| 351 | getErrL(), | 351 | getErrL(), |
| @@ -368,7 +368,7 @@ void InterCopyContext::lookupNativeFunction() const | |||
| 368 | // Always pushes a function to 'L2'. | 368 | // Always pushes a function to 'L2'. |
| 369 | void InterCopyContext::copyCachedFunction() const | 369 | void InterCopyContext::copyCachedFunction() const |
| 370 | { | 370 | { |
| 371 | FuncSubType const _funcSubType{ luaG_getfuncsubtype(L1, L1_i) }; | 371 | FuncSubType const _funcSubType{ luaW_getfuncsubtype(L1, L1_i) }; |
| 372 | if (_funcSubType == FuncSubType::Bytecode) { | 372 | if (_funcSubType == FuncSubType::Bytecode) { |
| 373 | void* const _aspointer{ const_cast<void*>(lua_topointer(L1, L1_i)) }; | 373 | void* const _aspointer{ const_cast<void*>(lua_topointer(L1, L1_i)) }; |
| 374 | // TODO: Merge this and same code for tables | 374 | // TODO: Merge this and same code for tables |
| @@ -386,10 +386,10 @@ void InterCopyContext::copyCachedFunction() const | |||
| 386 | // push a light userdata uniquely representing the function | 386 | // push a light userdata uniquely representing the function |
| 387 | lua_pushlightuserdata(L2, _aspointer); // L2: ... {cache} ... p | 387 | lua_pushlightuserdata(L2, _aspointer); // L2: ... {cache} ... p |
| 388 | 388 | ||
| 389 | //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaG_tostring(L2, -1) << " >>" << std::endl); | 389 | //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaW_tostring(L2, -1) << " >>" << std::endl); |
| 390 | 390 | ||
| 391 | lua_pushvalue(L2, -1); // L2: ... {cache} ... p p | 391 | lua_pushvalue(L2, -1); // L2: ... {cache} ... p p |
| 392 | if (luaG_rawget(L2, L2_cache_i) == LuaType::NIL) { // function is unknown // L2: ... {cache} ... p function|nil|true | 392 | if (luaW_rawget(L2, L2_cache_i) == LuaType::NIL) { // function is unknown // L2: ... {cache} ... p function|nil|true |
| 393 | lua_pop(L2, 1); // L2: ... {cache} ... p | 393 | lua_pop(L2, 1); // L2: ... {cache} ... p |
| 394 | 394 | ||
| 395 | // Set to 'true' for the duration of creation; need to find self-references | 395 | // Set to 'true' for the duration of creation; need to find self-references |
| @@ -405,7 +405,7 @@ void InterCopyContext::copyCachedFunction() const | |||
| 405 | } else { // function is native/LuaJIT: no need to cache | 405 | } else { // function is native/LuaJIT: no need to cache |
| 406 | lookupNativeFunction(); // L2: ... {cache} ... function | 406 | lookupNativeFunction(); // L2: ... {cache} ... function |
| 407 | // if the function was in fact a lookup sentinel, we can either get a function, table or full userdata here | 407 | // if the function was in fact a lookup sentinel, we can either get a function, table or full userdata here |
| 408 | LUA_ASSERT(L1, lua_isfunction(L2, kIdxTop) || lua_istable(L2, kIdxTop) || luaG_type(L2, kIdxTop) == LuaType::USERDATA); | 408 | LUA_ASSERT(L1, lua_isfunction(L2, kIdxTop) || lua_istable(L2, kIdxTop) || luaW_type(L2, kIdxTop) == LuaType::USERDATA); |
| 409 | } | 409 | } |
| 410 | } | 410 | } |
| 411 | 411 | ||
| @@ -430,7 +430,7 @@ bool InterCopyContext::lookupTable() const | |||
| 430 | 430 | ||
| 431 | case LookupMode::ToKeeper: | 431 | case LookupMode::ToKeeper: |
| 432 | // push a sentinel closure that holds the lookup name as upvalue | 432 | // push a sentinel closure that holds the lookup name as upvalue |
| 433 | luaG_pushstring(L2, _fqn); // L1: ... t ... L2: "f.q.n" | 433 | luaW_pushstring(L2, _fqn); // L1: ... t ... L2: "f.q.n" |
| 434 | lua_pushcclosure(L2, table_lookup_sentinel, 1); // L1: ... t ... L2: f | 434 | lua_pushcclosure(L2, table_lookup_sentinel, 1); // L1: ... t ... L2: f |
| 435 | break; | 435 | break; |
| 436 | 436 | ||
| @@ -439,26 +439,26 @@ bool InterCopyContext::lookupTable() const | |||
| 439 | kLookupRegKey.pushValue(L2); // L1: ... t ... L2: {} | 439 | kLookupRegKey.pushValue(L2); // L1: ... t ... L2: {} |
| 440 | STACK_CHECK(L2, 1); | 440 | STACK_CHECK(L2, 1); |
| 441 | LUA_ASSERT(L1, lua_istable(L2, -1)); | 441 | LUA_ASSERT(L1, lua_istable(L2, -1)); |
| 442 | luaG_pushstring(L2, _fqn); // L2: {} "f.q.n" | 442 | luaW_pushstring(L2, _fqn); // L2: {} "f.q.n" |
| 443 | // we accept destination lookup failures in the case of transfering the Lanes body function (this will result in the source table being cloned instead) | 443 | // we accept destination lookup failures in the case of transfering the Lanes body function (this will result in the source table being cloned instead) |
| 444 | // but not when we extract something out of a keeper, as there is nothing to clone! | 444 | // but not when we extract something out of a keeper, as there is nothing to clone! |
| 445 | if (luaG_rawget(L2, StackIndex{ -2 }) == LuaType::NIL && mode == LookupMode::LaneBody) { // L2: {} t | 445 | if (luaW_rawget(L2, StackIndex{ -2 }) == LuaType::NIL && mode == LookupMode::LaneBody) { // L2: {} t |
| 446 | lua_pop(L2, 2); // L1: ... t ... L2: | 446 | lua_pop(L2, 2); // L1: ... t ... L2: |
| 447 | STACK_CHECK(L2, 0); | 447 | STACK_CHECK(L2, 0); |
| 448 | return false; | 448 | return false; |
| 449 | } 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 | 449 | } 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 |
| 450 | kLaneNameRegKey.pushValue(L1); // L1: ... t ... lane_name | 450 | kLaneNameRegKey.pushValue(L1); // L1: ... t ... lane_name |
| 451 | std::string_view const _from{ luaG_tostring(L1, kIdxTop) }; | 451 | std::string_view const _from{ luaW_tostring(L1, kIdxTop) }; |
| 452 | lua_pop(L1, 1); // L1: ... t ... | 452 | lua_pop(L1, 1); // L1: ... t ... |
| 453 | kLaneNameRegKey.pushValue(L2); // L1: ... t ... L2: {} t lane_name | 453 | kLaneNameRegKey.pushValue(L2); // L1: ... t ... L2: {} t lane_name |
| 454 | std::string_view const _to{ luaG_tostring(L2, kIdxTop) }; | 454 | std::string_view const _to{ luaW_tostring(L2, kIdxTop) }; |
| 455 | lua_pop(L2, 1); // L1: ... t ... L2: {} t | 455 | lua_pop(L2, 1); // L1: ... t ... L2: {} t |
| 456 | raise_luaL_error( | 456 | raise_luaL_error( |
| 457 | getErrL(), | 457 | getErrL(), |
| 458 | "%s: source table '%s' found as %s in %s destination transfer database.", | 458 | "%s: source table '%s' found as %s in %s destination transfer database.", |
| 459 | _from.empty() ? "main" : _from.data(), | 459 | _from.empty() ? "main" : _from.data(), |
| 460 | _fqn.data(), | 460 | _fqn.data(), |
| 461 | luaG_typename(L2, kIdxTop).data(), | 461 | luaW_typename(L2, kIdxTop).data(), |
| 462 | _to.empty() ? "main" : _to.data()); | 462 | _to.empty() ? "main" : _to.data()); |
| 463 | } | 463 | } |
| 464 | lua_remove(L2, -2); // L1: ... t ... L2: t | 464 | lua_remove(L2, -2); // L1: ... t ... L2: t |
| @@ -487,8 +487,8 @@ void InterCopyContext::interCopyKeyValuePair() const | |||
| 487 | char* _valPath{ nullptr }; | 487 | char* _valPath{ nullptr }; |
| 488 | if (U->verboseErrors) { | 488 | if (U->verboseErrors) { |
| 489 | // for debug purposes, let's try to build a useful name | 489 | // for debug purposes, let's try to build a useful name |
| 490 | if (luaG_type(L1, _key_i) == LuaType::STRING) { | 490 | if (luaW_type(L1, _key_i) == LuaType::STRING) { |
| 491 | std::string_view const _key{ luaG_tostring(L1, _key_i) }; | 491 | std::string_view const _key{ luaW_tostring(L1, _key_i) }; |
| 492 | size_t const _bufLen{ name.size() + _key.size() + 2 }; // +2 for separator dot and terminating 0 | 492 | size_t const _bufLen{ name.size() + _key.size() + 2 }; // +2 for separator dot and terminating 0 |
| 493 | _valPath = static_cast<char*>(alloca(_bufLen)); | 493 | _valPath = static_cast<char*>(alloca(_bufLen)); |
| 494 | sprintf(_valPath, "%s." STRINGVIEW_FMT, name.data(), (int) _key.size(), _key.data()); | 494 | sprintf(_valPath, "%s." STRINGVIEW_FMT, name.data(), (int) _key.size(), _key.data()); |
| @@ -500,15 +500,15 @@ void InterCopyContext::interCopyKeyValuePair() const | |||
| 500 | sprintf(_valPath, "%s[" LUA_INTEGER_FMT "]", name.data(), key); | 500 | sprintf(_valPath, "%s[" LUA_INTEGER_FMT "]", name.data(), key); |
| 501 | } | 501 | } |
| 502 | #endif // defined LUA_LNUM || LUA_VERSION_NUM >= 503 | 502 | #endif // defined LUA_LNUM || LUA_VERSION_NUM >= 503 |
| 503 | else if (luaG_type(L1, _key_i) == LuaType::NUMBER) { | 503 | else if (luaW_type(L1, _key_i) == LuaType::NUMBER) { |
| 504 | lua_Number const key{ lua_tonumber(L1, _key_i) }; | 504 | lua_Number const key{ lua_tonumber(L1, _key_i) }; |
| 505 | _valPath = (char*) alloca(name.size() + 32 + 3); // +3 for [] and terminating 0 | 505 | _valPath = (char*) alloca(name.size() + 32 + 3); // +3 for [] and terminating 0 |
| 506 | sprintf(_valPath, "%s[" LUA_NUMBER_FMT "]", name.data(), key); | 506 | sprintf(_valPath, "%s[" LUA_NUMBER_FMT "]", name.data(), key); |
| 507 | } else if (luaG_type(L1, _key_i) == LuaType::LIGHTUSERDATA) { | 507 | } else if (luaW_type(L1, _key_i) == LuaType::LIGHTUSERDATA) { |
| 508 | void* const _key{ lua_touserdata(L1, _key_i) }; | 508 | void* const _key{ lua_touserdata(L1, _key_i) }; |
| 509 | _valPath = (char*) alloca(name.size() + 16 + 5); // +5 for [U:] and terminating 0 | 509 | _valPath = (char*) alloca(name.size() + 16 + 5); // +5 for [U:] and terminating 0 |
| 510 | sprintf(_valPath, "%s[U:%p]", name.data(), _key); | 510 | sprintf(_valPath, "%s[U:%p]", name.data(), _key); |
| 511 | } else if (luaG_type(L1, _key_i) == LuaType::BOOLEAN) { | 511 | } else if (luaW_type(L1, _key_i) == LuaType::BOOLEAN) { |
| 512 | int const _key{ lua_toboolean(L1, _key_i) }; | 512 | int const _key{ lua_toboolean(L1, _key_i) }; |
| 513 | _valPath = (char*) alloca(name.size() + 8); // +8 for [], 'false' and terminating 0 | 513 | _valPath = (char*) alloca(name.size() + 8); // +8 for [], 'false' and terminating 0 |
| 514 | sprintf(_valPath, "%s[%s]", name.data(), _key ? "true" : "false"); | 514 | sprintf(_valPath, "%s[%s]", name.data(), _key ? "true" : "false"); |
| @@ -532,7 +532,7 @@ LuaType InterCopyContext::processConversion() const | |||
| 532 | { | 532 | { |
| 533 | static constexpr int kPODmask = (1 << LUA_TNIL) | (1 << LUA_TBOOLEAN) | (1 << LUA_TLIGHTUSERDATA) | (1 << LUA_TNUMBER) | (1 << LUA_TSTRING); | 533 | static constexpr int kPODmask = (1 << LUA_TNIL) | (1 << LUA_TBOOLEAN) | (1 << LUA_TLIGHTUSERDATA) | (1 << LUA_TNUMBER) | (1 << LUA_TSTRING); |
| 534 | 534 | ||
| 535 | LuaType _val_type{ luaG_type(L1, L1_i) }; | 535 | LuaType _val_type{ luaW_type(L1, L1_i) }; |
| 536 | 536 | ||
| 537 | STACK_CHECK_START_REL(L1, 0); | 537 | STACK_CHECK_START_REL(L1, 0); |
| 538 | 538 | ||
| @@ -548,7 +548,7 @@ LuaType InterCopyContext::processConversion() const | |||
| 548 | } | 548 | } |
| 549 | // we have a metatable // L1: ... mt | 549 | // we have a metatable // L1: ... mt |
| 550 | static constexpr std::string_view kConvertField{ "__lanesconvert" }; | 550 | static constexpr std::string_view kConvertField{ "__lanesconvert" }; |
| 551 | LuaType const _converterType{ luaG_getfield(L1, kIdxTop, kConvertField) }; // L1: ... mt kConvertField | 551 | LuaType const _converterType{ luaW_getfield(L1, kIdxTop, kConvertField) }; // L1: ... mt kConvertField |
| 552 | switch (_converterType) { | 552 | switch (_converterType) { |
| 553 | case LuaType::NIL: | 553 | case LuaType::NIL: |
| 554 | // no __lanesconvert, nothing to do | 554 | // no __lanesconvert, nothing to do |
| @@ -557,18 +557,18 @@ LuaType InterCopyContext::processConversion() const | |||
| 557 | 557 | ||
| 558 | case LuaType::LIGHTUSERDATA: | 558 | case LuaType::LIGHTUSERDATA: |
| 559 | if (kNilSentinel.equals(L1, kIdxTop)) { | 559 | if (kNilSentinel.equals(L1, kIdxTop)) { |
| 560 | DEBUGSPEW_CODE(DebugSpew(U) << "converted " << luaG_typename(L1, _val_type) << " to nil" << std::endl); | 560 | DEBUGSPEW_CODE(DebugSpew(U) << "converted " << luaW_typename(L1, _val_type) << " to nil" << std::endl); |
| 561 | lua_replace(L1, L1_i); // L1: ... mt | 561 | lua_replace(L1, L1_i); // L1: ... mt |
| 562 | lua_pop(L1, 1); // L1: ... | 562 | lua_pop(L1, 1); // L1: ... |
| 563 | _val_type = _converterType; | 563 | _val_type = _converterType; |
| 564 | } else { | 564 | } else { |
| 565 | raise_luaL_error(getErrL(), "Invalid %s type %s", kConvertField.data(), luaG_typename(L1, _converterType).data()); | 565 | raise_luaL_error(getErrL(), "Invalid %s type %s", kConvertField.data(), luaW_typename(L1, _converterType).data()); |
| 566 | } | 566 | } |
| 567 | break; | 567 | break; |
| 568 | 568 | ||
| 569 | case LuaType::STRING: | 569 | case LuaType::STRING: |
| 570 | // kConvertField == "decay" -> replace source value with it's pointer | 570 | // kConvertField == "decay" -> replace source value with it's pointer |
| 571 | if (std::string_view const _mode{ luaG_tostring(L1, kIdxTop) }; _mode == "decay") { | 571 | if (std::string_view const _mode{ luaW_tostring(L1, kIdxTop) }; _mode == "decay") { |
| 572 | lua_pop(L1, 1); // L1: ... mt | 572 | lua_pop(L1, 1); // L1: ... mt |
| 573 | lua_pushlightuserdata(L1, const_cast<void*>(lua_topointer(L1, L1_i))); // L1: ... mt decayed | 573 | lua_pushlightuserdata(L1, const_cast<void*>(lua_topointer(L1, L1_i))); // L1: ... mt decayed |
| 574 | lua_replace(L1, L1_i); // L1: ... mt | 574 | lua_replace(L1, L1_i); // L1: ... mt |
| @@ -581,18 +581,18 @@ LuaType InterCopyContext::processConversion() const | |||
| 581 | 581 | ||
| 582 | case LuaType::FUNCTION: | 582 | case LuaType::FUNCTION: |
| 583 | lua_pushvalue(L1, L1_i); // L1: ... mt kConvertField val | 583 | lua_pushvalue(L1, L1_i); // L1: ... mt kConvertField val |
| 584 | luaG_pushstring(L1, mode == LookupMode::ToKeeper ? "keeper" : "regular"); // L1: ... mt kConvertField val string | 584 | luaW_pushstring(L1, mode == LookupMode::ToKeeper ? "keeper" : "regular"); // L1: ... mt kConvertField val string |
| 585 | lua_call(L1, 2, 1); // val:kConvertField(str) -> result // L1: ... mt kConvertField converted | 585 | lua_call(L1, 2, 1); // val:kConvertField(str) -> result // L1: ... mt kConvertField converted |
| 586 | lua_replace(L1, L1_i); // L1: ... mt | 586 | lua_replace(L1, L1_i); // L1: ... mt |
| 587 | lua_pop(L1, 1); // L1: ... mt | 587 | lua_pop(L1, 1); // L1: ... mt |
| 588 | _val_type = luaG_type(L1, L1_i); | 588 | _val_type = luaW_type(L1, L1_i); |
| 589 | break; | 589 | break; |
| 590 | 590 | ||
| 591 | default: | 591 | default: |
| 592 | raise_luaL_error(getErrL(), "Invalid %s type %s", kConvertField.data(), luaG_typename(L1, _converterType).data()); | 592 | raise_luaL_error(getErrL(), "Invalid %s type %s", kConvertField.data(), luaW_typename(L1, _converterType).data()); |
| 593 | } | 593 | } |
| 594 | STACK_CHECK(L1, 0); | 594 | STACK_CHECK(L1, 0); |
| 595 | LUA_ASSERT(getErrL(), luaG_type(L1, L1_i) == _val_type); | 595 | LUA_ASSERT(getErrL(), luaW_type(L1, L1_i) == _val_type); |
| 596 | return _val_type; | 596 | return _val_type; |
| 597 | } | 597 | } |
| 598 | 598 | ||
| @@ -615,7 +615,7 @@ bool InterCopyContext::pushCachedMetatable() const | |||
| 615 | // do we already know this metatable? | 615 | // do we already know this metatable? |
| 616 | std::ignore = kMtIdRegKey.getSubTable(L2, NArr{ 0 }, NRec{ 0 }); // L2: _R[kMtIdRegKey] | 616 | std::ignore = kMtIdRegKey.getSubTable(L2, NArr{ 0 }, NRec{ 0 }); // L2: _R[kMtIdRegKey] |
| 617 | lua_pushinteger(L2, _mt_id); // L2: _R[kMtIdRegKey] id | 617 | lua_pushinteger(L2, _mt_id); // L2: _R[kMtIdRegKey] id |
| 618 | if (luaG_rawget(L2, StackIndex{ -2 }) == LuaType::NIL) { // L2 did not know the metatable // L2: _R[kMtIdRegKey] mt|nil | 618 | if (luaW_rawget(L2, StackIndex{ -2 }) == LuaType::NIL) { // L2 did not know the metatable // L2: _R[kMtIdRegKey] mt|nil |
| 619 | lua_pop(L2, 1); // L2: _R[kMtIdRegKey] | 619 | lua_pop(L2, 1); // L2: _R[kMtIdRegKey] |
| 620 | InterCopyContext const _c{ U, L2, L1, L2_cache_i, SourceIndex{ lua_gettop(L1) }, VT::METATABLE, mode, name }; | 620 | InterCopyContext const _c{ U, L2, L1, L2_cache_i, SourceIndex{ lua_gettop(L1) }, VT::METATABLE, mode, name }; |
| 621 | if (_c.interCopyOne() != InterCopyResult::Success) { // L2: _R[kMtIdRegKey] mt? | 621 | if (_c.interCopyOne() != InterCopyResult::Success) { // L2: _R[kMtIdRegKey] mt? |
| @@ -662,9 +662,9 @@ bool InterCopyContext::pushCachedTable() const | |||
| 662 | // push a light userdata uniquely representing the table | 662 | // push a light userdata uniquely representing the table |
| 663 | lua_pushlightuserdata(L2, const_cast<void*>(_p)); // L1: ... t ... L2: ... p | 663 | lua_pushlightuserdata(L2, const_cast<void*>(_p)); // L1: ... t ... L2: ... p |
| 664 | 664 | ||
| 665 | //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaG_tostring(L2, -1) << " >>" << std::endl); | 665 | //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaW_tostring(L2, -1) << " >>" << std::endl); |
| 666 | 666 | ||
| 667 | bool const _not_found_in_cache{ luaG_rawget(L2, L2_cache_i) == LuaType::NIL }; // L1: ... t ... L2: ... {cached|nil} | 667 | bool const _not_found_in_cache{ luaW_rawget(L2, L2_cache_i) == LuaType::NIL }; // L1: ... t ... L2: ... {cached|nil} |
| 668 | if (_not_found_in_cache) { | 668 | if (_not_found_in_cache) { |
| 669 | // create a new entry in the cache | 669 | // create a new entry in the cache |
| 670 | lua_pop(L2, 1); // L1: ... t ... L2: ... | 670 | lua_pop(L2, 1); // L1: ... t ... L2: ... |
| @@ -696,7 +696,7 @@ bool InterCopyContext::lookupUserdata() const | |||
| 696 | 696 | ||
| 697 | case LookupMode::ToKeeper: | 697 | case LookupMode::ToKeeper: |
| 698 | // push a sentinel closure that holds the lookup name as upvalue | 698 | // push a sentinel closure that holds the lookup name as upvalue |
| 699 | luaG_pushstring(L2, _fqn); // L1: ... f ... L2: "f.q.n" | 699 | luaW_pushstring(L2, _fqn); // L1: ... f ... L2: "f.q.n" |
| 700 | lua_pushcclosure(L2, userdata_lookup_sentinel, 1); // L1: ... f ... L2: f | 700 | lua_pushcclosure(L2, userdata_lookup_sentinel, 1); // L1: ... f ... L2: f |
| 701 | break; | 701 | break; |
| 702 | 702 | ||
| @@ -705,16 +705,16 @@ bool InterCopyContext::lookupUserdata() const | |||
| 705 | kLookupRegKey.pushValue(L2); // L1: ... f ... L2: {} | 705 | kLookupRegKey.pushValue(L2); // L1: ... f ... L2: {} |
| 706 | STACK_CHECK(L2, 1); | 706 | STACK_CHECK(L2, 1); |
| 707 | LUA_ASSERT(L1, lua_istable(L2, -1)); | 707 | LUA_ASSERT(L1, lua_istable(L2, -1)); |
| 708 | luaG_pushstring(L2, _fqn); // L1: ... f ... L2: {} "f.q.n" | 708 | luaW_pushstring(L2, _fqn); // L1: ... f ... L2: {} "f.q.n" |
| 709 | LuaType const _type{ luaG_rawget(L2, StackIndex{ -2 }) }; // L1: ... f ... L2: {} f | 709 | LuaType const _type{ luaW_rawget(L2, StackIndex{ -2 }) }; // L1: ... f ... L2: {} f |
| 710 | // nil means we don't know how to transfer stuff: user should do something | 710 | // nil means we don't know how to transfer stuff: user should do something |
| 711 | // anything other than function or table should not happen! | 711 | // anything other than function or table should not happen! |
| 712 | if (_type != LuaType::FUNCTION && _type != LuaType::TABLE) { | 712 | if (_type != LuaType::FUNCTION && _type != LuaType::TABLE) { |
| 713 | kLaneNameRegKey.pushValue(L1); // L1: ... f ... lane_name | 713 | kLaneNameRegKey.pushValue(L1); // L1: ... f ... lane_name |
| 714 | std::string_view const _from{ luaG_tostring(L1, kIdxTop) }; | 714 | std::string_view const _from{ luaW_tostring(L1, kIdxTop) }; |
| 715 | lua_pop(L1, 1); // L1: ... f ... | 715 | lua_pop(L1, 1); // L1: ... f ... |
| 716 | kLaneNameRegKey.pushValue(L2); // L1: ... f ... L2: {} f lane_name | 716 | kLaneNameRegKey.pushValue(L2); // L1: ... f ... L2: {} f lane_name |
| 717 | std::string_view const _to{ luaG_tostring(L2, kIdxTop) }; | 717 | std::string_view const _to{ luaW_tostring(L2, kIdxTop) }; |
| 718 | lua_pop(L2, 1); // L2: {} f | 718 | lua_pop(L2, 1); // L2: {} f |
| 719 | raise_luaL_error( | 719 | raise_luaL_error( |
| 720 | getErrL(), | 720 | getErrL(), |
| @@ -736,7 +736,7 @@ bool InterCopyContext::lookupUserdata() const | |||
| 736 | [[nodiscard]] | 736 | [[nodiscard]] |
| 737 | bool InterCopyContext::tryCopyClonable() const | 737 | bool InterCopyContext::tryCopyClonable() const |
| 738 | { | 738 | { |
| 739 | SourceIndex const _L1_i{ luaG_absindex(L1, L1_i).value() }; | 739 | SourceIndex const _L1_i{ luaW_absindex(L1, L1_i).value() }; |
| 740 | void* const _source{ lua_touserdata(L1, _L1_i) }; | 740 | void* const _source{ lua_touserdata(L1, _L1_i) }; |
| 741 | 741 | ||
| 742 | STACK_CHECK_START_REL(L1, 0); | 742 | STACK_CHECK_START_REL(L1, 0); |
| @@ -744,7 +744,7 @@ bool InterCopyContext::tryCopyClonable() const | |||
| 744 | 744 | ||
| 745 | // Check if the source was already cloned during this copy | 745 | // Check if the source was already cloned during this copy |
| 746 | lua_pushlightuserdata(L2, _source); // L2: ... source | 746 | lua_pushlightuserdata(L2, _source); // L2: ... source |
| 747 | if (luaG_rawget(L2, L2_cache_i) != LuaType::NIL) { // L2: ... clone? | 747 | if (luaW_rawget(L2, L2_cache_i) != LuaType::NIL) { // L2: ... clone? |
| 748 | STACK_CHECK(L2, 1); | 748 | STACK_CHECK(L2, 1); |
| 749 | return true; | 749 | return true; |
| 750 | } else { | 750 | } else { |
| @@ -759,7 +759,7 @@ bool InterCopyContext::tryCopyClonable() const | |||
| 759 | } | 759 | } |
| 760 | 760 | ||
| 761 | // no __lanesclone? -> not clonable | 761 | // no __lanesclone? -> not clonable |
| 762 | if (luaG_getfield(L1, kIdxTop, "__lanesclone") == LuaType::NIL) { // L1: ... mt nil | 762 | if (luaW_getfield(L1, kIdxTop, "__lanesclone") == LuaType::NIL) { // L1: ... mt nil |
| 763 | lua_pop(L1, 2); // L1: ... | 763 | lua_pop(L1, 2); // L1: ... |
| 764 | STACK_CHECK(L1, 0); | 764 | STACK_CHECK(L1, 0); |
| 765 | return false; | 765 | return false; |
| @@ -769,10 +769,10 @@ bool InterCopyContext::tryCopyClonable() const | |||
| 769 | 769 | ||
| 770 | // we need to copy over the uservalues of the userdata as well | 770 | // we need to copy over the uservalues of the userdata as well |
| 771 | { | 771 | { |
| 772 | StackIndex const _mt{ luaG_absindex(L1, StackIndex{ -2 }) }; // L1: ... mt __lanesclone | 772 | StackIndex const _mt{ luaW_absindex(L1, StackIndex{ -2 }) }; // L1: ... mt __lanesclone |
| 773 | auto const userdata_size{ static_cast<size_t>(lua_rawlen(L1, _L1_i)) }; // make 32-bits builds happy | 773 | auto const userdata_size{ static_cast<size_t>(lua_rawlen(L1, _L1_i)) }; // make 32-bits builds happy |
| 774 | // extract all the uservalues, but don't transfer them yet | 774 | // extract all the uservalues, but don't transfer them yet |
| 775 | UserValueCount const _nuv{ luaG_getalluservalues(L1, _L1_i) }; // L1: ... mt __lanesclone [uv]* | 775 | UserValueCount const _nuv{ luaW_getalluservalues(L1, _L1_i) }; // L1: ... mt __lanesclone [uv]* |
| 776 | // create the clone userdata with the required number of uservalue slots | 776 | // create the clone userdata with the required number of uservalue slots |
| 777 | void* const _clone{ lua_newuserdatauv(L2, userdata_size, _nuv) }; // L2: ... u | 777 | void* const _clone{ lua_newuserdatauv(L2, userdata_size, _nuv) }; // L2: ... u |
| 778 | // copy the metatable in the target state, and give it to the clone we put there | 778 | // copy the metatable in the target state, and give it to the clone we put there |
| @@ -804,7 +804,7 @@ bool InterCopyContext::tryCopyClonable() const | |||
| 804 | // assign uservalues | 804 | // assign uservalues |
| 805 | UserValueIndex _uvi{ _nuv.value() }; | 805 | UserValueIndex _uvi{ _nuv.value() }; |
| 806 | while (_uvi > 0) { | 806 | while (_uvi > 0) { |
| 807 | _c.L1_i = SourceIndex{ luaG_absindex(L1, kIdxTop).value() }; | 807 | _c.L1_i = SourceIndex{ luaW_absindex(L1, kIdxTop).value() }; |
| 808 | if (_c.interCopyOne() != InterCopyResult::Success) { // L2: ... u uv | 808 | if (_c.interCopyOne() != InterCopyResult::Success) { // L2: ... u uv |
| 809 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); | 809 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); |
| 810 | } | 810 | } |
| @@ -850,10 +850,10 @@ bool InterCopyContext::tryCopyDeep() const | |||
| 850 | STACK_CHECK_START_REL(L2, 0); | 850 | STACK_CHECK_START_REL(L2, 0); |
| 851 | 851 | ||
| 852 | // extract all uservalues of the source. unfortunately, the only way to know their count is to iterate until we fail | 852 | // extract all uservalues of the source. unfortunately, the only way to know their count is to iterate until we fail |
| 853 | UserValueCount const _nuv{ luaG_getalluservalues(L1, L1_i) }; // L1: ... deep ... [uv]* | 853 | UserValueCount const _nuv{ luaW_getalluservalues(L1, L1_i) }; // L1: ... deep ... [uv]* |
| 854 | STACK_CHECK(L1, _nuv); | 854 | STACK_CHECK(L1, _nuv); |
| 855 | 855 | ||
| 856 | DeepPrelude* const _deep{ *luaG_tofulluserdata<DeepPrelude*>(L1, L1_i) }; | 856 | DeepPrelude* const _deep{ *luaW_tofulluserdata<DeepPrelude*>(L1, L1_i) }; |
| 857 | DeepFactory::PushDeepProxy(L2, _deep, _nuv, mode, getErrL()); // L1: ... deep ... [uv]* L2: deep | 857 | DeepFactory::PushDeepProxy(L2, _deep, _nuv, mode, getErrL()); // L1: ... deep ... [uv]* L2: deep |
| 858 | 858 | ||
| 859 | // transfer all uservalues of the source in the destination | 859 | // transfer all uservalues of the source in the destination |
| @@ -863,7 +863,7 @@ bool InterCopyContext::tryCopyDeep() const | |||
| 863 | STACK_GROW(L2, _nuv); | 863 | STACK_GROW(L2, _nuv); |
| 864 | UserValueIndex _uvi{ _nuv.value() }; | 864 | UserValueIndex _uvi{ _nuv.value() }; |
| 865 | while (_uvi) { | 865 | while (_uvi) { |
| 866 | _c.L1_i = SourceIndex{ luaG_absindex(L1, kIdxTop).value() }; | 866 | _c.L1_i = SourceIndex{ luaW_absindex(L1, kIdxTop).value() }; |
| 867 | if (_c.interCopyOne() != InterCopyResult::Success) { // L1: ... deep ... [uv]* L2: deep uv | 867 | if (_c.interCopyOne() != InterCopyResult::Success) { // L1: ... deep ... [uv]* L2: deep uv |
| 868 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); | 868 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); |
| 869 | } | 869 | } |
| @@ -911,7 +911,7 @@ bool InterCopyContext::interCopyFunction() const | |||
| 911 | lua_getupvalue(L1, L1_i, 2); // L1: ... u | 911 | lua_getupvalue(L1, L1_i, 2); // L1: ... u |
| 912 | void* _source{ lua_touserdata(L1, -1) }; | 912 | void* _source{ lua_touserdata(L1, -1) }; |
| 913 | lua_pushlightuserdata(L2, _source); // L2: ... source | 913 | lua_pushlightuserdata(L2, _source); // L2: ... source |
| 914 | if (luaG_rawget(L2, L2_cache_i) != LuaType::NIL) { // L2: ... u? | 914 | if (luaW_rawget(L2, L2_cache_i) != LuaType::NIL) { // L2: ... u? |
| 915 | lua_pop(L1, 1); // L1: ... | 915 | lua_pop(L1, 1); // L1: ... |
| 916 | STACK_CHECK(L1, 0); | 916 | STACK_CHECK(L1, 0); |
| 917 | STACK_CHECK(L2, 1); | 917 | STACK_CHECK(L2, 1); |
| @@ -933,7 +933,7 @@ bool InterCopyContext::interCopyFunction() const | |||
| 933 | auto const _userdata_size{ static_cast<size_t>(lua_rawlen(L1, kIdxTop)) }; // make 32-bits builds happy | 933 | auto const _userdata_size{ static_cast<size_t>(lua_rawlen(L1, kIdxTop)) }; // make 32-bits builds happy |
| 934 | { | 934 | { |
| 935 | // extract uservalues (don't transfer them yet) | 935 | // extract uservalues (don't transfer them yet) |
| 936 | UserValueCount const _nuv{ luaG_getalluservalues(L1, source_i) }; // L1: ... u [uv]* | 936 | UserValueCount const _nuv{ luaW_getalluservalues(L1, source_i) }; // L1: ... u [uv]* |
| 937 | STACK_CHECK(L1, _nuv + 1); | 937 | STACK_CHECK(L1, _nuv + 1); |
| 938 | // create the clone userdata with the required number of uservalue slots | 938 | // create the clone userdata with the required number of uservalue slots |
| 939 | _clone = lua_newuserdatauv(L2, _userdata_size, _nuv); // L2: ... mt u | 939 | _clone = lua_newuserdatauv(L2, _userdata_size, _nuv); // L2: ... mt u |
| @@ -948,7 +948,7 @@ bool InterCopyContext::interCopyFunction() const | |||
| 948 | InterCopyContext _c{ *this }; | 948 | InterCopyContext _c{ *this }; |
| 949 | UserValueIndex _uvi{ _nuv.value() }; | 949 | UserValueIndex _uvi{ _nuv.value() }; |
| 950 | while (_uvi > 0) { | 950 | while (_uvi > 0) { |
| 951 | _c.L1_i = SourceIndex{ luaG_absindex(L1, kIdxTop).value() }; | 951 | _c.L1_i = SourceIndex{ luaW_absindex(L1, kIdxTop).value() }; |
| 952 | if (_c.interCopyOne() != InterCopyResult::Success) { // L2: ... mt u uv | 952 | if (_c.interCopyOne() != InterCopyResult::Success) { // L2: ... mt u uv |
| 953 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); | 953 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); |
| 954 | } | 954 | } |
| @@ -965,9 +965,9 @@ bool InterCopyContext::interCopyFunction() const | |||
| 965 | // perform the custom cloning part | 965 | // perform the custom cloning part |
| 966 | lua_insert(L2, -2); // L2: ... u mt | 966 | lua_insert(L2, -2); // L2: ... u mt |
| 967 | // __lanesclone should always exist because we wouldn't be restoring data from a userdata_clone_sentinel closure to begin with | 967 | // __lanesclone should always exist because we wouldn't be restoring data from a userdata_clone_sentinel closure to begin with |
| 968 | LuaType const _funcType{ luaG_getfield(L2, kIdxTop, "__lanesclone") }; // L2: ... u mt __lanesclone | 968 | LuaType const _funcType{ luaW_getfield(L2, kIdxTop, "__lanesclone") }; // L2: ... u mt __lanesclone |
| 969 | if (_funcType != LuaType::FUNCTION) { | 969 | if (_funcType != LuaType::FUNCTION) { |
| 970 | raise_luaL_error(getErrL(), "INTERNAL ERROR: __lanesclone is a %s, not a function", luaG_typename(L2, _funcType).data()); | 970 | raise_luaL_error(getErrL(), "INTERNAL ERROR: __lanesclone is a %s, not a function", luaW_typename(L2, _funcType).data()); |
| 971 | } | 971 | } |
| 972 | lua_remove(L2, -2); // L2: ... u __lanesclone | 972 | lua_remove(L2, -2); // L2: ... u __lanesclone |
| 973 | lua_pushlightuserdata(L2, _clone); // L2: ... u __lanesclone clone | 973 | lua_pushlightuserdata(L2, _clone); // L2: ... u __lanesclone clone |
| @@ -1060,9 +1060,9 @@ bool InterCopyContext::interCopyNumber() const | |||
| 1060 | [[nodiscard]] | 1060 | [[nodiscard]] |
| 1061 | bool InterCopyContext::interCopyString() const | 1061 | bool InterCopyContext::interCopyString() const |
| 1062 | { | 1062 | { |
| 1063 | std::string_view const _s{ luaG_tostring(L1, L1_i) }; | 1063 | std::string_view const _s{ luaW_tostring(L1, L1_i) }; |
| 1064 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "'" << _s << "'" << std::endl); | 1064 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "'" << _s << "'" << std::endl); |
| 1065 | luaG_pushstring(L2, _s); | 1065 | luaW_pushstring(L2, _s); |
| 1066 | return true; | 1066 | return true; |
| 1067 | } | 1067 | } |
| 1068 | 1068 | ||
| @@ -1154,7 +1154,7 @@ bool InterCopyContext::interCopyUserdata() const | |||
| 1154 | 1154 | ||
| 1155 | // 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?) | 1155 | // 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?) |
| 1156 | if (lookupUserdata()) { | 1156 | if (lookupUserdata()) { |
| 1157 | 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 | 1157 | 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 |
| 1158 | return true; | 1158 | return true; |
| 1159 | } | 1159 | } |
| 1160 | 1160 | ||
| @@ -1291,8 +1291,8 @@ InterCopyResult InterCopyContext::interCopyPackage() const | |||
| 1291 | } const _onExit{ L2 }; | 1291 | } const _onExit{ L2 }; |
| 1292 | 1292 | ||
| 1293 | STACK_CHECK_START_REL(L1, 0); | 1293 | STACK_CHECK_START_REL(L1, 0); |
| 1294 | if (luaG_type(L1, L1_i) != LuaType::TABLE) { | 1294 | if (luaW_type(L1, L1_i) != LuaType::TABLE) { |
| 1295 | std::string_view const _msg{ luaG_pushstring(L1, "expected package as table, got a %s", luaL_typename(L1, L1_i)) }; | 1295 | std::string_view const _msg{ luaW_pushstring(L1, "expected package as table, got a %s", luaL_typename(L1, L1_i)) }; |
| 1296 | STACK_CHECK(L1, 1); | 1296 | STACK_CHECK(L1, 1); |
| 1297 | // raise the error when copying from lane to lane, else just leave it on the stack to be raised later | 1297 | // raise the error when copying from lane to lane, else just leave it on the stack to be raised later |
| 1298 | if (mode == LookupMode::LaneBody) { | 1298 | if (mode == LookupMode::LaneBody) { |
| @@ -1300,7 +1300,7 @@ InterCopyResult InterCopyContext::interCopyPackage() const | |||
| 1300 | } | 1300 | } |
| 1301 | return InterCopyResult::Error; | 1301 | return InterCopyResult::Error; |
| 1302 | } | 1302 | } |
| 1303 | if (luaG_getmodule(L2, LUA_LOADLIBNAME) == LuaType::NIL) { // package library not loaded: do nothing | 1303 | if (luaW_getmodule(L2, LUA_LOADLIBNAME) == LuaType::NIL) { // package library not loaded: do nothing |
| 1304 | DEBUGSPEW_CODE(DebugSpew(U) << "'package' not loaded, nothing to do" << std::endl); | 1304 | DEBUGSPEW_CODE(DebugSpew(U) << "'package' not loaded, nothing to do" << std::endl); |
| 1305 | STACK_CHECK(L1, 0); | 1305 | STACK_CHECK(L1, 0); |
| 1306 | return InterCopyResult::Success; | 1306 | return InterCopyResult::Success; |
| @@ -1317,7 +1317,7 @@ InterCopyResult InterCopyContext::interCopyPackage() const | |||
| 1317 | continue; | 1317 | continue; |
| 1318 | } | 1318 | } |
| 1319 | DEBUGSPEW_CODE(DebugSpew(U) << "package." << _entry << std::endl); | 1319 | DEBUGSPEW_CODE(DebugSpew(U) << "package." << _entry << std::endl); |
| 1320 | if (luaG_getfield(L1, L1_i, _entry) == LuaType::NIL) { | 1320 | if (luaW_getfield(L1, L1_i, _entry) == LuaType::NIL) { |
| 1321 | lua_pop(L1, 1); | 1321 | lua_pop(L1, 1); |
| 1322 | } else { | 1322 | } else { |
| 1323 | { | 1323 | { |
| @@ -1328,9 +1328,9 @@ InterCopyResult InterCopyContext::interCopyPackage() const | |||
| 1328 | STACK_CHECK(L1, 0); | 1328 | STACK_CHECK(L1, 0); |
| 1329 | } | 1329 | } |
| 1330 | if (_result == InterCopyResult::Success) { | 1330 | if (_result == InterCopyResult::Success) { |
| 1331 | luaG_setfield(L2, StackIndex{ -2 }, _entry); // set package[entry] | 1331 | luaW_setfield(L2, StackIndex{ -2 }, _entry); // set package[entry] |
| 1332 | } else { | 1332 | } else { |
| 1333 | std::string_view const _msg{ luaG_pushstring(L1, "failed to copy package.%s", _entry.data()) }; | 1333 | std::string_view const _msg{ luaW_pushstring(L1, "failed to copy package.%s", _entry.data()) }; |
| 1334 | // raise the error when copying from lane to lane, else just leave it on the stack to be raised later | 1334 | // raise the error when copying from lane to lane, else just leave it on the stack to be raised later |
| 1335 | if (mode == LookupMode::LaneBody) { | 1335 | if (mode == LookupMode::LaneBody) { |
| 1336 | raise_luaL_error(getErrL(), _msg); | 1336 | 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 | |||
| 77 | 77 | ||
| 78 | // a fifo full userdata has one uservalue, the table that holds the actual fifo contents | 78 | // a fifo full userdata has one uservalue, the table that holds the actual fifo contents |
| 79 | [[nodiscard]] | 79 | [[nodiscard]] |
| 80 | static void* operator new([[maybe_unused]] size_t size_, KeeperState L_) noexcept { return luaG_newuserdatauv<KeyUD>(L_, UserValueCount{ 1 }); } | 80 | static void* operator new([[maybe_unused]] size_t size_, KeeperState L_) noexcept { return luaW_newuserdatauv<KeyUD>(L_, UserValueCount{ 1 }); } |
| 81 | // always embedded somewhere else or "in-place constructed" as a full userdata | 81 | // always embedded somewhere else or "in-place constructed" as a full userdata |
| 82 | // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception | 82 | // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception |
| 83 | static void operator delete([[maybe_unused]] void* p_, [[maybe_unused]] KeeperState L_) { LUA_ASSERT(L_, !"should never be called"); } | 83 | 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_) | |||
| 146 | [[nodiscard]] | 146 | [[nodiscard]] |
| 147 | KeyUD* KeyUD::GetPtr(KeeperState const K_, StackIndex const idx_) | 147 | KeyUD* KeyUD::GetPtr(KeeperState const K_, StackIndex const idx_) |
| 148 | { | 148 | { |
| 149 | return luaG_tofulluserdata<KeyUD>(K_, idx_); | 149 | return luaW_tofulluserdata<KeyUD>(K_, idx_); |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | // ################################################################################################# | 152 | // ################################################################################################# |
| @@ -236,7 +236,7 @@ int KeyUD::pop(KeeperState const K_, int const minCount_, int const maxCount_) | |||
| 236 | // replaces it by its uservalue on the stack (the table holding the fifo values) | 236 | // replaces it by its uservalue on the stack (the table holding the fifo values) |
| 237 | void KeyUD::prepareAccess(KeeperState const K_, StackIndex const idx_) const | 237 | void KeyUD::prepareAccess(KeeperState const K_, StackIndex const idx_) const |
| 238 | { | 238 | { |
| 239 | StackIndex const _idx{ luaG_absindex(K_, idx_) }; | 239 | StackIndex const _idx{ luaW_absindex(K_, idx_) }; |
| 240 | LUA_ASSERT(K_, KeyUD::GetPtr(K_, idx_) == this); | 240 | LUA_ASSERT(K_, KeyUD::GetPtr(K_, idx_) == this); |
| 241 | // we can replace the key userdata in the stack without fear of it being GCed, there are other references around | 241 | // we can replace the key userdata in the stack without fear of it being GCed, there are other references around |
| 242 | lua_getiuservalue(K_, _idx, kContentsTableIndex); | 242 | lua_getiuservalue(K_, _idx, kContentsTableIndex); |
| @@ -250,7 +250,7 @@ void KeyUD::prepareAccess(KeeperState const K_, StackIndex const idx_) const | |||
| 250 | [[nodiscard]] | 250 | [[nodiscard]] |
| 251 | bool KeyUD::push(KeeperState const K_, int const count_, bool const enforceLimit_) | 251 | bool KeyUD::push(KeeperState const K_, int const count_, bool const enforceLimit_) |
| 252 | { | 252 | { |
| 253 | StackIndex const _fifoIdx{ luaG_absindex(K_, StackIndex{ -1 - count_ }) }; | 253 | StackIndex const _fifoIdx{ luaW_absindex(K_, StackIndex{ -1 - count_ }) }; |
| 254 | LUA_ASSERT(K_, KeyUD::GetPtr(K_, _fifoIdx) == this); // K_: this val... | 254 | LUA_ASSERT(K_, KeyUD::GetPtr(K_, _fifoIdx) == this); // K_: this val... |
| 255 | if (enforceLimit_ && (limit >= 0) && (count + count_ > limit)) { // not enough room | 255 | if (enforceLimit_ && (limit >= 0) && (count + count_ > limit)) { // not enough room |
| 256 | return false; | 256 | return false; |
| @@ -274,16 +274,16 @@ bool KeyUD::push(KeeperState const K_, int const count_, bool const enforceLimit | |||
| 274 | void KeyUD::pushFillStatus(KeeperState const K_) const | 274 | void KeyUD::pushFillStatus(KeeperState const K_) const |
| 275 | { | 275 | { |
| 276 | if (limit < 0) { | 276 | if (limit < 0) { |
| 277 | luaG_pushstring(K_, kUnder); | 277 | luaW_pushstring(K_, kUnder); |
| 278 | return; | 278 | return; |
| 279 | } | 279 | } |
| 280 | int const _delta{ limit - count }; | 280 | int const _delta{ limit - count }; |
| 281 | if (_delta < 0) { | 281 | if (_delta < 0) { |
| 282 | luaG_pushstring(K_, kOver); | 282 | luaW_pushstring(K_, kOver); |
| 283 | } else if (_delta > 0) { | 283 | } else if (_delta > 0) { |
| 284 | luaG_pushstring(K_, kUnder); | 284 | luaW_pushstring(K_, kUnder); |
| 285 | } else { | 285 | } else { |
| 286 | luaG_pushstring(K_, kExact); | 286 | luaW_pushstring(K_, kExact); |
| 287 | } | 287 | } |
| 288 | } | 288 | } |
| 289 | 289 | ||
| @@ -294,7 +294,7 @@ void KeyUD::PushFillStatus(KeeperState const K_, KeyUD const* const key_) | |||
| 294 | if (key_) { | 294 | if (key_) { |
| 295 | key_->pushFillStatus(K_); // _K: ... <fill status> | 295 | key_->pushFillStatus(K_); // _K: ... <fill status> |
| 296 | } else { | 296 | } else { |
| 297 | luaG_pushstring(K_, KeyUD::kUnder); // _K: ... "under" | 297 | luaW_pushstring(K_, KeyUD::kUnder); // _K: ... "under" |
| 298 | } | 298 | } |
| 299 | } | 299 | } |
| 300 | 300 | ||
| @@ -330,10 +330,10 @@ static void PushKeysDB(KeeperState const K_, StackIndex const idx_) | |||
| 330 | { | 330 | { |
| 331 | STACK_GROW(K_, 5); | 331 | STACK_GROW(K_, 5); |
| 332 | STACK_CHECK_START_REL(K_, 0); | 332 | STACK_CHECK_START_REL(K_, 0); |
| 333 | StackIndex const _absidx{ luaG_absindex(K_, idx_) }; | 333 | StackIndex const _absidx{ luaW_absindex(K_, idx_) }; |
| 334 | kLindasRegKey.pushValue(K_); // K_: ... LindasDB | 334 | kLindasRegKey.pushValue(K_); // K_: ... LindasDB |
| 335 | lua_pushvalue(K_, _absidx); // K_: ... LindasDB linda | 335 | lua_pushvalue(K_, _absidx); // K_: ... LindasDB linda |
| 336 | if (luaG_rawget(K_, StackIndex{ -2 }) == LuaType::NIL) { // K_: ... LindasDB KeysDB | 336 | if (luaW_rawget(K_, StackIndex{ -2 }) == LuaType::NIL) { // K_: ... LindasDB KeysDB |
| 337 | lua_pop(K_, 1); // K_: ... LindasDB | 337 | lua_pop(K_, 1); // K_: ... LindasDB |
| 338 | // add a new KeysDB table for this linda | 338 | // add a new KeysDB table for this linda |
| 339 | lua_newtable(K_); // K_: ... LindasDB KeysDB | 339 | lua_newtable(K_); // K_: ... LindasDB KeysDB |
| @@ -390,7 +390,7 @@ int keepercall_count(lua_State* const L_) | |||
| 390 | case 2: // _K: linda key | 390 | case 2: // _K: linda key |
| 391 | PushKeysDB(_K, StackIndex{ 1 }); // _K: linda key KeysDB | 391 | PushKeysDB(_K, StackIndex{ 1 }); // _K: linda key KeysDB |
| 392 | lua_replace(_K, 1); // _K: KeysDB key | 392 | lua_replace(_K, 1); // _K: KeysDB key |
| 393 | if (luaG_rawget(_K, StackIndex{ -2 }) == LuaType::NIL) { // the key is unknown // _K: KeysDB KeyUD|nil | 393 | if (luaW_rawget(_K, StackIndex{ -2 }) == LuaType::NIL) { // the key is unknown // _K: KeysDB KeyUD|nil |
| 394 | lua_remove(_K, -2); // _K: nil | 394 | lua_remove(_K, -2); // _K: nil |
| 395 | } else { // the key is known // _K: KeysDB KeyUD | 395 | } else { // the key is known // _K: KeysDB KeyUD |
| 396 | KeyUD* const _key{ KeyUD::GetPtr(_K, kIdxTop) }; | 396 | KeyUD* const _key{ KeyUD::GetPtr(_K, kIdxTop) }; |
| @@ -503,7 +503,7 @@ int keepercall_limit(lua_State* const L_) | |||
| 503 | if (_key && _key->limit >= 0) { | 503 | if (_key && _key->limit >= 0) { |
| 504 | lua_pushinteger(_K, _key->limit); // _K: limit | 504 | lua_pushinteger(_K, _key->limit); // _K: limit |
| 505 | } else { // if the key doesn't exist, it is unlimited by default | 505 | } else { // if the key doesn't exist, it is unlimited by default |
| 506 | luaG_pushstring(_K, "unlimited"); // _K: "unlimited" | 506 | luaW_pushstring(_K, "unlimited"); // _K: "unlimited" |
| 507 | } | 507 | } |
| 508 | // return a single value: the limit of the key | 508 | // return a single value: the limit of the key |
| 509 | } else { | 509 | } else { |
| @@ -617,7 +617,7 @@ int keepercall_restrict(lua_State* const L_) | |||
| 617 | if (_reading) { | 617 | if (_reading) { |
| 618 | return LindaRestrict::None; | 618 | return LindaRestrict::None; |
| 619 | } | 619 | } |
| 620 | std::string_view const _val{ luaG_tostring(_K, StackIndex{ 3 }) }; | 620 | std::string_view const _val{ luaW_tostring(_K, StackIndex{ 3 }) }; |
| 621 | if (_val == "set/get") { | 621 | if (_val == "set/get") { |
| 622 | return LindaRestrict::SetGet; | 622 | return LindaRestrict::SetGet; |
| 623 | } | 623 | } |
| @@ -649,7 +649,7 @@ int keepercall_restrict(lua_State* const L_) | |||
| 649 | lua_settop(_K, 0); // _K: | 649 | lua_settop(_K, 0); // _K: |
| 650 | auto const _prevRstrct{ _key ? _key->restrict : LindaRestrict::None }; | 650 | auto const _prevRstrct{ _key ? _key->restrict : LindaRestrict::None }; |
| 651 | // return a single value: the restrict mode of the key | 651 | // return a single value: the restrict mode of the key |
| 652 | luaG_pushstring(_K, _encodeRestrict(_prevRstrct)); // _K: _previous | 652 | luaW_pushstring(_K, _encodeRestrict(_prevRstrct)); // _K: _previous |
| 653 | } else { | 653 | } else { |
| 654 | if (_key == nullptr) { // _K: KeysDB key nil | 654 | if (_key == nullptr) { // _K: KeysDB key nil |
| 655 | lua_pop(_K, 1); // _K: KeysDB key | 655 | lua_pop(_K, 1); // _K: KeysDB key |
| @@ -661,7 +661,7 @@ int keepercall_restrict(lua_State* const L_) | |||
| 661 | // return true if we decide that blocked threads waiting to write on that key should be awakened | 661 | // return true if we decide that blocked threads waiting to write on that key should be awakened |
| 662 | // this is the case if we detect the key was full but it is no longer the case | 662 | // this is the case if we detect the key was full but it is no longer the case |
| 663 | LindaRestrict const _previous{ _key->changeRestrict(_rstrct) }; | 663 | LindaRestrict const _previous{ _key->changeRestrict(_rstrct) }; |
| 664 | luaG_pushstring(_K, _encodeRestrict(_previous)); // _K: _previous | 664 | luaW_pushstring(_K, _encodeRestrict(_previous)); // _K: _previous |
| 665 | } | 665 | } |
| 666 | STACK_CHECK(_K, 1); | 666 | STACK_CHECK(_K, 1); |
| 667 | return 1; | 667 | return 1; |
| @@ -680,7 +680,7 @@ int keepercall_send(lua_State* const L_) | |||
| 680 | PushKeysDB(_K, StackIndex{ 1 }); // _K: linda key val... KeysDB | 680 | PushKeysDB(_K, StackIndex{ 1 }); // _K: linda key val... KeysDB |
| 681 | // get the fifo associated to this key in this linda, create it if it doesn't exist | 681 | // get the fifo associated to this key in this linda, create it if it doesn't exist |
| 682 | lua_pushvalue(_K, 2); // _K: linda key val... KeysDB key | 682 | lua_pushvalue(_K, 2); // _K: linda key val... KeysDB key |
| 683 | if (luaG_rawget(_K, StackIndex{ -2 }) == LuaType::NIL) { // _K: linda key val... KeysDB KeyUD|nil | 683 | if (luaW_rawget(_K, StackIndex{ -2 }) == LuaType::NIL) { // _K: linda key val... KeysDB KeyUD|nil |
| 684 | lua_pop(_K, 1); // _K: linda key val... KeysDB | 684 | lua_pop(_K, 1); // _K: linda key val... KeysDB |
| 685 | std::ignore = KeyUD::Create(KeeperState{ _K }); // _K: linda key val... KeysDB KeyUD | 685 | std::ignore = KeyUD::Create(KeeperState{ _K }); // _K: linda key val... KeysDB KeyUD |
| 686 | // KeysDB[key] = KeyUD | 686 | // KeysDB[key] = KeyUD |
| @@ -863,7 +863,7 @@ int Keeper::PushLindaStorage(Linda& linda_, DestState const L_) | |||
| 863 | STACK_CHECK_START_REL(_K, 0); | 863 | STACK_CHECK_START_REL(_K, 0); |
| 864 | kLindasRegKey.pushValue(_K); // _K: LindasDB L_: | 864 | kLindasRegKey.pushValue(_K); // _K: LindasDB L_: |
| 865 | lua_pushlightuserdata(_K, &linda_); // _K: LindasDB linda L_: | 865 | lua_pushlightuserdata(_K, &linda_); // _K: LindasDB linda L_: |
| 866 | LuaType const _type{ luaG_rawget(_K, StackIndex{ -2 }) }; // _K: LindasDB KeysDB L_: | 866 | LuaType const _type{ luaW_rawget(_K, StackIndex{ -2 }) }; // _K: LindasDB KeysDB L_: |
| 867 | lua_remove(_K, -2); // _K: KeysDB L_: | 867 | lua_remove(_K, -2); // _K: KeysDB L_: |
| 868 | if (_type != LuaType::TABLE) { // possible if we didn't send anything through that linda | 868 | if (_type != LuaType::TABLE) { // possible if we didn't send anything through that linda |
| 869 | lua_pop(_K, 1); // _K: L_: | 869 | lua_pop(_K, 1); // _K: L_: |
| @@ -900,20 +900,20 @@ int Keeper::PushLindaStorage(Linda& linda_, DestState const L_) | |||
| 900 | if (_key->limit >= 0) { | 900 | if (_key->limit >= 0) { |
| 901 | lua_pushinteger(L_, _key->limit); // _K: KeysDB key L_: out key keyout fifo limit | 901 | lua_pushinteger(L_, _key->limit); // _K: KeysDB key L_: out key keyout fifo limit |
| 902 | } else { | 902 | } else { |
| 903 | luaG_pushstring(L_, "unlimited"); // _K: KeysDB key L_: out key keyout fifo limit | 903 | luaW_pushstring(L_, "unlimited"); // _K: KeysDB key L_: out key keyout fifo limit |
| 904 | } | 904 | } |
| 905 | STACK_CHECK(L_, 5); | 905 | STACK_CHECK(L_, 5); |
| 906 | lua_setfield(L_, -3, "limit"); // _K: KeysDB key L_: out key keyout fifo | 906 | lua_setfield(L_, -3, "limit"); // _K: KeysDB key L_: out key keyout fifo |
| 907 | // keyout.restrict | 907 | // keyout.restrict |
| 908 | switch (_key->restrict) { | 908 | switch (_key->restrict) { |
| 909 | case LindaRestrict::None: | 909 | case LindaRestrict::None: |
| 910 | luaG_pushstring(L_, "none"); // _K: KeysDB key L_: out key keyout fifo restrict | 910 | luaW_pushstring(L_, "none"); // _K: KeysDB key L_: out key keyout fifo restrict |
| 911 | break; | 911 | break; |
| 912 | case LindaRestrict::SetGet: | 912 | case LindaRestrict::SetGet: |
| 913 | luaG_pushstring(L_, "set/get"); // _K: KeysDB key L_: out key keyout fifo restrict | 913 | luaW_pushstring(L_, "set/get"); // _K: KeysDB key L_: out key keyout fifo restrict |
| 914 | break; | 914 | break; |
| 915 | case LindaRestrict::SendReceive: | 915 | case LindaRestrict::SendReceive: |
| 916 | luaG_pushstring(L_, "send/receive"); // _K: KeysDB key L_: out key keyout fifo restrict | 916 | luaW_pushstring(L_, "send/receive"); // _K: KeysDB key L_: out key keyout fifo restrict |
| 917 | break; | 917 | break; |
| 918 | } | 918 | } |
| 919 | STACK_CHECK(L_, 5); | 919 | STACK_CHECK(L_, 5); |
| @@ -1090,7 +1090,7 @@ void Keepers::initialize(Universe& U_, lua_State* L_, size_t const nbKeepers_, i | |||
| 1090 | keeper_.K = _K; | 1090 | keeper_.K = _K; |
| 1091 | 1091 | ||
| 1092 | // Give a name to the state | 1092 | // Give a name to the state |
| 1093 | luaG_pushstring(_K, "Keeper #%d", i_ + 1); // L_: settings _K: "Keeper #n" | 1093 | luaW_pushstring(_K, "Keeper #%d", i_ + 1); // L_: settings _K: "Keeper #n" |
| 1094 | if constexpr (HAVE_DECODA_SUPPORT()) { | 1094 | if constexpr (HAVE_DECODA_SUPPORT()) { |
| 1095 | lua_pushvalue(_K, -1); // _K: "Keeper #n" Keeper #n" | 1095 | lua_pushvalue(_K, -1); // _K: "Keeper #n" Keeper #n" |
| 1096 | lua_setglobal(_K, "decoda_name"); // L_: settings _K: "Keeper #n" | 1096 | 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 | |||
| 1112 | STACK_CHECK(_K, 0); | 1112 | STACK_CHECK(_K, 0); |
| 1113 | 1113 | ||
| 1114 | // copy package.path and package.cpath from the source state | 1114 | // copy package.path and package.cpath from the source state |
| 1115 | if (luaG_getmodule(L, LUA_LOADLIBNAME) != LuaType::NIL) { // L_: settings package _K: | 1115 | if (luaW_getmodule(L, LUA_LOADLIBNAME) != LuaType::NIL) { // L_: settings package _K: |
| 1116 | // when copying with mode LookupMode::ToKeeper, error message is pushed at the top of the stack, not raised immediately | 1116 | // when copying with mode LookupMode::ToKeeper, error message is pushed at the top of the stack, not raised immediately |
| 1117 | InterCopyContext _c{ U, DestState{ _K.value() }, SourceState{ L }, {}, SourceIndex{ luaG_absindex(L, kIdxTop).value() }, {}, LookupMode::ToKeeper, {} }; | 1117 | InterCopyContext _c{ U, DestState{ _K.value() }, SourceState{ L }, {}, SourceIndex{ luaW_absindex(L, kIdxTop).value() }, {}, LookupMode::ToKeeper, {} }; |
| 1118 | if (_c.interCopyPackage() != InterCopyResult::Success) { // L_: settings ... error_msg _K: | 1118 | if (_c.interCopyPackage() != InterCopyResult::Success) { // L_: settings ... error_msg _K: |
| 1119 | // if something went wrong, the error message is at the top of the stack | 1119 | // if something went wrong, the error message is at the top of the stack |
| 1120 | lua_remove(L, -2); // L_: settings error_msg | 1120 | 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) | |||
| 49 | { | 49 | { |
| 50 | Lane* const _lane{ ToLane(L_, StackIndex{ 1 }) }; | 50 | Lane* const _lane{ ToLane(L_, StackIndex{ 1 }) }; |
| 51 | luaL_argcheck(L_, lua_gettop(L_) == 1, 2, "too many arguments"); | 51 | luaL_argcheck(L_, lua_gettop(L_) == 1, 2, "too many arguments"); |
| 52 | luaG_pushstring(L_, _lane->getDebugName()); | 52 | luaW_pushstring(L_, _lane->getDebugName()); |
| 53 | return 1; | 53 | return 1; |
| 54 | } | 54 | } |
| 55 | 55 | ||
| @@ -85,17 +85,17 @@ static LUAG_FUNC(set_finalizer) | |||
| 85 | static LUAG_FUNC(lane_threadname) | 85 | static LUAG_FUNC(lane_threadname) |
| 86 | { | 86 | { |
| 87 | // C s_lane structure is a light userdata upvalue | 87 | // C s_lane structure is a light userdata upvalue |
| 88 | Lane* const _lane{ luaG_tolightuserdata<Lane>(L_, StackIndex{ lua_upvalueindex(1) }) }; | 88 | Lane* const _lane{ luaW_tolightuserdata<Lane>(L_, StackIndex{ lua_upvalueindex(1) }) }; |
| 89 | 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 | 89 | 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 |
| 90 | if (lua_gettop(L_) == 1) { | 90 | if (lua_gettop(L_) == 1) { |
| 91 | lua_settop(L_, 1); | 91 | lua_settop(L_, 1); |
| 92 | STACK_CHECK_START_REL(L_, 0); | 92 | STACK_CHECK_START_REL(L_, 0); |
| 93 | _lane->storeDebugName(luaG_tostring(L_, kIdxTop)); | 93 | _lane->storeDebugName(luaW_tostring(L_, kIdxTop)); |
| 94 | _lane->applyDebugName(); | 94 | _lane->applyDebugName(); |
| 95 | STACK_CHECK(L_, 0); | 95 | STACK_CHECK(L_, 0); |
| 96 | return 0; | 96 | return 0; |
| 97 | } else if (lua_gettop(L_) == 0) { | 97 | } else if (lua_gettop(L_) == 0) { |
| 98 | luaG_pushstring(L_, _lane->getDebugName()); | 98 | luaW_pushstring(L_, _lane->getDebugName()); |
| 99 | return 1; | 99 | return 1; |
| 100 | } else { | 100 | } else { |
| 101 | raise_luaL_error(L_, "Wrong number of arguments"); | 101 | raise_luaL_error(L_, "Wrong number of arguments"); |
| @@ -117,7 +117,7 @@ static LUAG_FUNC(lane_join) | |||
| 117 | Lane* const _lane{ ToLane(L_, StackIndex{ 1 }) }; | 117 | Lane* const _lane{ ToLane(L_, StackIndex{ 1 }) }; |
| 118 | 118 | ||
| 119 | std::chrono::time_point<std::chrono::steady_clock> _until{ std::chrono::time_point<std::chrono::steady_clock>::max() }; | 119 | std::chrono::time_point<std::chrono::steady_clock> _until{ std::chrono::time_point<std::chrono::steady_clock>::max() }; |
| 120 | if (luaG_type(L_, StackIndex{ 2 }) == LuaType::NUMBER) { // we don't want to use lua_isnumber() because of autocoercion | 120 | if (luaW_type(L_, StackIndex{ 2 }) == LuaType::NUMBER) { // we don't want to use lua_isnumber() because of autocoercion |
| 121 | lua_Duration const duration{ lua_tonumber(L_, 2) }; | 121 | lua_Duration const duration{ lua_tonumber(L_, 2) }; |
| 122 | if (duration.count() >= 0.0) { | 122 | if (duration.count() >= 0.0) { |
| 123 | _until = std::chrono::steady_clock::now() + std::chrono::duration_cast<std::chrono::steady_clock::duration>(duration); | 123 | _until = std::chrono::steady_clock::now() + std::chrono::duration_cast<std::chrono::steady_clock::duration>(duration); |
| @@ -237,13 +237,13 @@ static int lane_index_string(lua_State* L_) | |||
| 237 | Lane* const _lane{ ToLane(L_, kIdxSelf) }; | 237 | Lane* const _lane{ ToLane(L_, kIdxSelf) }; |
| 238 | LUA_ASSERT(L_, lua_gettop(L_) == 2); // L_: lane "key" | 238 | LUA_ASSERT(L_, lua_gettop(L_) == 2); // L_: lane "key" |
| 239 | 239 | ||
| 240 | std::string_view const _keystr{ luaG_tostring(L_, kIdxKey) }; | 240 | std::string_view const _keystr{ luaW_tostring(L_, kIdxKey) }; |
| 241 | lua_settop(L_, 2); // keep only our original arguments on the stack | 241 | lua_settop(L_, 2); // keep only our original arguments on the stack |
| 242 | 242 | ||
| 243 | // look in metatable first | 243 | // look in metatable first |
| 244 | lua_getmetatable(L_, kIdxSelf); // L_: lane "key" mt | 244 | lua_getmetatable(L_, kIdxSelf); // L_: lane "key" mt |
| 245 | lua_replace(L_, -3); // L_: mt "key" | 245 | lua_replace(L_, -3); // L_: mt "key" |
| 246 | if (luaG_rawget(L_, StackIndex{ -2 }) != LuaType::NIL) { // found something? // L_: mt value | 246 | if (luaW_rawget(L_, StackIndex{ -2 }) != LuaType::NIL) { // found something? // L_: mt value |
| 247 | return 1; // done | 247 | return 1; // done |
| 248 | } | 248 | } |
| 249 | 249 | ||
| @@ -269,7 +269,7 @@ static LUAG_FUNC(lane_index) | |||
| 269 | Lane* const _lane{ ToLane(L_, kIdxSelf) }; | 269 | Lane* const _lane{ ToLane(L_, kIdxSelf) }; |
| 270 | LUA_ASSERT(L_, lua_gettop(L_) == 2); | 270 | LUA_ASSERT(L_, lua_gettop(L_) == 2); |
| 271 | 271 | ||
| 272 | switch (luaG_type(L_, kKey)) { | 272 | switch (luaW_type(L_, kKey)) { |
| 273 | case LuaType::NUMBER: | 273 | case LuaType::NUMBER: |
| 274 | return lane_index_number(L_); // stack modification is undefined, returned value is at the top | 274 | return lane_index_number(L_); // stack modification is undefined, returned value is at the top |
| 275 | 275 | ||
| @@ -279,19 +279,19 @@ static LUAG_FUNC(lane_index) | |||
| 279 | default: // unknown key | 279 | default: // unknown key |
| 280 | lua_getmetatable(L_, kIdxSelf); // L_: mt | 280 | lua_getmetatable(L_, kIdxSelf); // L_: mt |
| 281 | kCachedError.pushKey(L_); // L_: mt kCachedError | 281 | kCachedError.pushKey(L_); // L_: mt kCachedError |
| 282 | if (luaG_rawget(L_, StackIndex{ -2 }) != LuaType::FUNCTION) { // L_: mt error() | 282 | if (luaW_rawget(L_, StackIndex{ -2 }) != LuaType::FUNCTION) { // L_: mt error() |
| 283 | raise_luaL_error(L_, "INTERNAL ERROR: cached error() is a %s, not a function", luaG_typename(L_, kIdxTop).data()); | 283 | raise_luaL_error(L_, "INTERNAL ERROR: cached error() is a %s, not a function", luaW_typename(L_, kIdxTop).data()); |
| 284 | } | 284 | } |
| 285 | luaG_pushstring(L_, "Unknown key: "); // L_: mt error() "Unknown key: " | 285 | luaW_pushstring(L_, "Unknown key: "); // L_: mt error() "Unknown key: " |
| 286 | kCachedTostring.pushKey(L_); // L_: mt error() "Unknown key: " kCachedTostring | 286 | kCachedTostring.pushKey(L_); // L_: mt error() "Unknown key: " kCachedTostring |
| 287 | if (luaG_rawget(L_, StackIndex{ -4 }) != LuaType::FUNCTION) { // L_: mt error() "Unknown key: " tostring() | 287 | if (luaW_rawget(L_, StackIndex{ -4 }) != LuaType::FUNCTION) { // L_: mt error() "Unknown key: " tostring() |
| 288 | raise_luaL_error(L_, "INTERNAL ERROR: cached tostring() is a %s, not a function", luaG_typename(L_, kIdxTop).data()); | 288 | raise_luaL_error(L_, "INTERNAL ERROR: cached tostring() is a %s, not a function", luaW_typename(L_, kIdxTop).data()); |
| 289 | } | 289 | } |
| 290 | lua_pushvalue(L_, kKey); // L_: mt error() "Unknown key: " tostring() k | 290 | lua_pushvalue(L_, kKey); // L_: mt error() "Unknown key: " tostring() k |
| 291 | lua_call(L_, 1, 1); // L_: mt error() "Unknown key: " "k" | 291 | lua_call(L_, 1, 1); // L_: mt error() "Unknown key: " "k" |
| 292 | lua_concat(L_, 2); // L_: mt error() "Unknown key: <k>" | 292 | lua_concat(L_, 2); // L_: mt error() "Unknown key: <k>" |
| 293 | lua_call(L_, 1, 0); // error( "Unknown key: " .. key) -> doesn't return // L_: mt | 293 | lua_call(L_, 1, 0); // error( "Unknown key: " .. key) -> doesn't return // L_: mt |
| 294 | raise_luaL_error(L_, "%s[%s]: should not get here!", _lane->getDebugName().data(), luaG_typename(L_, kKey).data()); | 294 | raise_luaL_error(L_, "%s[%s]: should not get here!", _lane->getDebugName().data(), luaW_typename(L_, kKey).data()); |
| 295 | } | 295 | } |
| 296 | } | 296 | } |
| 297 | 297 | ||
| @@ -382,7 +382,7 @@ int Lane::LuaErrorHandler(lua_State* L_) | |||
| 382 | // table of { "sourcefile.lua:<line>", ... } | 382 | // table of { "sourcefile.lua:<line>", ... } |
| 383 | // | 383 | // |
| 384 | lua_newtable(L_); // L_: some_error {} | 384 | lua_newtable(L_); // L_: some_error {} |
| 385 | StackIndex const kIdxTraceTbl{ luaG_absindex(L_, kIdxTop) }; | 385 | StackIndex const kIdxTraceTbl{ luaW_absindex(L_, kIdxTop) }; |
| 386 | 386 | ||
| 387 | // Best to start from level 1, but in some cases it might be a C function | 387 | // Best to start from level 1, but in some cases it might be a C function |
| 388 | // and we don't get '.currentline' for that. It's okay - just keep level | 388 | // and we don't get '.currentline' for that. It's okay - just keep level |
| @@ -393,25 +393,25 @@ int Lane::LuaErrorHandler(lua_State* L_) | |||
| 393 | lua_getinfo(L_, _extended ? "Sln" : "Sl", &_ar); | 393 | lua_getinfo(L_, _extended ? "Sln" : "Sl", &_ar); |
| 394 | if (_extended) { | 394 | if (_extended) { |
| 395 | lua_newtable(L_); // L_: some_error {} {} | 395 | lua_newtable(L_); // L_: some_error {} {} |
| 396 | StackIndex const kIdxFrameTbl{ luaG_absindex(L_, kIdxTop) }; | 396 | StackIndex const kIdxFrameTbl{ luaW_absindex(L_, kIdxTop) }; |
| 397 | lua_pushstring(L_, _ar.source); // L_: some_error {} {} source | 397 | lua_pushstring(L_, _ar.source); // L_: some_error {} {} source |
| 398 | luaG_setfield(L_, kIdxFrameTbl, std::string_view{ "source" }); // L_: some_error {} {} | 398 | luaW_setfield(L_, kIdxFrameTbl, std::string_view{ "source" }); // L_: some_error {} {} |
| 399 | 399 | ||
| 400 | lua_pushinteger(L_, _ar.currentline); // L_: some_error {} {} currentline | 400 | lua_pushinteger(L_, _ar.currentline); // L_: some_error {} {} currentline |
| 401 | luaG_setfield(L_, kIdxFrameTbl, std::string_view{ "currentline" }); // L_: some_error {} {} | 401 | luaW_setfield(L_, kIdxFrameTbl, std::string_view{ "currentline" }); // L_: some_error {} {} |
| 402 | 402 | ||
| 403 | lua_pushstring(L_, _ar.name ? _ar.name : "<?>"); // L_: some_error {} {} name | 403 | lua_pushstring(L_, _ar.name ? _ar.name : "<?>"); // L_: some_error {} {} name |
| 404 | luaG_setfield(L_, kIdxFrameTbl, std::string_view{ "name" }); // L_: some_error {} {} | 404 | luaW_setfield(L_, kIdxFrameTbl, std::string_view{ "name" }); // L_: some_error {} {} |
| 405 | 405 | ||
| 406 | lua_pushstring(L_, _ar.namewhat); // L_: some_error {} {} namewhat | 406 | lua_pushstring(L_, _ar.namewhat); // L_: some_error {} {} namewhat |
| 407 | luaG_setfield(L_, kIdxFrameTbl, std::string_view{ "namewhat" }); // L_: some_error {} {} | 407 | luaW_setfield(L_, kIdxFrameTbl, std::string_view{ "namewhat" }); // L_: some_error {} {} |
| 408 | 408 | ||
| 409 | lua_pushstring(L_, _ar.what); // L_: some_error {} {} what | 409 | lua_pushstring(L_, _ar.what); // L_: some_error {} {} what |
| 410 | luaG_setfield(L_, kIdxFrameTbl, std::string_view{ "what" }); // L_: some_error {} {} | 410 | luaW_setfield(L_, kIdxFrameTbl, std::string_view{ "what" }); // L_: some_error {} {} |
| 411 | } else if (_ar.currentline > 0) { | 411 | } else if (_ar.currentline > 0) { |
| 412 | luaG_pushstring(L_, "%s:%d", _ar.short_src, _ar.currentline); // L_: some_error {} "blah:blah" | 412 | luaW_pushstring(L_, "%s:%d", _ar.short_src, _ar.currentline); // L_: some_error {} "blah:blah" |
| 413 | } else { | 413 | } else { |
| 414 | luaG_pushstring(L_, "%s:?", _ar.short_src); // L_: some_error {} "blah" | 414 | luaW_pushstring(L_, "%s:?", _ar.short_src); // L_: some_error {} "blah" |
| 415 | } | 415 | } |
| 416 | lua_rawseti(L_, kIdxTraceTbl, static_cast<lua_Integer>(_n)); // L_: some_error {} | 416 | lua_rawseti(L_, kIdxTraceTbl, static_cast<lua_Integer>(_n)); // L_: some_error {} |
| 417 | } | 417 | } |
| @@ -448,7 +448,7 @@ static int PushStackTrace(lua_State* const L_, Lane::ErrorTraceLevel const error | |||
| 448 | 448 | ||
| 449 | // For cancellation the error message is kCancelError, and a stack trace isn't placed | 449 | // For cancellation the error message is kCancelError, and a stack trace isn't placed |
| 450 | // For other errors, the message can be whatever was thrown, and we should have a stack trace table | 450 | // For other errors, the message can be whatever was thrown, and we should have a stack trace table |
| 451 | LUA_ASSERT(L_, luaG_type(L_, StackIndex{ 1 + stk_base_ }) == (kCancelError.equals(L_, stk_base_) ? LuaType::NIL : LuaType::TABLE)); | 451 | LUA_ASSERT(L_, luaW_type(L_, StackIndex{ 1 + stk_base_ }) == (kCancelError.equals(L_, stk_base_) ? LuaType::NIL : LuaType::TABLE)); |
| 452 | // Just leaving the stack trace table on the stack is enough to get it through to the master. | 452 | // Just leaving the stack trace table on the stack is enough to get it through to the master. |
| 453 | } else { | 453 | } else { |
| 454 | // any kind of error can be thrown with error(), or through a lane/linda cancellation | 454 | // 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 | |||
| 460 | case LuaError::ERRERR: // error while running the error handler (if any, for example an out-of-memory condition) | 460 | case LuaError::ERRERR: // error while running the error handler (if any, for example an out-of-memory condition) |
| 461 | default: | 461 | default: |
| 462 | // the Lua core provides a string error message in those situations | 462 | // the Lua core provides a string error message in those situations |
| 463 | LUA_ASSERT(L_, (lua_gettop(L_) == stk_base_) && (luaG_type(L_, stk_base_) == LuaType::STRING)); | 463 | LUA_ASSERT(L_, (lua_gettop(L_) == stk_base_) && (luaW_type(L_, stk_base_) == LuaType::STRING)); |
| 464 | break; | 464 | break; |
| 465 | } | 465 | } |
| 466 | return lua_gettop(L_) - _top; // either 0 or 1 | 466 | return lua_gettop(L_) - _top; // either 0 or 1 |
| @@ -509,7 +509,7 @@ static LuaError run_finalizers(Lane* const lane_, Lane::ErrorTraceLevel const er | |||
| 509 | LUA_ASSERT(_L, lua_isfunction(_L, -1)); | 509 | LUA_ASSERT(_L, lua_isfunction(_L, -1)); |
| 510 | if (lua_rc_ != LuaError::OK) { // we have <error>, [trace] on the thread stack | 510 | if (lua_rc_ != LuaError::OK) { // we have <error>, [trace] on the thread stack |
| 511 | LUA_ASSERT(_L, lane_->nresults == 1 || lane_->nresults == 2); | 511 | LUA_ASSERT(_L, lane_->nresults == 1 || lane_->nresults == 2); |
| 512 | //std::string_view const _err_msg{ luaG_tostring(_L, 1) }; | 512 | //std::string_view const _err_msg{ luaW_tostring(_L, 1) }; |
| 513 | if (lane_->isCoroutine()) { | 513 | if (lane_->isCoroutine()) { |
| 514 | // transfer them on the main state | 514 | // transfer them on the main state |
| 515 | lua_pushvalue(lane_->L, 1); | 515 | lua_pushvalue(lane_->L, 1); |
| @@ -561,7 +561,7 @@ static LuaError run_finalizers(Lane* const lane_, Lane::ErrorTraceLevel const er | |||
| 561 | 561 | ||
| 562 | if (lane_->isCoroutine()) { | 562 | if (lane_->isCoroutine()) { |
| 563 | // only the coroutine thread should remain on the master state when we are done | 563 | // only the coroutine thread should remain on the master state when we are done |
| 564 | LUA_ASSERT(_L, lua_gettop(_L) == 1 && luaG_type(_L, StackIndex{ 1 }) == LuaType::THREAD); | 564 | LUA_ASSERT(_L, lua_gettop(_L) == 1 && luaW_type(_L, StackIndex{ 1 }) == LuaType::THREAD); |
| 565 | } | 565 | } |
| 566 | 566 | ||
| 567 | return _rc; | 567 | return _rc; |
| @@ -674,7 +674,7 @@ static void lane_main(Lane* const lane_) | |||
| 674 | do { | 674 | do { |
| 675 | // starting with Lua 5.4, lua_resume can leave more stuff on the stack below the actual yielded values. | 675 | // starting with Lua 5.4, lua_resume can leave more stuff on the stack below the actual yielded values. |
| 676 | // that's why we have lane_->nresults | 676 | // that's why we have lane_->nresults |
| 677 | _rc = luaG_resume(_L, nullptr, _nargs, &lane_->nresults); // L: ... retvals|err... | 677 | _rc = luaW_resume(_L, nullptr, _nargs, &lane_->nresults); // L: ... retvals|err... |
| 678 | if (_rc == LuaError::YIELD) { | 678 | if (_rc == LuaError::YIELD) { |
| 679 | // on the stack we find the values pushed by lane:resume() | 679 | // on the stack we find the values pushed by lane:resume() |
| 680 | _nargs = lua_gettop(_L); | 680 | _nargs = lua_gettop(_L); |
| @@ -748,7 +748,7 @@ static void lane_main(Lane* const lane_) | |||
| 748 | // in case of error and if it exists, fetch stack trace from registry and push it | 748 | // in case of error and if it exists, fetch stack trace from registry and push it |
| 749 | lane_->nresults += PushStackTrace(_L, lane_->errorTraceLevel, _rc, StackIndex{ 1 }); // L: retvals|error [trace] | 749 | lane_->nresults += PushStackTrace(_L, lane_->errorTraceLevel, _rc, StackIndex{ 1 }); // L: retvals|error [trace] |
| 750 | 750 | ||
| 751 | DEBUGSPEW_CODE(DebugSpew(lane_->U) << "Lane " << _L << " body: " << GetErrcodeName(_rc) << " (" << (kCancelError.equals(_L, StackIndex{ 1 }) ? "cancelled" : luaG_typename(_L, StackIndex{ 1 })) << ")" << std::endl); | 751 | DEBUGSPEW_CODE(DebugSpew(lane_->U) << "Lane " << _L << " body: " << GetErrcodeName(_rc) << " (" << (kCancelError.equals(_L, StackIndex{ 1 }) ? "cancelled" : luaW_typename(_L, StackIndex{ 1 })) << ")" << std::endl); |
| 752 | // Call finalizers, if the script has set them up. | 752 | // Call finalizers, if the script has set them up. |
| 753 | // If the lane is not a coroutine, there is only a regular state, so everything is the same whether we use S or L. | 753 | // If the lane is not a coroutine, there is only a regular state, so everything is the same whether we use S or L. |
| 754 | // 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 | 754 | // 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) | |||
| 797 | lua_settop(L_, 1); // L_: lane | 797 | lua_settop(L_, 1); // L_: lane |
| 798 | 798 | ||
| 799 | // no error if the lane body doesn't return a non-nil first value | 799 | // no error if the lane body doesn't return a non-nil first value |
| 800 | luaG_pushstring(L_, "close"); // L_: lane "close" | 800 | luaW_pushstring(L_, "close"); // L_: lane "close" |
| 801 | lua_pushcclosure(L_, LG_lane_join, 1); // L_: lane join() | 801 | lua_pushcclosure(L_, LG_lane_join, 1); // L_: lane join() |
| 802 | lua_insert(L_, 1); // L_: join() lane | 802 | lua_insert(L_, 1); // L_: join() lane |
| 803 | lua_call(L_, 1, LUA_MULTRET); // L_: join() results | 803 | lua_call(L_, 1, LUA_MULTRET); // L_: join() results |
| @@ -827,9 +827,9 @@ static LUAG_FUNC(lane_gc) | |||
| 827 | // if there a gc callback? | 827 | // if there a gc callback? |
| 828 | lua_getiuservalue(L_, StackIndex{ 1 }, UserValueIndex{ 1 }); // L_: ud uservalue | 828 | lua_getiuservalue(L_, StackIndex{ 1 }, UserValueIndex{ 1 }); // L_: ud uservalue |
| 829 | kLaneGC.pushKey(L_); // L_: ud uservalue __gc | 829 | kLaneGC.pushKey(L_); // L_: ud uservalue __gc |
| 830 | if (luaG_rawget(L_, StackIndex{ -2 }) != LuaType::NIL) { // L_: ud uservalue gc_cb|nil | 830 | if (luaW_rawget(L_, StackIndex{ -2 }) != LuaType::NIL) { // L_: ud uservalue gc_cb|nil |
| 831 | lua_remove(L_, -2); // L_: ud gc_cb|nil | 831 | lua_remove(L_, -2); // L_: ud gc_cb|nil |
| 832 | luaG_pushstring(L_, _lane->getDebugName()); // L_: ud gc_cb name | 832 | luaW_pushstring(L_, _lane->getDebugName()); // L_: ud gc_cb name |
| 833 | _have_gc_cb = true; | 833 | _have_gc_cb = true; |
| 834 | } else { | 834 | } else { |
| 835 | lua_pop(L_, 2); // L_: ud | 835 | lua_pop(L_, 2); // L_: ud |
| @@ -840,7 +840,7 @@ static LUAG_FUNC(lane_gc) | |||
| 840 | // still running: will have to be cleaned up later | 840 | // still running: will have to be cleaned up later |
| 841 | _lane->selfdestructAdd(); | 841 | _lane->selfdestructAdd(); |
| 842 | if (_have_gc_cb) { | 842 | if (_have_gc_cb) { |
| 843 | luaG_pushstring(L_, "selfdestruct"); // L_: ud gc_cb name status | 843 | luaW_pushstring(L_, "selfdestruct"); // L_: ud gc_cb name status |
| 844 | lua_call(L_, 2, 0); // L_: ud | 844 | lua_call(L_, 2, 0); // L_: ud |
| 845 | } | 845 | } |
| 846 | return 0; | 846 | return 0; |
| @@ -855,7 +855,7 @@ static LUAG_FUNC(lane_gc) | |||
| 855 | 855 | ||
| 856 | // do this after lane cleanup in case the callback triggers an error | 856 | // do this after lane cleanup in case the callback triggers an error |
| 857 | if (_have_gc_cb) { | 857 | if (_have_gc_cb) { |
| 858 | luaG_pushstring(L_, "closed"); // L_: ud gc_cb name status | 858 | luaW_pushstring(L_, "closed"); // L_: ud gc_cb name status |
| 859 | lua_call(L_, 2, 0); // L_: ud | 859 | lua_call(L_, 2, 0); // L_: ud |
| 860 | } | 860 | } |
| 861 | return 0; | 861 | return 0; |
| @@ -900,7 +900,7 @@ void Lane::applyDebugName() const | |||
| 900 | { | 900 | { |
| 901 | if constexpr (HAVE_DECODA_SUPPORT()) { | 901 | if constexpr (HAVE_DECODA_SUPPORT()) { |
| 902 | // to see VM name in Decoda debugger Virtual Machine window | 902 | // to see VM name in Decoda debugger Virtual Machine window |
| 903 | luaG_pushstring(L, debugName); // L: ... "name" | 903 | luaW_pushstring(L, debugName); // L: ... "name" |
| 904 | lua_setglobal(L, "decoda_name"); // L: ... | 904 | lua_setglobal(L, "decoda_name"); // L: ... |
| 905 | } | 905 | } |
| 906 | // and finally set the OS thread name | 906 | // and finally set the OS thread name |
| @@ -1013,7 +1013,7 @@ void Lane::PushMetatable(lua_State* const L_) | |||
| 1013 | { | 1013 | { |
| 1014 | STACK_CHECK_START_REL(L_, 0); | 1014 | STACK_CHECK_START_REL(L_, 0); |
| 1015 | if (luaL_newmetatable(L_, kLaneMetatableName.data())) { // L_: mt | 1015 | if (luaL_newmetatable(L_, kLaneMetatableName.data())) { // L_: mt |
| 1016 | luaG_registerlibfuncs(L_, local::sLaneFunctions); | 1016 | luaW_registerlibfuncs(L_, local::sLaneFunctions); |
| 1017 | // cache error() and tostring() | 1017 | // cache error() and tostring() |
| 1018 | kCachedError.pushKey(L_); // L_: mt kCachedError | 1018 | kCachedError.pushKey(L_); // L_: mt kCachedError |
| 1019 | lua_getglobal(L_, "error"); // L_: mt kCachedError error() | 1019 | lua_getglobal(L_, "error"); // L_: mt kCachedError error() |
| @@ -1022,7 +1022,7 @@ void Lane::PushMetatable(lua_State* const L_) | |||
| 1022 | lua_getglobal(L_, "tostring"); // L_: mt kCachedTostring tostring() | 1022 | lua_getglobal(L_, "tostring"); // L_: mt kCachedTostring tostring() |
| 1023 | lua_rawset(L_, -3); // L_: mt | 1023 | lua_rawset(L_, -3); // L_: mt |
| 1024 | // hide the actual metatable from getmetatable() | 1024 | // hide the actual metatable from getmetatable() |
| 1025 | luaG_pushstring(L_, kLaneMetatableName); // L_: mt "Lane" | 1025 | luaW_pushstring(L_, kLaneMetatableName); // L_: mt "Lane" |
| 1026 | lua_setfield(L_, -2, "__metatable"); // L_: mt | 1026 | lua_setfield(L_, -2, "__metatable"); // L_: mt |
| 1027 | } | 1027 | } |
| 1028 | STACK_CHECK(L_, 1); | 1028 | STACK_CHECK(L_, 1); |
| @@ -1035,7 +1035,7 @@ void Lane::pushStatusString(lua_State* const L_) const | |||
| 1035 | std::string_view const _str{ threadStatusString() }; | 1035 | std::string_view const _str{ threadStatusString() }; |
| 1036 | LUA_ASSERT(L_, !_str.empty()); | 1036 | LUA_ASSERT(L_, !_str.empty()); |
| 1037 | 1037 | ||
| 1038 | luaG_pushstring(L_, _str); | 1038 | luaW_pushstring(L_, _str); |
| 1039 | } | 1039 | } |
| 1040 | 1040 | ||
| 1041 | // ################################################################################################# | 1041 | // ################################################################################################# |
| @@ -1175,7 +1175,7 @@ std::string_view Lane::pushErrorTraceLevel(lua_State* L_) const | |||
| 1175 | std::string_view const _str{ errorTraceLevelString() }; | 1175 | std::string_view const _str{ errorTraceLevelString() }; |
| 1176 | LUA_ASSERT(L_, !_str.empty()); | 1176 | LUA_ASSERT(L_, !_str.empty()); |
| 1177 | 1177 | ||
| 1178 | return luaG_pushstring(L_, _str); | 1178 | return luaW_pushstring(L_, _str); |
| 1179 | } | 1179 | } |
| 1180 | 1180 | ||
| 1181 | // ################################################################################################# | 1181 | // ################################################################################################# |
| @@ -1186,7 +1186,7 @@ void Lane::resetResultsStorage(lua_State* const L_, StackIndex const self_idx_) | |||
| 1186 | { | 1186 | { |
| 1187 | STACK_GROW(L_, 4); | 1187 | STACK_GROW(L_, 4); |
| 1188 | STACK_CHECK_START_REL(L_, 0); | 1188 | STACK_CHECK_START_REL(L_, 0); |
| 1189 | StackIndex const _self_idx{ luaG_absindex(L_, self_idx_) }; | 1189 | StackIndex const _self_idx{ luaW_absindex(L_, self_idx_) }; |
| 1190 | LUA_ASSERT(L_, ToLane(L_, _self_idx) == this); // L_: ... self ... | 1190 | LUA_ASSERT(L_, ToLane(L_, _self_idx) == this); // L_: ... self ... |
| 1191 | // create the new table | 1191 | // create the new table |
| 1192 | lua_newtable(L_); // L_: ... self ... {} | 1192 | lua_newtable(L_); // L_: ... self ... {} |
| @@ -1220,7 +1220,7 @@ void Lane::securizeDebugName(lua_State* const L_) | |||
| 1220 | lua_newtable(L_); // L_: lane ... {uv} {} | 1220 | lua_newtable(L_); // L_: lane ... {uv} {} |
| 1221 | { | 1221 | { |
| 1222 | std::lock_guard<std::mutex> _guard{ debugNameMutex }; | 1222 | std::lock_guard<std::mutex> _guard{ debugNameMutex }; |
| 1223 | debugName = luaG_pushstring(L_, debugName); // L_: lane ... {uv} {} name | 1223 | debugName = luaW_pushstring(L_, debugName); // L_: lane ... {uv} {} name |
| 1224 | } | 1224 | } |
| 1225 | lua_rawset(L_, -3); // L_: lane ... {uv} | 1225 | lua_rawset(L_, -3); // L_: lane ... {uv} |
| 1226 | lua_pop(L_, 1); // L_: lane | 1226 | lua_pop(L_, 1); // L_: lane |
| @@ -1243,13 +1243,13 @@ void Lane::storeDebugName(std::string_view const& name_) | |||
| 1243 | { | 1243 | { |
| 1244 | STACK_CHECK_START_REL(L, 0); | 1244 | STACK_CHECK_START_REL(L, 0); |
| 1245 | // 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... | 1245 | // 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... |
| 1246 | kLaneNameRegKey.setValue(L, [name = name_](lua_State* L_) { luaG_pushstring(L_, name); }); | 1246 | kLaneNameRegKey.setValue(L, [name = name_](lua_State* L_) { luaW_pushstring(L_, name); }); |
| 1247 | STACK_CHECK(L, 0); | 1247 | STACK_CHECK(L, 0); |
| 1248 | kLaneNameRegKey.pushValue(L); // L: ... "name" ... | 1248 | kLaneNameRegKey.pushValue(L); // L: ... "name" ... |
| 1249 | // keep a direct view on the stored string | 1249 | // keep a direct view on the stored string |
| 1250 | { | 1250 | { |
| 1251 | std::lock_guard<std::mutex> _guard{ debugNameMutex }; | 1251 | std::lock_guard<std::mutex> _guard{ debugNameMutex }; |
| 1252 | debugName = luaG_tostring(L, kIdxTop); | 1252 | debugName = luaW_tostring(L, kIdxTop); |
| 1253 | } | 1253 | } |
| 1254 | lua_pop(L, 1); | 1254 | lua_pop(L, 1); |
| 1255 | STACK_CHECK(L, 0); | 1255 | STACK_CHECK(L, 0); |
| @@ -1283,7 +1283,7 @@ int Lane::storeResults(lua_State* const L_) | |||
| 1283 | default: | 1283 | default: |
| 1284 | // this is an internal error, we probably never get here | 1284 | // this is an internal error, we probably never get here |
| 1285 | lua_settop(L_, 0); // L_: | 1285 | lua_settop(L_, 0); // L_: |
| 1286 | luaG_pushstring(L_, "Unexpected status: "); // L_: "Unexpected status: " | 1286 | luaW_pushstring(L_, "Unexpected status: "); // L_: "Unexpected status: " |
| 1287 | pushStatusString(L_); // L_: "Unexpected status: " "<status>" | 1287 | pushStatusString(L_); // L_: "Unexpected status: " "<status>" |
| 1288 | lua_concat(L_, 2); // L_: "Unexpected status: <status>" | 1288 | lua_concat(L_, 2); // L_: "Unexpected status: <status>" |
| 1289 | raise_lua_error(L_); | 1289 | raise_lua_error(L_); |
| @@ -1421,7 +1421,7 @@ bool Lane::waitForJoin(lua_State* const L_, std::chrono::time_point<std::chrono: | |||
| 1421 | 1421 | ||
| 1422 | if (!_done) { | 1422 | if (!_done) { |
| 1423 | lua_pushnil(L_); // L_: lane nil | 1423 | lua_pushnil(L_); // L_: lane nil |
| 1424 | luaG_pushstring(L_, "timeout"); // L_: lane nil "timeout" | 1424 | luaW_pushstring(L_, "timeout"); // L_: lane nil "timeout" |
| 1425 | return false; | 1425 | return false; |
| 1426 | } | 1426 | } |
| 1427 | } | 1427 | } |
| @@ -1437,7 +1437,7 @@ bool Lane::waitForJoin(lua_State* const L_, std::chrono::time_point<std::chrono: | |||
| 1437 | 1437 | ||
| 1438 | if (!_done) { | 1438 | if (!_done) { |
| 1439 | lua_pushnil(L_); // L_: lane nil | 1439 | lua_pushnil(L_); // L_: lane nil |
| 1440 | luaG_pushstring(L_, "timeout"); // L_: lane nil "timeout" | 1440 | luaW_pushstring(L_, "timeout"); // L_: lane nil "timeout" |
| 1441 | return false; | 1441 | return false; |
| 1442 | } | 1442 | } |
| 1443 | } | 1443 | } |
diff --git a/src/lanes.cpp b/src/lanes.cpp index 0eaeb3e..d9ac4df 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp | |||
| @@ -173,7 +173,7 @@ LUAG_FUNC(sleep) | |||
| 173 | lua_pushcfunction(L_, LG_linda_receive); // L_: duration|nil receive() | 173 | lua_pushcfunction(L_, LG_linda_receive); // L_: duration|nil receive() |
| 174 | STACK_CHECK_START_REL(L_, 0); // we pushed the function we intend to call, now prepare the arguments | 174 | STACK_CHECK_START_REL(L_, 0); // we pushed the function we intend to call, now prepare the arguments |
| 175 | _U->timerLinda->push(L_); // L_: duration|nil receive() timerLinda | 175 | _U->timerLinda->push(L_); // L_: duration|nil receive() timerLinda |
| 176 | if (luaG_tostring(L_, StackIndex{ 1 }) == "indefinitely") { | 176 | if (luaW_tostring(L_, StackIndex{ 1 }) == "indefinitely") { |
| 177 | lua_pushnil(L_); // L_: duration? receive() timerLinda nil | 177 | lua_pushnil(L_); // L_: duration? receive() timerLinda nil |
| 178 | } else if (lua_isnoneornil(L_, 1)) { | 178 | } else if (lua_isnoneornil(L_, 1)) { |
| 179 | lua_pushnumber(L_, 0); // L_: duration? receive() timerLinda 0 | 179 | lua_pushnumber(L_, 0); // L_: duration? receive() timerLinda 0 |
| @@ -183,7 +183,7 @@ LUAG_FUNC(sleep) | |||
| 183 | else { | 183 | else { |
| 184 | lua_pushnumber(L_, lua_tonumber(L_, 1)); // L_: duration? receive() timerLinda duration | 184 | lua_pushnumber(L_, lua_tonumber(L_, 1)); // L_: duration? receive() timerLinda duration |
| 185 | } | 185 | } |
| 186 | luaG_pushstring(L_, "ac100de1-a696-4619-b2f0-a26de9d58ab8"); // L_: duration? receive() timerLinda duration key | 186 | luaW_pushstring(L_, "ac100de1-a696-4619-b2f0-a26de9d58ab8"); // L_: duration? receive() timerLinda duration key |
| 187 | STACK_CHECK(L_, 3); // 3 arguments ready | 187 | STACK_CHECK(L_, 3); // 3 arguments ready |
| 188 | lua_call(L_, 3, LUA_MULTRET); // timerLinda:receive(duration,key) // L_: duration? result... | 188 | lua_call(L_, 3, LUA_MULTRET); // timerLinda:receive(duration,key) // L_: duration? result... |
| 189 | return lua_gettop(L_) - 1; | 189 | return lua_gettop(L_) - 1; |
| @@ -197,7 +197,7 @@ LUAG_FUNC(sleep) | |||
| 197 | // upvalue[1]: _G.require | 197 | // upvalue[1]: _G.require |
| 198 | LUAG_FUNC(require) | 198 | LUAG_FUNC(require) |
| 199 | { | 199 | { |
| 200 | std::string_view const _name{ luaG_tostring(L_, StackIndex{ 1 }) }; // L_: "name" ... | 200 | std::string_view const _name{ luaW_tostring(L_, StackIndex{ 1 }) }; // L_: "name" ... |
| 201 | int const _nargs{ lua_gettop(L_) }; | 201 | int const _nargs{ lua_gettop(L_) }; |
| 202 | DEBUGSPEW_CODE(Universe * _U{ Universe::Get(L_) }); | 202 | DEBUGSPEW_CODE(Universe * _U{ Universe::Get(L_) }); |
| 203 | STACK_CHECK_START_REL(L_, 0); | 203 | STACK_CHECK_START_REL(L_, 0); |
| @@ -223,8 +223,8 @@ int lanes_register(lua_State* const L_) | |||
| 223 | if (!_U) { | 223 | if (!_U) { |
| 224 | raise_luaL_error(L_, "Lanes is not ready"); | 224 | raise_luaL_error(L_, "Lanes is not ready"); |
| 225 | } | 225 | } |
| 226 | std::string_view const _name{ luaG_checkstring(L_, StackIndex{ 1 }) }; | 226 | std::string_view const _name{ luaW_checkstring(L_, StackIndex{ 1 }) }; |
| 227 | LuaType const _mod_type{ luaG_type(L_, StackIndex{ 2 }) }; | 227 | LuaType const _mod_type{ luaW_type(L_, StackIndex{ 2 }) }; |
| 228 | // ignore extra arguments, just in case | 228 | // ignore extra arguments, just in case |
| 229 | lua_settop(L_, 2); | 229 | lua_settop(L_, 2); |
| 230 | luaL_argcheck(L_, (_mod_type == LuaType::TABLE) || (_mod_type == LuaType::FUNCTION), 2, "unexpected module type"); | 230 | luaL_argcheck(L_, (_mod_type == LuaType::TABLE) || (_mod_type == LuaType::FUNCTION), 2, "unexpected module type"); |
| @@ -292,7 +292,7 @@ LUAG_FUNC(lane_new) | |||
| 292 | Universe* const _U{ Universe::Get(L_) }; | 292 | Universe* const _U{ Universe::Get(L_) }; |
| 293 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: setup" << std::endl); | 293 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: setup" << std::endl); |
| 294 | 294 | ||
| 295 | std::optional<std::string_view> _libs_str{ lua_isnil(L_, kLibsIdx) ? std::nullopt : std::make_optional(luaG_tostring(L_, kLibsIdx)) }; | 295 | std::optional<std::string_view> _libs_str{ lua_isnil(L_, kLibsIdx) ? std::nullopt : std::make_optional(luaW_tostring(L_, kLibsIdx)) }; |
| 296 | lua_State* const _S{ state::NewLaneState(_U, SourceState{ L_ }, _libs_str) }; // L_: [fixed] ... L2: | 296 | lua_State* const _S{ state::NewLaneState(_U, SourceState{ L_ }, _libs_str) }; // L_: [fixed] ... L2: |
| 297 | STACK_CHECK_START_REL(_S, 0); | 297 | STACK_CHECK_START_REL(_S, 0); |
| 298 | 298 | ||
| @@ -354,7 +354,7 @@ LUAG_FUNC(lane_new) | |||
| 354 | DEBUGSPEW_CODE(DebugSpew(lane->U) << "lane_new: preparing lane userdata" << std::endl); | 354 | DEBUGSPEW_CODE(DebugSpew(lane->U) << "lane_new: preparing lane userdata" << std::endl); |
| 355 | STACK_CHECK_START_REL(L, 0); | 355 | STACK_CHECK_START_REL(L, 0); |
| 356 | // a Lane full userdata needs a single uservalue | 356 | // a Lane full userdata needs a single uservalue |
| 357 | Lane** const _ud{ luaG_newuserdatauv<Lane*>(L, UserValueCount{ 1 }) }; // L: ... lane | 357 | Lane** const _ud{ luaW_newuserdatauv<Lane*>(L, UserValueCount{ 1 }) }; // L: ... lane |
| 358 | *_ud = lane; // don't forget to store the pointer in the userdata! | 358 | *_ud = lane; // don't forget to store the pointer in the userdata! |
| 359 | 359 | ||
| 360 | // Set metatable for the userdata | 360 | // Set metatable for the userdata |
| @@ -378,25 +378,25 @@ LUAG_FUNC(lane_new) | |||
| 378 | lua_setiuservalue(L, StackIndex{ -2 }, UserValueIndex{ 1 }); // L: ... lane | 378 | lua_setiuservalue(L, StackIndex{ -2 }, UserValueIndex{ 1 }); // L: ... lane |
| 379 | 379 | ||
| 380 | StackIndex const _name_idx{ lua_isnoneornil(L, kNameIdx) ? kIdxNone : kNameIdx }; | 380 | StackIndex const _name_idx{ lua_isnoneornil(L, kNameIdx) ? kIdxNone : kNameIdx }; |
| 381 | std::string_view _debugName{ (_name_idx > 0) ? luaG_tostring(L, _name_idx) : std::string_view{} }; | 381 | std::string_view _debugName{ (_name_idx > 0) ? luaW_tostring(L, _name_idx) : std::string_view{} }; |
| 382 | if (!_debugName.empty()) | 382 | if (!_debugName.empty()) |
| 383 | { | 383 | { |
| 384 | if (_debugName == "auto") { | 384 | if (_debugName == "auto") { |
| 385 | if (luaG_type(L, kFuncIdx) == LuaType::STRING) { | 385 | if (luaW_type(L, kFuncIdx) == LuaType::STRING) { |
| 386 | lua_Debug _ar; | 386 | lua_Debug _ar; |
| 387 | if (lua_getstack(L, 2, &_ar) == 0) { // 0 is here, 1 is lanes.gen, 2 is its caller | 387 | if (lua_getstack(L, 2, &_ar) == 0) { // 0 is here, 1 is lanes.gen, 2 is its caller |
| 388 | lua_getstack(L, 1, &_ar); // level 2 may not exist with LuaJIT, try again with level 1 | 388 | lua_getstack(L, 1, &_ar); // level 2 may not exist with LuaJIT, try again with level 1 |
| 389 | } | 389 | } |
| 390 | lua_getinfo(L, "Sl", &_ar); | 390 | lua_getinfo(L, "Sl", &_ar); |
| 391 | luaG_pushstring(L, "%s:%d", _ar.short_src, _ar.currentline); // L: ... lane "<name>" | 391 | luaW_pushstring(L, "%s:%d", _ar.short_src, _ar.currentline); // L: ... lane "<name>" |
| 392 | } else { | 392 | } else { |
| 393 | lua_Debug _ar; | 393 | lua_Debug _ar; |
| 394 | lua_pushvalue(L, kFuncIdx); // L: ... lane func | 394 | lua_pushvalue(L, kFuncIdx); // L: ... lane func |
| 395 | lua_getinfo(L, ">S", &_ar); // L: ... lane | 395 | lua_getinfo(L, ">S", &_ar); // L: ... lane |
| 396 | luaG_pushstring(L, "%s:%d", _ar.short_src, _ar.linedefined); // L: ... lane "<name>" | 396 | luaW_pushstring(L, "%s:%d", _ar.short_src, _ar.linedefined); // L: ... lane "<name>" |
| 397 | } | 397 | } |
| 398 | lua_replace(L, _name_idx); // L: ... lane | 398 | lua_replace(L, _name_idx); // L: ... lane |
| 399 | _debugName = luaG_tostring(L, _name_idx); | 399 | _debugName = luaW_tostring(L, _name_idx); |
| 400 | } | 400 | } |
| 401 | lane->storeDebugName(_debugName); | 401 | lane->storeDebugName(_debugName); |
| 402 | } | 402 | } |
| @@ -461,17 +461,17 @@ LUAG_FUNC(lane_new) | |||
| 461 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: process 'required' list" << std::endl); | 461 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: process 'required' list" << std::endl); |
| 462 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); | 462 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); |
| 463 | // should not happen, was checked in lanes.lua before calling lane_new() | 463 | // should not happen, was checked in lanes.lua before calling lane_new() |
| 464 | if (luaG_type(L_, _required_idx) != LuaType::TABLE) { | 464 | if (luaW_type(L_, _required_idx) != LuaType::TABLE) { |
| 465 | raise_luaL_error(L_, "expected required module list as a table, got %s", luaL_typename(L_, _required_idx)); | 465 | raise_luaL_error(L_, "expected required module list as a table, got %s", luaL_typename(L_, _required_idx)); |
| 466 | } | 466 | } |
| 467 | 467 | ||
| 468 | lua_pushnil(L_); // L_: [fixed] args... nil L2: | 468 | lua_pushnil(L_); // L_: [fixed] args... nil L2: |
| 469 | while (lua_next(L_, _required_idx) != 0) { // L_: [fixed] args... n "modname" L2: | 469 | while (lua_next(L_, _required_idx) != 0) { // L_: [fixed] args... n "modname" L2: |
| 470 | if (luaG_type(L_, kIdxTop) != LuaType::STRING || luaG_type(L_, StackIndex{ -2 }) != LuaType::NUMBER || lua_tonumber(L_, -2) != _nbRequired) { | 470 | if (luaW_type(L_, kIdxTop) != LuaType::STRING || luaW_type(L_, StackIndex{ -2 }) != LuaType::NUMBER || lua_tonumber(L_, -2) != _nbRequired) { |
| 471 | raise_luaL_error(L_, "required module list should be a list of strings"); | 471 | raise_luaL_error(L_, "required module list should be a list of strings"); |
| 472 | } else { | 472 | } else { |
| 473 | // require the module in the target state, and populate the lookup table there too | 473 | // require the module in the target state, and populate the lookup table there too |
| 474 | std::string_view const _name{ luaG_tostring(L_, kIdxTop) }; | 474 | std::string_view const _name{ luaW_tostring(L_, kIdxTop) }; |
| 475 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: require '" << _name << "'" << std::endl); | 475 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: require '" << _name << "'" << std::endl); |
| 476 | 476 | ||
| 477 | // require the module in the target lane | 477 | // require the module in the target lane |
| @@ -480,7 +480,7 @@ LUAG_FUNC(lane_new) | |||
| 480 | lua_pop(_L2, 1); // L_: [fixed] args... n "modname" L2: | 480 | lua_pop(_L2, 1); // L_: [fixed] args... n "modname" L2: |
| 481 | raise_luaL_error(L_, "cannot pre-require modules without loading 'package' library first"); | 481 | raise_luaL_error(L_, "cannot pre-require modules without loading 'package' library first"); |
| 482 | } else { | 482 | } else { |
| 483 | luaG_pushstring(_L2, _name); // L_: [fixed] args... n "modname" L2: require() name | 483 | luaW_pushstring(_L2, _name); // L_: [fixed] args... n "modname" L2: require() name |
| 484 | LuaError const _rc{ lua_pcall(_L2, 1, 1, 0) }; // L_: [fixed] args... n "modname" L2: ret/errcode | 484 | LuaError const _rc{ lua_pcall(_L2, 1, 1, 0) }; // L_: [fixed] args... n "modname" L2: ret/errcode |
| 485 | if (_rc != LuaError::OK) { | 485 | if (_rc != LuaError::OK) { |
| 486 | // propagate error to main state if any | 486 | // propagate error to main state if any |
| @@ -515,7 +515,7 @@ LUAG_FUNC(lane_new) | |||
| 515 | lua_pushnil(L_); // L_: [fixed] args... nil L2: | 515 | lua_pushnil(L_); // L_: [fixed] args... nil L2: |
| 516 | // Lua 5.2 wants us to push the globals table on the stack | 516 | // Lua 5.2 wants us to push the globals table on the stack |
| 517 | InterCopyContext _c{ _U, DestState{ _L2 }, SourceState{ L_ }, {}, {}, {}, {}, {} }; | 517 | InterCopyContext _c{ _U, DestState{ _L2 }, SourceState{ L_ }, {}, {}, {}, {}, {} }; |
| 518 | luaG_pushglobaltable(_L2); // L_: [fixed] args... nil L2: _G | 518 | luaW_pushglobaltable(_L2); // L_: [fixed] args... nil L2: _G |
| 519 | while (lua_next(L_, _globals_idx)) { // L_: [fixed] args... k v L2: _G | 519 | while (lua_next(L_, _globals_idx)) { // L_: [fixed] args... k v L2: _G |
| 520 | std::ignore = _c.interCopy(2); // L_: [fixed] args... k v L2: _G k v | 520 | std::ignore = _c.interCopy(2); // L_: [fixed] args... k v L2: _G k v |
| 521 | // assign it in L2's globals table | 521 | // assign it in L2's globals table |
| @@ -529,7 +529,7 @@ LUAG_FUNC(lane_new) | |||
| 529 | 529 | ||
| 530 | // Lane main function | 530 | // Lane main function |
| 531 | [[maybe_unused]] int const _errorHandlerCount{ _lane->pushErrorHandler() }; // L_: [fixed] args... L2: eh? | 531 | [[maybe_unused]] int const _errorHandlerCount{ _lane->pushErrorHandler() }; // L_: [fixed] args... L2: eh? |
| 532 | LuaType const _func_type{ luaG_type(L_, kFuncIdx) }; | 532 | LuaType const _func_type{ luaW_type(L_, kFuncIdx) }; |
| 533 | if (_func_type == LuaType::FUNCTION) { | 533 | if (_func_type == LuaType::FUNCTION) { |
| 534 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: transfer lane body" << std::endl); | 534 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: transfer lane body" << std::endl); |
| 535 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); | 535 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); |
| @@ -546,7 +546,7 @@ LUAG_FUNC(lane_new) | |||
| 546 | raise_luaL_error(L_, "error when parsing lane function code"); | 546 | raise_luaL_error(L_, "error when parsing lane function code"); |
| 547 | } | 547 | } |
| 548 | } else { | 548 | } else { |
| 549 | raise_luaL_error(L_, "Expected function, got %s", luaG_typename(L_, _func_type).data()); | 549 | raise_luaL_error(L_, "Expected function, got %s", luaW_typename(L_, _func_type).data()); |
| 550 | } | 550 | } |
| 551 | STACK_CHECK(L_, 0); | 551 | STACK_CHECK(L_, 0); |
| 552 | STACK_CHECK(_L2, _errorHandlerCount + 1); | 552 | STACK_CHECK(_L2, _errorHandlerCount + 1); |
| @@ -634,7 +634,7 @@ LUAG_FUNC(wakeup_conv) | |||
| 634 | 634 | ||
| 635 | STACK_CHECK_START_REL(L_, 0); | 635 | STACK_CHECK_START_REL(L_, 0); |
| 636 | auto _readInteger = [L = L_](std::string_view const& name_) { | 636 | auto _readInteger = [L = L_](std::string_view const& name_) { |
| 637 | std::ignore = luaG_getfield(L, StackIndex{ 1 }, name_); | 637 | std::ignore = luaW_getfield(L, StackIndex{ 1 }, name_); |
| 638 | lua_Integer const val{ lua_tointeger(L, -1) }; | 638 | lua_Integer const val{ lua_tointeger(L, -1) }; |
| 639 | lua_pop(L, 1); | 639 | lua_pop(L, 1); |
| 640 | return static_cast<int>(val); | 640 | return static_cast<int>(val); |
| @@ -650,7 +650,7 @@ LUAG_FUNC(wakeup_conv) | |||
| 650 | // If Lua table has '.isdst' we trust that. If it does not, we'll let | 650 | // If Lua table has '.isdst' we trust that. If it does not, we'll let |
| 651 | // 'mktime' decide on whether the time is within DST or not (value -1). | 651 | // 'mktime' decide on whether the time is within DST or not (value -1). |
| 652 | // | 652 | // |
| 653 | int const _isdst{ (luaG_getfield(L_, StackIndex{ 1 }, "isdst") == LuaType::BOOLEAN) ? lua_toboolean(L_, -1) : -1 }; | 653 | int const _isdst{ (luaW_getfield(L_, StackIndex{ 1 }, "isdst") == LuaType::BOOLEAN) ? lua_toboolean(L_, -1) : -1 }; |
| 654 | lua_pop(L_, 1); | 654 | lua_pop(L_, 1); |
| 655 | STACK_CHECK(L_, 0); | 655 | STACK_CHECK(L_, 0); |
| 656 | 656 | ||
| @@ -715,8 +715,8 @@ LUAG_FUNC(configure) | |||
| 715 | 715 | ||
| 716 | Universe* _U{ Universe::Get(L_) }; | 716 | Universe* _U{ Universe::Get(L_) }; |
| 717 | bool const _from_master_state{ _U == nullptr }; | 717 | bool const _from_master_state{ _U == nullptr }; |
| 718 | std::string_view const _name{ luaG_checkstring(L_, StackIndex{ lua_upvalueindex(1) }) }; | 718 | std::string_view const _name{ luaW_checkstring(L_, StackIndex{ lua_upvalueindex(1) }) }; |
| 719 | LUA_ASSERT(L_, luaG_type(L_, StackIndex{ 1 }) == LuaType::TABLE); | 719 | LUA_ASSERT(L_, luaW_type(L_, StackIndex{ 1 }) == LuaType::TABLE); |
| 720 | 720 | ||
| 721 | STACK_GROW(L_, 4); | 721 | STACK_GROW(L_, 4); |
| 722 | STACK_CHECK_START_ABS(L_, 1); // L_: settings | 722 | STACK_CHECK_START_ABS(L_, 1); // L_: settings |
| @@ -726,7 +726,7 @@ LUAG_FUNC(configure) | |||
| 726 | 726 | ||
| 727 | if (_U == nullptr) { | 727 | if (_U == nullptr) { |
| 728 | // 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... | 728 | // 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... |
| 729 | kLaneNameRegKey.setValue(L_, [](lua_State* L_) { luaG_pushstring(L_, "main"); }); | 729 | kLaneNameRegKey.setValue(L_, [](lua_State* L_) { luaW_pushstring(L_, "main"); }); |
| 730 | 730 | ||
| 731 | // create the universe | 731 | // create the universe |
| 732 | _U = Universe::Create(L_); // L_: settings universe | 732 | _U = Universe::Create(L_); // L_: settings universe |
| @@ -742,7 +742,7 @@ LUAG_FUNC(configure) | |||
| 742 | lua_pushnil(L_); // L_: settings M nil | 742 | lua_pushnil(L_); // L_: settings M nil |
| 743 | lua_setfield(L_, -2, "configure"); // L_: settings M | 743 | lua_setfield(L_, -2, "configure"); // L_: settings M |
| 744 | // add functions to the module's table | 744 | // add functions to the module's table |
| 745 | luaG_registerlibfuncs(L_, local::sLanesFunctions); | 745 | luaW_registerlibfuncs(L_, local::sLanesFunctions); |
| 746 | 746 | ||
| 747 | // register core.threads() only if settings say it should be available | 747 | // register core.threads() only if settings say it should be available |
| 748 | if (_U->tracker.isActive()) { | 748 | if (_U->tracker.isActive()) { |
| @@ -767,7 +767,7 @@ LUAG_FUNC(configure) | |||
| 767 | lua_pushcclosure(L_, LG_require, 1); // L_: settings M lanes.require | 767 | lua_pushcclosure(L_, LG_require, 1); // L_: settings M lanes.require |
| 768 | lua_setfield(L_, -2, "require"); // L_: settings M | 768 | lua_setfield(L_, -2, "require"); // L_: settings M |
| 769 | 769 | ||
| 770 | luaG_pushstring( | 770 | luaW_pushstring( |
| 771 | L_, | 771 | L_, |
| 772 | "%d.%d.%d", | 772 | "%d.%d.%d", |
| 773 | LANES_VERSION_MAJOR, | 773 | LANES_VERSION_MAJOR, |
| @@ -799,7 +799,7 @@ LUAG_FUNC(configure) | |||
| 799 | // don't do this when called during the initialization of a new lane, | 799 | // don't do this when called during the initialization of a new lane, |
| 800 | // because we will do it after on_state_create() is called, | 800 | // because we will do it after on_state_create() is called, |
| 801 | // and we don't want to skip _G because of caching in case globals are created then | 801 | // and we don't want to skip _G because of caching in case globals are created then |
| 802 | luaG_pushglobaltable(L_); // L_: settings M _G | 802 | luaW_pushglobaltable(L_); // L_: settings M _G |
| 803 | tools::PopulateFuncLookupTable(L_, kIdxTop, {}); | 803 | tools::PopulateFuncLookupTable(L_, kIdxTop, {}); |
| 804 | lua_pop(L_, 1); // L_: settings M | 804 | lua_pop(L_, 1); // L_: settings M |
| 805 | } | 805 | } |
| @@ -879,10 +879,10 @@ LANES_API int luaopen_lanes_core(lua_State* const L_) | |||
| 879 | 879 | ||
| 880 | // Prevent PUC-Lua/LuaJIT mismatch. Hopefully this works for MoonJIT too | 880 | // Prevent PUC-Lua/LuaJIT mismatch. Hopefully this works for MoonJIT too |
| 881 | if constexpr (LUAJIT_FLAVOR() == 0) { | 881 | if constexpr (LUAJIT_FLAVOR() == 0) { |
| 882 | if (luaG_getmodule(L_, LUA_JITLIBNAME) != LuaType::NIL) | 882 | if (luaW_getmodule(L_, LUA_JITLIBNAME) != LuaType::NIL) |
| 883 | raise_luaL_error(L_, "Lanes is built for PUC-Lua, don't run from LuaJIT"); | 883 | raise_luaL_error(L_, "Lanes is built for PUC-Lua, don't run from LuaJIT"); |
| 884 | } else { | 884 | } else { |
| 885 | if (luaG_getmodule(L_, LUA_JITLIBNAME) == LuaType::NIL) | 885 | if (luaW_getmodule(L_, LUA_JITLIBNAME) == LuaType::NIL) |
| 886 | raise_luaL_error(L_, "Lanes is built for LuaJIT, don't run from PUC-Lua"); | 886 | raise_luaL_error(L_, "Lanes is built for LuaJIT, don't run from PUC-Lua"); |
| 887 | } | 887 | } |
| 888 | lua_pop(L_, 1); // L_: | 888 | 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 { | |||
| 47 | { | 47 | { |
| 48 | STACK_CHECK_START_REL(L_, 0); | 48 | STACK_CHECK_START_REL(L_, 0); |
| 49 | for (StackIndex const _i : std::ranges::iota_view{ start_, StackIndex{ end_ + 1 } }) { | 49 | for (StackIndex const _i : std::ranges::iota_view{ start_, StackIndex{ end_ + 1 } }) { |
| 50 | LuaType const _t{ luaG_type(L_, _i) }; | 50 | LuaType const _t{ luaW_type(L_, _i) }; |
| 51 | switch (_t) { | 51 | switch (_t) { |
| 52 | case LuaType::BOOLEAN: | 52 | case LuaType::BOOLEAN: |
| 53 | case LuaType::NUMBER: | 53 | case LuaType::NUMBER: |
| @@ -109,13 +109,13 @@ namespace { | |||
| 109 | { | 109 | { |
| 110 | Linda* const _linda{ ToLinda<OPT>(L_, idx_) }; | 110 | Linda* const _linda{ ToLinda<OPT>(L_, idx_) }; |
| 111 | if (_linda != nullptr) { | 111 | if (_linda != nullptr) { |
| 112 | luaG_pushstring(L_, "Linda: "); | 112 | luaW_pushstring(L_, "Linda: "); |
| 113 | std::string_view const _lindaName{ _linda->getName() }; | 113 | std::string_view const _lindaName{ _linda->getName() }; |
| 114 | if (!_lindaName.empty()) { | 114 | if (!_lindaName.empty()) { |
| 115 | luaG_pushstring(L_, _lindaName); | 115 | luaW_pushstring(L_, _lindaName); |
| 116 | } else { | 116 | } else { |
| 117 | // obfuscate the pointer so that we can't read the value with our eyes out of a script | 117 | // obfuscate the pointer so that we can't read the value with our eyes out of a script |
| 118 | luaG_pushstring(L_, "%p", _linda->obfuscated()); | 118 | luaW_pushstring(L_, "%p", _linda->obfuscated()); |
| 119 | } | 119 | } |
| 120 | lua_concat(L_, 2); | 120 | lua_concat(L_, 2); |
| 121 | return 1; | 121 | return 1; |
| @@ -132,7 +132,7 @@ namespace { | |||
| 132 | StackIndex _key_i{ 2 }; // index of first slot, if timeout not there | 132 | StackIndex _key_i{ 2 }; // index of first slot, if timeout not there |
| 133 | 133 | ||
| 134 | std::chrono::time_point<std::chrono::steady_clock> _until{ std::chrono::time_point<std::chrono::steady_clock>::max() }; | 134 | std::chrono::time_point<std::chrono::steady_clock> _until{ std::chrono::time_point<std::chrono::steady_clock>::max() }; |
| 135 | if (luaG_type(L_, StackIndex{ 2 }) == LuaType::NUMBER) { // we don't want to use lua_isnumber() because of autocoercion | 135 | if (luaW_type(L_, StackIndex{ 2 }) == LuaType::NUMBER) { // we don't want to use lua_isnumber() because of autocoercion |
| 136 | lua_Duration const _duration{ lua_tonumber(L_, 2) }; | 136 | lua_Duration const _duration{ lua_tonumber(L_, 2) }; |
| 137 | if (_duration.count() >= 0.0) { | 137 | if (_duration.count() >= 0.0) { |
| 138 | _until = std::chrono::steady_clock::now() + std::chrono::duration_cast<std::chrono::steady_clock::duration>(_duration); | 138 | _until = std::chrono::steady_clock::now() + std::chrono::duration_cast<std::chrono::steady_clock::duration>(_duration); |
| @@ -279,7 +279,7 @@ namespace { | |||
| 279 | if (_nbPushed == 0) { | 279 | if (_nbPushed == 0) { |
| 280 | // not enough data in the linda slot to fulfill the request, return nil, "timeout" | 280 | // not enough data in the linda slot to fulfill the request, return nil, "timeout" |
| 281 | lua_pushnil(L_); | 281 | lua_pushnil(L_); |
| 282 | luaG_pushstring(L_, "timeout"); | 282 | luaW_pushstring(L_, "timeout"); |
| 283 | return 2; | 283 | return 2; |
| 284 | } | 284 | } |
| 285 | return _nbPushed; | 285 | return _nbPushed; |
| @@ -350,16 +350,16 @@ Linda* Linda::CreateTimerLinda(lua_State* const L_) | |||
| 350 | // Initialize 'timerLinda'; a common Linda object shared by all states | 350 | // Initialize 'timerLinda'; a common Linda object shared by all states |
| 351 | lua_pushcfunction(L_, LG_linda); // L_: lanes.linda | 351 | lua_pushcfunction(L_, LG_linda); // L_: lanes.linda |
| 352 | lua_createtable(L_, 0, 3); // L_: lanes.linda {} | 352 | lua_createtable(L_, 0, 3); // L_: lanes.linda {} |
| 353 | luaG_pushstring(L_, "lanes-timer"); // L_: lanes.linda {} "lanes-timer" | 353 | luaW_pushstring(L_, "lanes-timer"); // L_: lanes.linda {} "lanes-timer" |
| 354 | luaG_setfield(L_, StackIndex{ -2 }, std::string_view{ "name" }); // L_: lanes.linda { .name="lanes-timer" } | 354 | luaW_setfield(L_, StackIndex{ -2 }, std::string_view{ "name" }); // L_: lanes.linda { .name="lanes-timer" } |
| 355 | lua_pushinteger(L_, 0); // L_: lanes.linda { .name="lanes-timer" } 0 | 355 | lua_pushinteger(L_, 0); // L_: lanes.linda { .name="lanes-timer" } 0 |
| 356 | luaG_setfield(L_, StackIndex{ -2 }, std::string_view{ "group" }); // L_: lanes.linda { .name="lanes-timer" .group = 0 } | 356 | luaW_setfield(L_, StackIndex{ -2 }, std::string_view{ "group" }); // L_: lanes.linda { .name="lanes-timer" .group = 0 } |
| 357 | // note that wake_period is not set (will default to the value in the universe) | 357 | // note that wake_period is not set (will default to the value in the universe) |
| 358 | lua_call(L_, 1, 1); // L_: linda | 358 | lua_call(L_, 1, 1); // L_: linda |
| 359 | STACK_CHECK(L_, 1); | 359 | STACK_CHECK(L_, 1); |
| 360 | 360 | ||
| 361 | // Proxy userdata contents is only a 'DeepPrelude*' pointer | 361 | // Proxy userdata contents is only a 'DeepPrelude*' pointer |
| 362 | auto const _timerLinda{ *luaG_tofulluserdata<Linda*>(L_, kIdxTop) }; | 362 | auto const _timerLinda{ *luaW_tofulluserdata<Linda*>(L_, kIdxTop) }; |
| 363 | // increment refcount so that this linda remains alive as long as the universe exists. | 363 | // increment refcount so that this linda remains alive as long as the universe exists. |
| 364 | _timerLinda->refcount.fetch_add(1, std::memory_order_relaxed); | 364 | _timerLinda->refcount.fetch_add(1, std::memory_order_relaxed); |
| 365 | lua_pop(L_, 1); // L_: | 365 | lua_pop(L_, 1); // L_: |
| @@ -452,7 +452,7 @@ int Linda::ProtectedCall(lua_State* const L_, lua_CFunction const f_) | |||
| 452 | 452 | ||
| 453 | void Linda::pushCancelString(lua_State* L_) const | 453 | void Linda::pushCancelString(lua_State* L_) const |
| 454 | { | 454 | { |
| 455 | luaG_pushstring(L_, cancelStatus == Status::Cancelled ? "cancelled" : "active"); | 455 | luaW_pushstring(L_, cancelStatus == Status::Cancelled ? "cancelled" : "active"); |
| 456 | } | 456 | } |
| 457 | 457 | ||
| 458 | // ################################################################################################# | 458 | // ################################################################################################# |
| @@ -504,7 +504,7 @@ void Linda::setName(std::string_view const& name_) | |||
| 504 | LUAG_FUNC(linda_cancel) | 504 | LUAG_FUNC(linda_cancel) |
| 505 | { | 505 | { |
| 506 | Linda* const _linda{ ToLinda<false>(L_, StackIndex{ 1 }) }; | 506 | Linda* const _linda{ ToLinda<false>(L_, StackIndex{ 1 }) }; |
| 507 | std::string_view const _who{ luaG_optstring(L_, StackIndex{ 2 }, "both") }; | 507 | std::string_view const _who{ luaW_optstring(L_, StackIndex{ 2 }, "both") }; |
| 508 | // make sure we got 2 arguments: the linda and the cancellation mode | 508 | // make sure we got 2 arguments: the linda and the cancellation mode |
| 509 | luaL_argcheck(L_, lua_gettop(L_) <= 2, 2, "wrong number of arguments"); | 509 | luaL_argcheck(L_, lua_gettop(L_) <= 2, 2, "wrong number of arguments"); |
| 510 | 510 | ||
| @@ -592,13 +592,13 @@ static int linda_index_string(lua_State* L_) | |||
| 592 | Linda* const _linda{ ToLinda<false>(L_, kIdxSelf) }; | 592 | Linda* const _linda{ ToLinda<false>(L_, kIdxSelf) }; |
| 593 | LUA_ASSERT(L_, lua_gettop(L_) == 2); // L_: linda "key" | 593 | LUA_ASSERT(L_, lua_gettop(L_) == 2); // L_: linda "key" |
| 594 | 594 | ||
| 595 | std::string_view const _keystr{ luaG_tostring(L_, kIdxKey) }; | 595 | std::string_view const _keystr{ luaW_tostring(L_, kIdxKey) }; |
| 596 | lua_settop(L_, 2); // keep only our original arguments on the stack | 596 | lua_settop(L_, 2); // keep only our original arguments on the stack |
| 597 | 597 | ||
| 598 | // look in metatable first | 598 | // look in metatable first |
| 599 | lua_getmetatable(L_, kIdxSelf); // L_: linda "key" mt | 599 | lua_getmetatable(L_, kIdxSelf); // L_: linda "key" mt |
| 600 | lua_replace(L_, -3); // L_: mt "key" | 600 | lua_replace(L_, -3); // L_: mt "key" |
| 601 | if (luaG_rawget(L_, StackIndex{ -2 }) != LuaType::NIL) { // found something? // L_: mt value | 601 | if (luaW_rawget(L_, StackIndex{ -2 }) != LuaType::NIL) { // found something? // L_: mt value |
| 602 | return 1; // done | 602 | return 1; // done |
| 603 | } | 603 | } |
| 604 | 604 | ||
| @@ -618,12 +618,12 @@ static LUAG_FUNC(linda_index) | |||
| 618 | static constexpr StackIndex kIdxKey{ 2 }; | 618 | static constexpr StackIndex kIdxKey{ 2 }; |
| 619 | LUA_ASSERT(L_, lua_gettop(L_) == 2); | 619 | LUA_ASSERT(L_, lua_gettop(L_) == 2); |
| 620 | 620 | ||
| 621 | switch (luaG_type(L_, kIdxKey)) { | 621 | switch (luaW_type(L_, kIdxKey)) { |
| 622 | case LuaType::STRING: | 622 | case LuaType::STRING: |
| 623 | return linda_index_string(L_); // stack modification is undefined, returned value is at the top | 623 | return linda_index_string(L_); // stack modification is undefined, returned value is at the top |
| 624 | 624 | ||
| 625 | default: // unknown key | 625 | default: // unknown key |
| 626 | raise_luaL_error(L_, "Unsupported linda indexing key type %s", luaG_typename(L_, kIdxKey).data()); | 626 | raise_luaL_error(L_, "Unsupported linda indexing key type %s", luaW_typename(L_, kIdxKey).data()); |
| 627 | } | 627 | } |
| 628 | } | 628 | } |
| 629 | 629 | ||
| @@ -766,7 +766,7 @@ LUAG_FUNC(linda_limit) | |||
| 766 | int const _nargs{ lua_gettop(L_) }; | 766 | int const _nargs{ lua_gettop(L_) }; |
| 767 | luaL_argcheck(L_, _nargs == 2 || _nargs == 3, 2, "wrong number of arguments"); | 767 | luaL_argcheck(L_, _nargs == 2 || _nargs == 3, 2, "wrong number of arguments"); |
| 768 | // make sure we got a numeric limit, or "unlimited", (or nothing) | 768 | // make sure we got a numeric limit, or "unlimited", (or nothing) |
| 769 | bool const _unlimited{ luaG_tostring(L_, StackIndex{ 3 }) == "unlimited" }; | 769 | bool const _unlimited{ luaW_tostring(L_, StackIndex{ 3 }) == "unlimited" }; |
| 770 | LindaLimit const _val{ _unlimited ? std::numeric_limits<LindaLimit::type>::max() : static_cast<LindaLimit::type>(luaL_optinteger(L_, 3, 0)) }; | 770 | LindaLimit const _val{ _unlimited ? std::numeric_limits<LindaLimit::type>::max() : static_cast<LindaLimit::type>(luaL_optinteger(L_, 3, 0)) }; |
| 771 | if (_val < 0) { | 771 | if (_val < 0) { |
| 772 | raise_luaL_argerror(L_, StackIndex{ 3 }, "limit must be >= 0"); | 772 | raise_luaL_argerror(L_, StackIndex{ 3 }, "limit must be >= 0"); |
| @@ -777,23 +777,23 @@ LUAG_FUNC(linda_limit) | |||
| 777 | KeeperCallResult _pushed; | 777 | KeeperCallResult _pushed; |
| 778 | if (_linda->cancelStatus == Linda::Active) { | 778 | if (_linda->cancelStatus == Linda::Active) { |
| 779 | if (_unlimited) { | 779 | if (_unlimited) { |
| 780 | LUA_ASSERT(L_, lua_gettop(L_) == 3 && luaG_tostring(L_, StackIndex{ 3 }) == "unlimited"); | 780 | LUA_ASSERT(L_, lua_gettop(L_) == 3 && luaW_tostring(L_, StackIndex{ 3 }) == "unlimited"); |
| 781 | // inside the Keeper, unlimited is signified with a -1 limit (can't use nil because of nil kNilSentinel conversions!) | 781 | // inside the Keeper, unlimited is signified with a -1 limit (can't use nil because of nil kNilSentinel conversions!) |
| 782 | lua_pop(L_, 1); // L_: linda slot | 782 | lua_pop(L_, 1); // L_: linda slot |
| 783 | lua_pushinteger(L_, -1); // L_: linda slot nil | 783 | lua_pushinteger(L_, -1); // L_: linda slot nil |
| 784 | } | 784 | } |
| 785 | Keeper* const _keeper{ _linda->whichKeeper() }; | 785 | Keeper* const _keeper{ _linda->whichKeeper() }; |
| 786 | _pushed = keeper_call(_keeper->K, KEEPER_API(limit), L_, _linda, StackIndex{ 2 }); | 786 | _pushed = keeper_call(_keeper->K, KEEPER_API(limit), L_, _linda, StackIndex{ 2 }); |
| 787 | LUA_ASSERT(L_, _pushed.has_value() && (_pushed.value() == 2) && luaG_type(L_, kIdxTop) == LuaType::STRING); | 787 | LUA_ASSERT(L_, _pushed.has_value() && (_pushed.value() == 2) && luaW_type(L_, kIdxTop) == LuaType::STRING); |
| 788 | if (_nargs == 3) { // 3 args: setting the limit | 788 | if (_nargs == 3) { // 3 args: setting the limit |
| 789 | // changing the limit: no error, boolean value saying if we should wake blocked writer threads | 789 | // changing the limit: no error, boolean value saying if we should wake blocked writer threads |
| 790 | LUA_ASSERT(L_, luaG_type(L_, StackIndex{ -2 }) == LuaType::BOOLEAN); // L_: bool string | 790 | LUA_ASSERT(L_, luaW_type(L_, StackIndex{ -2 }) == LuaType::BOOLEAN); // L_: bool string |
| 791 | if (lua_toboolean(L_, -2)) { | 791 | if (lua_toboolean(L_, -2)) { |
| 792 | _linda->readHappened.notify_all(); // To be done from within the 'K' locking area | 792 | _linda->readHappened.notify_all(); // To be done from within the 'K' locking area |
| 793 | } | 793 | } |
| 794 | } else { // 2 args: reading the limit | 794 | } else { // 2 args: reading the limit |
| 795 | // reading the limit: a number >=0 or "unlimited" | 795 | // reading the limit: a number >=0 or "unlimited" |
| 796 | LUA_ASSERT(L_, luaG_type(L_, StackIndex{ -2 }) == LuaType::NUMBER || luaG_tostring(L_, StackIndex{ -2 }) == "unlimited"); | 796 | LUA_ASSERT(L_, luaW_type(L_, StackIndex{ -2 }) == LuaType::NUMBER || luaW_tostring(L_, StackIndex{ -2 }) == "unlimited"); |
| 797 | } | 797 | } |
| 798 | } else { // linda is cancelled | 798 | } else { // linda is cancelled |
| 799 | // do nothing and return nil,lanes.cancel_error | 799 | // do nothing and return nil,lanes.cancel_error |
| @@ -849,7 +849,7 @@ LUAG_FUNC(linda_restrict) | |||
| 849 | int const _nargs{ lua_gettop(L_) }; | 849 | int const _nargs{ lua_gettop(L_) }; |
| 850 | luaL_argcheck(L_, _nargs == 2 || _nargs == 3, 2, "wrong number of arguments"); | 850 | luaL_argcheck(L_, _nargs == 2 || _nargs == 3, 2, "wrong number of arguments"); |
| 851 | // make sure we got a known restrict mode, (or nothing) | 851 | // make sure we got a known restrict mode, (or nothing) |
| 852 | std::string_view const _mode{ luaG_tostring(L_, StackIndex{ 3 }) }; | 852 | std::string_view const _mode{ luaW_tostring(L_, StackIndex{ 3 }) }; |
| 853 | if (!_mode.empty() && (_mode != "none" && _mode != "set/get" && _mode != "send/receive")) { | 853 | if (!_mode.empty() && (_mode != "none" && _mode != "set/get" && _mode != "send/receive")) { |
| 854 | raise_luaL_argerror(L_, StackIndex{ 3 }, "unknown restrict mode"); | 854 | raise_luaL_argerror(L_, StackIndex{ 3 }, "unknown restrict mode"); |
| 855 | } | 855 | } |
| @@ -861,7 +861,7 @@ LUAG_FUNC(linda_restrict) | |||
| 861 | Keeper* const _keeper{ _linda->whichKeeper() }; | 861 | Keeper* const _keeper{ _linda->whichKeeper() }; |
| 862 | _pushed = keeper_call(_keeper->K, KEEPER_API(restrict), L_, _linda, StackIndex{ 2 }); | 862 | _pushed = keeper_call(_keeper->K, KEEPER_API(restrict), L_, _linda, StackIndex{ 2 }); |
| 863 | // we should get a single return value: the string describing the previous restrict mode | 863 | // we should get a single return value: the string describing the previous restrict mode |
| 864 | LUA_ASSERT(L_, _pushed.has_value() && (_pushed.value() == 1) && luaG_type(L_, kIdxTop) == LuaType::STRING); | 864 | LUA_ASSERT(L_, _pushed.has_value() && (_pushed.value() == 1) && luaW_type(L_, kIdxTop) == LuaType::STRING); |
| 865 | } else { // linda is cancelled | 865 | } else { // linda is cancelled |
| 866 | // do nothing and return nil,lanes.cancel_error | 866 | // do nothing and return nil,lanes.cancel_error |
| 867 | lua_pushnil(L_); | 867 | lua_pushnil(L_); |
| @@ -981,7 +981,7 @@ LUAG_FUNC(linda_send) | |||
| 981 | } else { | 981 | } else { |
| 982 | // not enough room in the Linda slot to fulfill the request, return nil, "timeout" | 982 | // not enough room in the Linda slot to fulfill the request, return nil, "timeout" |
| 983 | lua_pushnil(L_); | 983 | lua_pushnil(L_); |
| 984 | luaG_pushstring(L_, "timeout"); | 984 | luaW_pushstring(L_, "timeout"); |
| 985 | return 2; | 985 | return 2; |
| 986 | } | 986 | } |
| 987 | } | 987 | } |
| @@ -1016,7 +1016,7 @@ LUAG_FUNC(linda_set) | |||
| 1016 | if (kRestrictedChannel.equals(L_, kIdxTop)) { | 1016 | if (kRestrictedChannel.equals(L_, kIdxTop)) { |
| 1017 | raise_luaL_error(L_, "Key is restricted"); | 1017 | raise_luaL_error(L_, "Key is restricted"); |
| 1018 | } | 1018 | } |
| 1019 | LUA_ASSERT(L_, _pushed.value() == 2 && luaG_type(L_, kIdxTop) == LuaType::STRING && luaG_type(L_, StackIndex{ -2 }) == LuaType::BOOLEAN); | 1019 | LUA_ASSERT(L_, _pushed.value() == 2 && luaW_type(L_, kIdxTop) == LuaType::STRING && luaW_type(L_, StackIndex{ -2 }) == LuaType::BOOLEAN); |
| 1020 | 1020 | ||
| 1021 | if (_has_data) { | 1021 | if (_has_data) { |
| 1022 | // we put some data in the slot, tell readers that they should wake | 1022 | // we put some data in the slot, tell readers that they should wake |
| @@ -1078,7 +1078,7 @@ LUAG_FUNC(linda_towatch) | |||
| 1078 | LUAG_FUNC(linda_wake) | 1078 | LUAG_FUNC(linda_wake) |
| 1079 | { | 1079 | { |
| 1080 | Linda* const _linda{ ToLinda<false>(L_, StackIndex{ 1 }) }; | 1080 | Linda* const _linda{ ToLinda<false>(L_, StackIndex{ 1 }) }; |
| 1081 | std::string_view const _who{ luaG_optstring(L_, StackIndex{ 2 }, "both") }; | 1081 | std::string_view const _who{ luaW_optstring(L_, StackIndex{ 2 }, "both") }; |
| 1082 | // make sure we got 2 arguments: the linda and the wake targets | 1082 | // make sure we got 2 arguments: the linda and the wake targets |
| 1083 | luaL_argcheck(L_, lua_gettop(L_) <= 2, 2, "wrong number of arguments"); | 1083 | luaL_argcheck(L_, lua_gettop(L_) <= 2, 2, "wrong number of arguments"); |
| 1084 | 1084 | ||
| @@ -1154,8 +1154,8 @@ LUAG_FUNC(linda) | |||
| 1154 | if (lua_isnil(L_, kIdxTop)) { | 1154 | if (lua_isnil(L_, kIdxTop)) { |
| 1155 | lua_pop(L_, 1); | 1155 | lua_pop(L_, 1); |
| 1156 | lua_pushnumber(L_, _U->lindaWakePeriod.count()); | 1156 | lua_pushnumber(L_, _U->lindaWakePeriod.count()); |
| 1157 | } else if (luaG_type(L_, kIdxTop) == LuaType::STRING) { | 1157 | } else if (luaW_type(L_, kIdxTop) == LuaType::STRING) { |
| 1158 | if (luaG_tostring(L_, kIdxTop) != "never") { | 1158 | if (luaW_tostring(L_, kIdxTop) != "never") { |
| 1159 | luaL_argerror(L_, 1, "invalid wake_period"); | 1159 | luaL_argerror(L_, 1, "invalid wake_period"); |
| 1160 | } else { | 1160 | } else { |
| 1161 | lua_pop(L_, 1); | 1161 | lua_pop(L_, 1); |
| @@ -1177,7 +1177,7 @@ LUAG_FUNC(linda) | |||
| 1177 | 1177 | ||
| 1178 | #if LUA_VERSION_NUM >= 504 // to-be-closed support starts with Lua 5.4 | 1178 | #if LUA_VERSION_NUM >= 504 // to-be-closed support starts with Lua 5.4 |
| 1179 | lua_getfield(L_, 1, "close_handler"); // L_: {} wake_period group close_handler | 1179 | lua_getfield(L_, 1, "close_handler"); // L_: {} wake_period group close_handler |
| 1180 | LuaType const _handlerType{ luaG_type(L_, kIdxTop) }; | 1180 | LuaType const _handlerType{ luaW_type(L_, kIdxTop) }; |
| 1181 | if (_handlerType == LuaType::NIL) { | 1181 | if (_handlerType == LuaType::NIL) { |
| 1182 | lua_pop(L_, 1); // L_: {} wake_period group | 1182 | lua_pop(L_, 1); // L_: {} wake_period group |
| 1183 | } else if (_handlerType == LuaType::USERDATA || _handlerType == LuaType::TABLE) { | 1183 | } else if (_handlerType == LuaType::USERDATA || _handlerType == LuaType::TABLE) { |
| @@ -1188,7 +1188,7 @@ LUAG_FUNC(linda) | |||
| 1188 | } | 1188 | } |
| 1189 | #endif // LUA_VERSION_NUM >= 504 | 1189 | #endif // LUA_VERSION_NUM >= 504 |
| 1190 | 1190 | ||
| 1191 | auto const _nameType{ luaG_getfield(L_, StackIndex{ 1 }, "name") }; // L_: {} wake_period group [close_handler] name | 1191 | auto const _nameType{ luaW_getfield(L_, StackIndex{ 1 }, "name") }; // L_: {} wake_period group [close_handler] name |
| 1192 | luaL_argcheck(L_, _nameType == LuaType::NIL || _nameType == LuaType::STRING, 1, "name is not a string"); | 1192 | luaL_argcheck(L_, _nameType == LuaType::NIL || _nameType == LuaType::STRING, 1, "name is not a string"); |
| 1193 | lua_replace(L_, 1); // L_: name wake_period group [close_handler] | 1193 | lua_replace(L_, 1); // L_: name wake_period group [close_handler] |
| 1194 | } | 1194 | } |
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 | |||
| 47 | lua_newtable(L_); // L_: mt | 47 | lua_newtable(L_); // L_: mt |
| 48 | 48 | ||
| 49 | // protect metatable from external access | 49 | // protect metatable from external access |
| 50 | luaG_pushstring(L_, kLindaMetatableName); // L_: mt "<name>" | 50 | luaW_pushstring(L_, kLindaMetatableName); // L_: mt "<name>" |
| 51 | lua_setfield(L_, -2, "__metatable"); // L_: mt | 51 | lua_setfield(L_, -2, "__metatable"); // L_: mt |
| 52 | 52 | ||
| 53 | // the linda functions | 53 | // the linda functions |
| 54 | luaG_registerlibfuncs(L_, mLindaMT); | 54 | luaW_registerlibfuncs(L_, mLindaMT); |
| 55 | 55 | ||
| 56 | kNilSentinel.pushKey(L_); // L_: mt kNilSentinel | 56 | kNilSentinel.pushKey(L_); // L_: mt kNilSentinel |
| 57 | lua_setfield(L_, -2, "null"); // L_: mt | 57 | lua_setfield(L_, -2, "null"); // L_: mt |
| 58 | 58 | ||
| 59 | // if the metatable contains __index, leave it as is | 59 | // if the metatable contains __index, leave it as is |
| 60 | if (luaG_getfield(L_, kIdxTop, kIndex) != LuaType::NIL) { // L_: mt __index | 60 | if (luaW_getfield(L_, kIdxTop, kIndex) != LuaType::NIL) { // L_: mt __index |
| 61 | lua_pop(L_, 1); // L_: mt __index | 61 | lua_pop(L_, 1); // L_: mt __index |
| 62 | } else { | 62 | } else { |
| 63 | // metatable is its own index | 63 | // metatable is its own index |
| 64 | lua_pushvalue(L_, kIdxTop); // L_: mt mt | 64 | lua_pushvalue(L_, kIdxTop); // L_: mt mt |
| 65 | luaG_setfield(L_, StackIndex{ -2 }, kIndex); // L_: mt | 65 | luaW_setfield(L_, StackIndex{ -2 }, kIndex); // L_: mt |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | STACK_CHECK(L_, 1); | 68 | STACK_CHECK(L_, 1); |
| @@ -110,7 +110,7 @@ DeepPrelude* LindaFactory::newDeepObjectInternal(lua_State* const L_) const | |||
| 110 | { | 110 | { |
| 111 | STACK_CHECK_START_REL(L_, 0); | 111 | STACK_CHECK_START_REL(L_, 0); |
| 112 | // 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 | 112 | // 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 |
| 113 | std::string_view _linda_name{ luaG_tostring(L_, StackIndex{ 1 }) }; | 113 | std::string_view _linda_name{ luaW_tostring(L_, StackIndex{ 1 }) }; |
| 114 | auto const _wake_period{ static_cast<lua_Duration>(lua_tonumber(L_, 2)) }; | 114 | auto const _wake_period{ static_cast<lua_Duration>(lua_tonumber(L_, 2)) }; |
| 115 | LindaGroup const _linda_group{ static_cast<int>(lua_tointeger(L_, 3)) }; | 115 | LindaGroup const _linda_group{ static_cast<int>(lua_tointeger(L_, 3)) }; |
| 116 | 116 | ||
| @@ -119,12 +119,12 @@ DeepPrelude* LindaFactory::newDeepObjectInternal(lua_State* const L_) const | |||
| 119 | lua_Debug _ar; | 119 | lua_Debug _ar; |
| 120 | if (lua_getstack(L_, 1, &_ar) == 1) { // 1 because we want the name of the function that called lanes.linda (where we currently are) | 120 | if (lua_getstack(L_, 1, &_ar) == 1) { // 1 because we want the name of the function that called lanes.linda (where we currently are) |
| 121 | lua_getinfo(L_, "Sln", &_ar); | 121 | lua_getinfo(L_, "Sln", &_ar); |
| 122 | _linda_name = luaG_pushstring(L_, "%s:%d", _ar.short_src, _ar.currentline); | 122 | _linda_name = luaW_pushstring(L_, "%s:%d", _ar.short_src, _ar.currentline); |
| 123 | } else { | 123 | } else { |
| 124 | _linda_name = luaG_pushstring(L_, "<unresolved>"); | 124 | _linda_name = luaW_pushstring(L_, "<unresolved>"); |
| 125 | } | 125 | } |
| 126 | // since the name is not empty, it is at slot 1, and we can replace "auto" with the result, just in case | 126 | // since the name is not empty, it is at slot 1, and we can replace "auto" with the result, just in case |
| 127 | LUA_ASSERT(L_, luaG_tostring(L_, StackIndex{ 1 }) == "auto"); | 127 | LUA_ASSERT(L_, luaW_tostring(L_, StackIndex{ 1 }) == "auto"); |
| 128 | lua_replace(L_, 1); | 128 | lua_replace(L_, 1); |
| 129 | } | 129 | } |
| 130 | 130 | ||
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_ | |||
| 52 | static constexpr auto _pushNameOnFQN = [](lua_State* const L_) { | 52 | static constexpr auto _pushNameOnFQN = [](lua_State* const L_) { |
| 53 | STACK_CHECK_START_REL(L_, 0); | 53 | STACK_CHECK_START_REL(L_, 0); |
| 54 | lua_pushvalue(L_, -2); // L_: o "r" {c} {fqn} ... k v k | 54 | lua_pushvalue(L_, -2); // L_: o "r" {c} {fqn} ... k v k |
| 55 | auto const _keyType{ luaG_type(L_, kIdxTop) }; | 55 | auto const _keyType{ luaW_type(L_, kIdxTop) }; |
| 56 | if (_keyType != LuaType::STRING) { | 56 | if (_keyType != LuaType::STRING) { |
| 57 | lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... k v | 57 | lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... k v |
| 58 | luaG_pushstring(L_, "<%s>", luaG_typename(L_, _keyType).data()); // L_: o "r" {c} {fqn} ... k v "<type of k>" | 58 | luaW_pushstring(L_, "<%s>", luaW_typename(L_, _keyType).data()); // L_: o "r" {c} {fqn} ... k v "<type of k>" |
| 59 | } else { | 59 | } else { |
| 60 | // decorate the key string with something that tells us the type of the value | 60 | // decorate the key string with something that tells us the type of the value |
| 61 | switch (luaG_type(L_, StackIndex{ -2 })) { | 61 | switch (luaW_type(L_, StackIndex{ -2 })) { |
| 62 | default: | 62 | default: |
| 63 | LUA_ASSERT(L_, false); // there is something wrong if we end up here | 63 | LUA_ASSERT(L_, false); // there is something wrong if we end up here |
| 64 | luaG_pushstring(L_, "??"); // L_: o "r" {c} {fqn} ... k v "k" "??" | 64 | luaW_pushstring(L_, "??"); // L_: o "r" {c} {fqn} ... k v "k" "??" |
| 65 | break; | 65 | break; |
| 66 | case LuaType::FUNCTION: | 66 | case LuaType::FUNCTION: |
| 67 | luaG_pushstring(L_, "()"); // L_: o "r" {c} {fqn} ... k v "k" "()" | 67 | luaW_pushstring(L_, "()"); // L_: o "r" {c} {fqn} ... k v "k" "()" |
| 68 | break; | 68 | break; |
| 69 | case LuaType::TABLE: | 69 | case LuaType::TABLE: |
| 70 | luaG_pushstring(L_, "[]"); // L_: o "r" {c} {fqn} ... k v "k" "[]" | 70 | luaW_pushstring(L_, "[]"); // L_: o "r" {c} {fqn} ... k v "k" "[]" |
| 71 | break; | 71 | break; |
| 72 | case LuaType::USERDATA: | 72 | case LuaType::USERDATA: |
| 73 | luaG_pushstring(L_, "<>"); // L_: o "r" {c} {fqn} ... k v "k" "<>" | 73 | luaW_pushstring(L_, "<>"); // L_: o "r" {c} {fqn} ... k v "k" "<>" |
| 74 | break; | 74 | break; |
| 75 | } | 75 | } |
| 76 | lua_concat(L_, 2); // L_: o "r" {c} {fqn} ... k v "k??" | 76 | 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_ | |||
| 92 | static constexpr auto _recurseThenPop = [](lua_State* const L_, FqnLength const shortest_) -> FqnLength { | 92 | static constexpr auto _recurseThenPop = [](lua_State* const L_, FqnLength const shortest_) -> FqnLength { |
| 93 | STACK_CHECK_START_REL(L_, 0); // L_: o "r" {c} {fqn} ... <> | 93 | STACK_CHECK_START_REL(L_, 0); // L_: o "r" {c} {fqn} ... <> |
| 94 | FqnLength r_{ shortest_ }; | 94 | FqnLength r_{ shortest_ }; |
| 95 | auto const _type{ luaG_type(L_, kIdxTop) }; | 95 | auto const _type{ luaW_type(L_, kIdxTop) }; |
| 96 | if (_type == LuaType::TABLE || _type == LuaType::USERDATA || _type == LuaType::FUNCTION) { | 96 | if (_type == LuaType::TABLE || _type == LuaType::USERDATA || _type == LuaType::FUNCTION) { |
| 97 | r_ = DiscoverObjectNameRecur(L_, shortest_); | 97 | r_ = DiscoverObjectNameRecur(L_, shortest_); |
| 98 | STACK_CHECK(L_, 0); | 98 | STACK_CHECK(L_, 0); |
| @@ -113,7 +113,7 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_ | |||
| 113 | STACK_CHECK_START_REL(L_, 0); // L_: o "r" {c} {fqn} ... k v | 113 | STACK_CHECK_START_REL(L_, 0); // L_: o "r" {c} {fqn} ... k v |
| 114 | 114 | ||
| 115 | // filter out uninteresting values | 115 | // filter out uninteresting values |
| 116 | auto const _valType{ luaG_type(L_, kIdxTop) }; | 116 | auto const _valType{ luaW_type(L_, kIdxTop) }; |
| 117 | if (_valType == LuaType::NIL || _valType == LuaType::BOOLEAN || _valType == LuaType::LIGHTUSERDATA || _valType == LuaType::NUMBER || _valType == LuaType::STRING) { | 117 | if (_valType == LuaType::NIL || _valType == LuaType::BOOLEAN || _valType == LuaType::LIGHTUSERDATA || _valType == LuaType::NUMBER || _valType == LuaType::STRING) { |
| 118 | lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... k | 118 | lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... k |
| 119 | return _r; | 119 | return _r; |
| @@ -177,7 +177,7 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_ | |||
| 177 | 177 | ||
| 178 | UserValueIndex _uvi{ 0 }; | 178 | UserValueIndex _uvi{ 0 }; |
| 179 | while (lua_getiuservalue(L_, kIdxTop, ++_uvi) != LUA_TNONE) { // L_: o "r" {c} {fqn} ... U uv | 179 | while (lua_getiuservalue(L_, kIdxTop, ++_uvi) != LUA_TNONE) { // L_: o "r" {c} {fqn} ... U uv |
| 180 | luaG_pushstring(L_, "<uv:%d>", _uvi); // L_: o "r" {c} {fqn} ... U uv name | 180 | luaW_pushstring(L_, "<uv:%d>", _uvi); // L_: o "r" {c} {fqn} ... U uv name |
| 181 | lua_insert(L_, -2); // L_: o "r" {c} {fqn} ... U name uv | 181 | lua_insert(L_, -2); // L_: o "r" {c} {fqn} ... U name uv |
| 182 | r_ = _processKeyValue(L_, r_); // L_: o "r" {c} {fqn} ... U name | 182 | r_ = _processKeyValue(L_, r_); // L_: o "r" {c} {fqn} ... U name |
| 183 | lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... U | 183 | lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... U |
| @@ -200,7 +200,7 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_ | |||
| 200 | _upname = "<C>"; | 200 | _upname = "<C>"; |
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | luaG_pushstring(L_, "upvalue:%s", _upname); // L_: o "r" {c} {fqn} ... F up name | 203 | luaW_pushstring(L_, "upvalue:%s", _upname); // L_: o "r" {c} {fqn} ... F up name |
| 204 | lua_insert(L_, -2); // L_: o "r" {c} {fqn} ... F name up | 204 | lua_insert(L_, -2); // L_: o "r" {c} {fqn} ... F name up |
| 205 | r_ = _processKeyValue(L_, r_); // L_: o "r" {c} {fqn} ... F name | 205 | r_ = _processKeyValue(L_, r_); // L_: o "r" {c} {fqn} ... F name |
| 206 | lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... F | 206 | lua_pop(L_, 1); // L_: o "r" {c} {fqn} ... F |
| @@ -213,7 +213,7 @@ FqnLength DiscoverObjectNameRecur(lua_State* const L_, FqnLength const shortest_ | |||
| 213 | STACK_GROW(L_, 2); | 213 | STACK_GROW(L_, 2); |
| 214 | STACK_CHECK_START_REL(L_, 0); | 214 | STACK_CHECK_START_REL(L_, 0); |
| 215 | // stack top contains the location to search in (table, function, userdata) | 215 | // stack top contains the location to search in (table, function, userdata) |
| 216 | [[maybe_unused]] auto const _typeWhere{ luaG_type(L_, kIdxTop) }; | 216 | [[maybe_unused]] auto const _typeWhere{ luaW_type(L_, kIdxTop) }; |
| 217 | LUA_ASSERT(L_, _typeWhere == LuaType::TABLE || _typeWhere == LuaType::USERDATA || _typeWhere == LuaType::FUNCTION); | 217 | LUA_ASSERT(L_, _typeWhere == LuaType::TABLE || _typeWhere == LuaType::USERDATA || _typeWhere == LuaType::FUNCTION); |
| 218 | lua_pushvalue(L_, kIdxTop); // L_: o "r" {c} {fqn} ... <> <> | 218 | lua_pushvalue(L_, kIdxTop); // L_: o "r" {c} {fqn} ... <> <> |
| 219 | lua_rawget(L_, kCache); // L_: o "r" {c} {fqn} ... <> nil/N | 219 | lua_rawget(L_, kCache); // L_: o "r" {c} {fqn} ... <> nil/N |
| @@ -263,12 +263,12 @@ LUAG_FUNC(nameof) | |||
| 263 | 263 | ||
| 264 | // nil, boolean, light userdata, number and string aren't identifiable | 264 | // nil, boolean, light userdata, number and string aren't identifiable |
| 265 | static constexpr auto _isIdentifiable = [](lua_State* const L_) { | 265 | static constexpr auto _isIdentifiable = [](lua_State* const L_) { |
| 266 | auto const _valType{ luaG_type(L_, kIdxTop) }; | 266 | auto const _valType{ luaW_type(L_, kIdxTop) }; |
| 267 | return _valType == LuaType::TABLE || _valType == LuaType::FUNCTION || _valType == LuaType::USERDATA || _valType == LuaType::THREAD; | 267 | return _valType == LuaType::TABLE || _valType == LuaType::FUNCTION || _valType == LuaType::USERDATA || _valType == LuaType::THREAD; |
| 268 | }; | 268 | }; |
| 269 | 269 | ||
| 270 | if (!_isIdentifiable(L_)) { | 270 | if (!_isIdentifiable(L_)) { |
| 271 | luaG_pushstring(L_, luaG_typename(L_, kIdxTop)); // L_: o "type" | 271 | luaW_pushstring(L_, luaW_typename(L_, kIdxTop)); // L_: o "type" |
| 272 | lua_insert(L_, -2); // L_: "type" o | 272 | lua_insert(L_, -2); // L_: "type" o |
| 273 | return 2; | 273 | return 2; |
| 274 | } | 274 | } |
| @@ -282,15 +282,15 @@ LUAG_FUNC(nameof) | |||
| 282 | // push a table whose contents are strings that, when concatenated, produce unique name | 282 | // push a table whose contents are strings that, when concatenated, produce unique name |
| 283 | lua_newtable(L_); // L_: o nil {c} {fqn} | 283 | lua_newtable(L_); // L_: o nil {c} {fqn} |
| 284 | // {fqn}[1] = "_G" | 284 | // {fqn}[1] = "_G" |
| 285 | luaG_pushstring(L_, LUA_GNAME); // L_: o nil {c} {fqn} "_G" | 285 | luaW_pushstring(L_, LUA_GNAME); // L_: o nil {c} {fqn} "_G" |
| 286 | lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} | 286 | lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} |
| 287 | // this is where we start the search | 287 | // this is where we start the search |
| 288 | luaG_pushglobaltable(L_); // L_: o nil {c} {fqn} _G | 288 | luaW_pushglobaltable(L_); // L_: o nil {c} {fqn} _G |
| 289 | auto const _foundInG{ DiscoverObjectNameRecur(L_, FqnLength{ std::numeric_limits<FqnLength::type>::max() }) }; | 289 | auto const _foundInG{ DiscoverObjectNameRecur(L_, FqnLength{ std::numeric_limits<FqnLength::type>::max() }) }; |
| 290 | if (lua_isnil(L_, 2)) { // try again with registry, just in case... | 290 | if (lua_isnil(L_, 2)) { // try again with registry, just in case... |
| 291 | LUA_ASSERT(L_, _foundInG == std::numeric_limits<FqnLength::type>::max()); | 291 | LUA_ASSERT(L_, _foundInG == std::numeric_limits<FqnLength::type>::max()); |
| 292 | lua_pop(L_, 1); // L_: o nil {c} {fqn} | 292 | lua_pop(L_, 1); // L_: o nil {c} {fqn} |
| 293 | luaG_pushstring(L_, "_R"); // L_: o nil {c} {fqn} "_R" | 293 | luaW_pushstring(L_, "_R"); // L_: o nil {c} {fqn} "_R" |
| 294 | lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} | 294 | lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} |
| 295 | lua_pushvalue(L_, kIdxRegistry); // L_: o nil {c} {fqn} _R | 295 | lua_pushvalue(L_, kIdxRegistry); // L_: o nil {c} {fqn} _R |
| 296 | [[maybe_unused]] auto const _foundInR{ DiscoverObjectNameRecur(L_, FqnLength{ std::numeric_limits<FqnLength::type>::max() }) }; | 296 | [[maybe_unused]] auto const _foundInR{ DiscoverObjectNameRecur(L_, FqnLength{ std::numeric_limits<FqnLength::type>::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 { | |||
| 166 | }; | 166 | }; |
| 167 | 167 | ||
| 168 | if (_L == nullptr) { | 168 | if (_L == nullptr) { |
| 169 | raise_luaL_error(from_, "luaG_newstate() failed while creating state; out of memory"); | 169 | raise_luaL_error(from_, "luaW_newstate() failed while creating state; out of memory"); |
| 170 | } | 170 | } |
| 171 | return _L; | 171 | return _L; |
| 172 | } | 172 | } |
| @@ -202,11 +202,11 @@ namespace state { | |||
| 202 | 202 | ||
| 203 | // neither libs (not even 'base') nor special init func: we are done | 203 | // neither libs (not even 'base') nor special init func: we are done |
| 204 | if (!libs_.has_value() && std::holds_alternative<std::nullptr_t>(U_->onStateCreateFunc)) { | 204 | if (!libs_.has_value() && std::holds_alternative<std::nullptr_t>(U_->onStateCreateFunc)) { |
| 205 | DEBUGSPEW_CODE(DebugSpew(U_) << "luaG_newstate(nullptr)" << std::endl); | 205 | DEBUGSPEW_CODE(DebugSpew(U_) << "luaW_newstate(nullptr)" << std::endl); |
| 206 | return _L; | 206 | return _L; |
| 207 | } | 207 | } |
| 208 | 208 | ||
| 209 | DEBUGSPEW_CODE(DebugSpew(U_) << "luaG_newstate()" << std::endl); | 209 | DEBUGSPEW_CODE(DebugSpew(U_) << "luaW_newstate()" << std::endl); |
| 210 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U_ }); | 210 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U_ }); |
| 211 | 211 | ||
| 212 | // copy settings (for example because it may contain a Lua on_state_create function) | 212 | // copy settings (for example because it may contain a Lua on_state_create function) |
| @@ -239,7 +239,7 @@ namespace state { | |||
| 239 | lua_pop(_L, 1); | 239 | lua_pop(_L, 1); |
| 240 | } else { | 240 | } else { |
| 241 | lua_pushcfunction(_L, luaopen_base); | 241 | lua_pushcfunction(_L, luaopen_base); |
| 242 | luaG_pushstring(_L, ""); | 242 | luaW_pushstring(_L, ""); |
| 243 | lua_call(_L, 1, 0); | 243 | lua_call(_L, 1, 0); |
| 244 | } | 244 | } |
| 245 | } | 245 | } |
| @@ -274,7 +274,7 @@ namespace state { | |||
| 274 | 274 | ||
| 275 | STACK_CHECK(_L, 0); | 275 | STACK_CHECK(_L, 0); |
| 276 | // after all this, register everything we find in our name<->function database | 276 | // after all this, register everything we find in our name<->function database |
| 277 | luaG_pushglobaltable(_L); // L: _G | 277 | luaW_pushglobaltable(_L); // L: _G |
| 278 | tools::PopulateFuncLookupTable(_L, kIdxTop, {}); | 278 | tools::PopulateFuncLookupTable(_L, kIdxTop, {}); |
| 279 | lua_pop(_L, 1); // L: | 279 | lua_pop(_L, 1); // L: |
| 280 | STACK_CHECK(_L, 0); | 280 | STACK_CHECK(_L, 0); |
| @@ -286,19 +286,19 @@ namespace state { | |||
| 286 | kLookupRegKey.pushValue(_L); // L: {} | 286 | kLookupRegKey.pushValue(_L); // L: {} |
| 287 | lua_pushnil(_L); // L: {} nil | 287 | lua_pushnil(_L); // L: {} nil |
| 288 | while (lua_next(_L, -2)) { // L: {} k v | 288 | while (lua_next(_L, -2)) { // L: {} k v |
| 289 | luaG_pushstring(_L, "["); // L: {} k v "[" | 289 | luaW_pushstring(_L, "["); // L: {} k v "[" |
| 290 | 290 | ||
| 291 | lua_getglobal(_L, "tostring"); // L: {} k v "[" tostring | 291 | lua_getglobal(_L, "tostring"); // L: {} k v "[" tostring |
| 292 | lua_pushvalue(_L, -4); // L: {} k v "[" tostring k | 292 | lua_pushvalue(_L, -4); // L: {} k v "[" tostring k |
| 293 | lua_call(_L, 1, 1); // L: {} k v "[" 'k' | 293 | lua_call(_L, 1, 1); // L: {} k v "[" 'k' |
| 294 | 294 | ||
| 295 | luaG_pushstring(_L, "] = "); // L: {} k v "[" 'k' "] = " | 295 | luaW_pushstring(_L, "] = "); // L: {} k v "[" 'k' "] = " |
| 296 | 296 | ||
| 297 | lua_getglobal(_L, "tostring"); // L: {} k v "[" 'k' "] = " tostring | 297 | lua_getglobal(_L, "tostring"); // L: {} k v "[" 'k' "] = " tostring |
| 298 | lua_pushvalue(_L, -5); // L: {} k v "[" 'k' "] = " tostring v | 298 | lua_pushvalue(_L, -5); // L: {} k v "[" 'k' "] = " tostring v |
| 299 | lua_call(_L, 1, 1); // L: {} k v "[" 'k' "] = " 'v' | 299 | lua_call(_L, 1, 1); // L: {} k v "[" 'k' "] = " 'v' |
| 300 | lua_concat(_L, 4); // L: {} k v "[k] = v" | 300 | lua_concat(_L, 4); // L: {} k v "[k] = v" |
| 301 | DEBUGSPEW_CODE(DebugSpew(U_) << luaG_tostring(_L, kIdxTop) << std::endl); | 301 | DEBUGSPEW_CODE(DebugSpew(U_) << luaW_tostring(_L, kIdxTop) << std::endl); |
| 302 | lua_pop(_L, 2); // L: {} k | 302 | lua_pop(_L, 2); // L: {} k |
| 303 | } // lua_next() // L: {} | 303 | } // lua_next() // L: {} |
| 304 | lua_pop(_L, 1); // L: | 304 | lua_pop(_L, 1); // L: |
| @@ -317,7 +317,7 @@ namespace state { | |||
| 317 | lua_newtable(L_); // L_: out | 317 | lua_newtable(L_); // L_: out |
| 318 | for (luaL_Reg const& _entry : local::sLibs) { | 318 | for (luaL_Reg const& _entry : local::sLibs) { |
| 319 | lua_pushboolean(L_, 1); // L_: out true | 319 | lua_pushboolean(L_, 1); // L_: out true |
| 320 | luaG_setfield(L_, StackIndex{ -2 }, std::string_view{ _entry.name }); // out[name] = true // L_: out | 320 | luaW_setfield(L_, StackIndex{ -2 }, std::string_view{ _entry.name }); // out[name] = true // L_: out |
| 321 | } | 321 | } |
| 322 | STACK_CHECK(L_, 1); | 322 | STACK_CHECK(L_, 1); |
| 323 | return 1; | 323 | 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 | |||
| 109 | std::string_view const _funcname{ StripFuncName(where_) }; | 109 | std::string_view const _funcname{ StripFuncName(where_) }; |
| 110 | 110 | ||
| 111 | #if defined(PLATFORM_XBOX) | 111 | #if defined(PLATFORM_XBOX) |
| 112 | luaG_pushstring(L_, "%s() failed with code %d", _funcname.data(), _rc); | 112 | luaW_pushstring(L_, "%s() failed with code %d", _funcname.data(), _rc); |
| 113 | #else // PLATFORM_XBOX | 113 | #else // PLATFORM_XBOX |
| 114 | char _buf[256]; | 114 | char _buf[256]; |
| 115 | FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, _rc, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), _buf, 256, nullptr); | 115 | FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, _rc, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), _buf, 256, nullptr); |
| 116 | luaG_pushstring(L_, "%s() failed with code %d '%s'", _funcname.data(), _rc, _buf); | 116 | luaW_pushstring(L_, "%s() failed with code %d '%s'", _funcname.data(), _rc, _buf); |
| 117 | #endif // PLATFORM_XBOX | 117 | #endif // PLATFORM_XBOX |
| 118 | raise_lua_error(L_); | 118 | raise_lua_error(L_); |
| 119 | } | 119 | } |
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 | |||
| 63 | * +-----------------+-------------------+------------+----------+ | 63 | * +-----------------+-------------------+------------+----------+ |
| 64 | * | lua_tocfunction | nullptr | | nullptr | | 64 | * | lua_tocfunction | nullptr | | nullptr | |
| 65 | * +-----------------+-------------------+------------+----------+ | 65 | * +-----------------+-------------------+------------+----------+ |
| 66 | * | luaG_dump | kWriterReturnCode | 1 | 1 | | 66 | * | luaW_dump | kWriterReturnCode | 1 | 1 | |
| 67 | * +-----------------+-------------------+------------+----------+ | 67 | * +-----------------+-------------------+------------+----------+ |
| 68 | */ | 68 | */ |
| 69 | 69 | ||
| 70 | [[nodiscard]] | 70 | [[nodiscard]] |
| 71 | FuncSubType luaG_getfuncsubtype(lua_State* const L_, StackIndex const i_) | 71 | FuncSubType luaW_getfuncsubtype(lua_State* const L_, StackIndex const i_) |
| 72 | { | 72 | { |
| 73 | if (lua_tocfunction(L_, i_)) { // nullptr for LuaJIT-fast && bytecode functions | 73 | if (lua_tocfunction(L_, i_)) { // nullptr for LuaJIT-fast && bytecode functions |
| 74 | return FuncSubType::Native; | 74 | return FuncSubType::Native; |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | // luaG_dump expects the function at the top of the stack | 77 | // luaW_dump expects the function at the top of the stack |
| 78 | int const _popCount{ (luaG_absindex(L_, i_) == lua_gettop(L_)) ? 0 : (lua_pushvalue(L_, i_), 1) }; | 78 | int const _popCount{ (luaW_absindex(L_, i_) == lua_gettop(L_)) ? 0 : (lua_pushvalue(L_, i_), 1) }; |
| 79 | // here we either have a Lua bytecode or a LuaJIT-compiled function | 79 | // here we either have a Lua bytecode or a LuaJIT-compiled function |
| 80 | int const _dumpres{ luaG_dump(L_, dummy_writer, nullptr, 0) }; | 80 | int const _dumpres{ luaW_dump(L_, dummy_writer, nullptr, 0) }; |
| 81 | if (_popCount > 0) { | 81 | if (_popCount > 0) { |
| 82 | lua_pop(L_, _popCount); | 82 | lua_pop(L_, _popCount); |
| 83 | } | 83 | } |
| 84 | if (_dumpres == kWriterReturnCode) { | 84 | if (_dumpres == kWriterReturnCode) { |
| 85 | // anytime we get kWriterReturnCode, this means that luaG_dump() attempted a dump | 85 | // anytime we get kWriterReturnCode, this means that luaW_dump() attempted a dump |
| 86 | return FuncSubType::Bytecode; | 86 | return FuncSubType::Bytecode; |
| 87 | } | 87 | } |
| 88 | // we didn't try to dump, therefore this is a LuaJIT-fast function | 88 | // we didn't try to dump, therefore this is a LuaJIT-fast function |
| @@ -115,7 +115,7 @@ namespace tools { | |||
| 115 | // &b is popped at that point (-> replaced by the result) | 115 | // &b is popped at that point (-> replaced by the result) |
| 116 | luaL_pushresult(&_b); // L_: ... {} ... "<result>" | 116 | luaL_pushresult(&_b); // L_: ... {} ... "<result>" |
| 117 | STACK_CHECK(L_, 1); | 117 | STACK_CHECK(L_, 1); |
| 118 | return luaG_tostring(L_, kIdxTop); | 118 | return luaW_tostring(L_, kIdxTop); |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | } // namespace tools | 121 | } // namespace tools |
| @@ -145,10 +145,10 @@ static void update_lookup_entry(lua_State* const L_, StackIndex const ctxBase_, | |||
| 145 | // first, raise an error if the function is already known | 145 | // first, raise an error if the function is already known |
| 146 | lua_pushvalue(L_, -1); // L_: ... {bfc} k o o | 146 | lua_pushvalue(L_, -1); // L_: ... {bfc} k o o |
| 147 | lua_rawget(L_, _dest); // L_: ... {bfc} k o name? | 147 | lua_rawget(L_, _dest); // L_: ... {bfc} k o name? |
| 148 | std::string_view const _prevName{ luaG_tostring(L_, kIdxTop) }; // nullptr if we got nil (first encounter of this object) | 148 | std::string_view const _prevName{ luaW_tostring(L_, kIdxTop) }; // nullptr if we got nil (first encounter of this object) |
| 149 | // push name in fqn stack (note that concatenation will crash if name is a not string or a number) | 149 | // push name in fqn stack (note that concatenation will crash if name is a not string or a number) |
| 150 | lua_pushvalue(L_, -3); // L_: ... {bfc} k o name? k | 150 | lua_pushvalue(L_, -3); // L_: ... {bfc} k o name? k |
| 151 | LUA_ASSERT(L_, luaG_type(L_, kIdxTop) == LuaType::NUMBER || luaG_type(L_, kIdxTop) == LuaType::STRING); | 151 | LUA_ASSERT(L_, luaW_type(L_, kIdxTop) == LuaType::NUMBER || luaW_type(L_, kIdxTop) == LuaType::STRING); |
| 152 | TableIndex const _deeper{ depth_ + 1 }; | 152 | TableIndex const _deeper{ depth_ + 1 }; |
| 153 | lua_rawseti(L_, _fqn, _deeper); // L_: ... {bfc} k o name? | 153 | lua_rawseti(L_, _fqn, _deeper); // L_: ... {bfc} k o name? |
| 154 | // generate name | 154 | // generate name |
| @@ -161,7 +161,7 @@ static void update_lookup_entry(lua_State* const L_, StackIndex const ctxBase_, | |||
| 161 | // Therefore, when we encounter an object for which a name was previously registered, we need to select a single name | 161 | // Therefore, when we encounter an object for which a name was previously registered, we need to select a single name |
| 162 | // based on some sorting order so that we end up with the same name in all databases whatever order the table walk yielded | 162 | // based on some sorting order so that we end up with the same name in all databases whatever order the table walk yielded |
| 163 | if (!_prevName.empty() && ((_prevName.size() < _newName.size()) || (_prevName <= _newName))) { | 163 | if (!_prevName.empty() && ((_prevName.size() < _newName.size()) || (_prevName <= _newName))) { |
| 164 | DEBUGSPEW_CODE(DebugSpew(_U) << luaG_typename(L_, StackIndex{ -3 }) << " '" << _newName << "' remains named '" << _prevName << "'" << std::endl); | 164 | DEBUGSPEW_CODE(DebugSpew(_U) << luaW_typename(L_, StackIndex{ -3 }) << " '" << _newName << "' remains named '" << _prevName << "'" << std::endl); |
| 165 | // the previous name is 'smaller' than the one we just generated: keep it! | 165 | // the previous name is 'smaller' than the one we just generated: keep it! |
| 166 | lua_pop(L_, 3); // L_: ... {bfc} k | 166 | lua_pop(L_, 3); // L_: ... {bfc} k |
| 167 | } else { | 167 | } else { |
| @@ -175,7 +175,7 @@ static void update_lookup_entry(lua_State* const L_, StackIndex const ctxBase_, | |||
| 175 | } else { | 175 | } else { |
| 176 | lua_remove(L_, -2); // L_: ... {bfc} k o "f.q.n" | 176 | lua_remove(L_, -2); // L_: ... {bfc} k o "f.q.n" |
| 177 | } | 177 | } |
| 178 | DEBUGSPEW_CODE(DebugSpew(_U) << luaG_typename(L_, StackIndex{ -2 }) << " '" << _newName << "'" << std::endl); | 178 | DEBUGSPEW_CODE(DebugSpew(_U) << luaW_typename(L_, StackIndex{ -2 }) << " '" << _newName << "'" << std::endl); |
| 179 | // prepare the stack for database feed | 179 | // prepare the stack for database feed |
| 180 | lua_pushvalue(L_, -1); // L_: ... {bfc} k o "f.q.n" "f.q.n" | 180 | lua_pushvalue(L_, -1); // L_: ... {bfc} k o "f.q.n" "f.q.n" |
| 181 | lua_pushvalue(L_, -3); // L_: ... {bfc} k o "f.q.n" "f.q.n" o | 181 | 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 | |||
| 210 | STACK_CHECK_START_REL(L_, 0); // L_: ... {i_} | 210 | STACK_CHECK_START_REL(L_, 0); // L_: ... {i_} |
| 211 | 211 | ||
| 212 | // if object is a userdata, replace it by its metatable | 212 | // if object is a userdata, replace it by its metatable |
| 213 | if (luaG_type(L_, i_) == LuaType::USERDATA) { | 213 | if (luaW_type(L_, i_) == LuaType::USERDATA) { |
| 214 | lua_getmetatable(L_, i_); // L_: ... {i_} mt | 214 | lua_getmetatable(L_, i_); // L_: ... {i_} mt |
| 215 | lua_replace(L_, i_); // L_: ... {i_} | 215 | lua_replace(L_, i_); // L_: ... {i_} |
| 216 | } | 216 | } |
| @@ -239,7 +239,7 @@ static void populate_lookup_table_recur(lua_State* const L_, StackIndex const db | |||
| 239 | lua_pushnil(L_); // L_: ... {i_} {bfc} nil | 239 | lua_pushnil(L_); // L_: ... {i_} {bfc} nil |
| 240 | while (lua_next(L_, i_) != 0) { // L_: ... {i_} {bfc} k v | 240 | while (lua_next(L_, i_) != 0) { // L_: ... {i_} {bfc} k v |
| 241 | // just for debug, not actually needed | 241 | // just for debug, not actually needed |
| 242 | // std::string_view const _key{ (luaG_type(L_, -2) == LuaType::STRING) ? luaG_tostring(L_, -2) : "not a string" }; | 242 | // std::string_view const _key{ (luaW_type(L_, -2) == LuaType::STRING) ? luaW_tostring(L_, -2) : "not a string" }; |
| 243 | // subtable: process it recursively | 243 | // subtable: process it recursively |
| 244 | if (lua_istable(L_, kIdxTop)) { // L_: ... {i_} {bfc} k {} | 244 | if (lua_istable(L_, kIdxTop)) { // L_: ... {i_} {bfc} k {} |
| 245 | // increment visit count to make sure we will actually scan it at this recursive level | 245 | // 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 | |||
| 256 | lua_rawset(L_, _breadthFirstCache); // L_: ... {i_} {bfc} k {} | 256 | lua_rawset(L_, _breadthFirstCache); // L_: ... {i_} {bfc} k {} |
| 257 | // generate a name, and if we already had one name, keep whichever is the shorter | 257 | // generate a name, and if we already had one name, keep whichever is the shorter |
| 258 | update_lookup_entry(L_, dbIdx_, depth_); // L_: ... {i_} {bfc} k | 258 | update_lookup_entry(L_, dbIdx_, depth_); // L_: ... {i_} {bfc} k |
| 259 | } else if (lua_isfunction(L_, kIdxTop) && (luaG_getfuncsubtype(L_, kIdxTop) != FuncSubType::Bytecode)) { | 259 | } else if (lua_isfunction(L_, kIdxTop) && (luaW_getfuncsubtype(L_, kIdxTop) != FuncSubType::Bytecode)) { |
| 260 | // generate a name, and if we already had one name, keep whichever is the shorter | 260 | // generate a name, and if we already had one name, keep whichever is the shorter |
| 261 | // this pops the function from the stack | 261 | // this pops the function from the stack |
| 262 | update_lookup_entry(L_, dbIdx_, depth_); // L_: ... {i_} {bfc} k | 262 | update_lookup_entry(L_, dbIdx_, depth_); // L_: ... {i_} {bfc} k |
| 263 | } else if (luaG_type(L_, kIdxTop) == LuaType::USERDATA) { | 263 | } else if (luaW_type(L_, kIdxTop) == LuaType::USERDATA) { |
| 264 | // generate a name, and if we already had one name, keep whichever is the shorter | 264 | // generate a name, and if we already had one name, keep whichever is the shorter |
| 265 | // this pops the userdata from the stack | 265 | // this pops the userdata from the stack |
| 266 | update_lookup_entry(L_, dbIdx_, depth_); // L_: ... {i_} {bfc} k | 266 | 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 | |||
| 273 | TableIndex const _deeper{ depth_ + 1 }; | 273 | TableIndex const _deeper{ depth_ + 1 }; |
| 274 | lua_pushnil(L_); // L_: ... {i_} {bfc} nil | 274 | lua_pushnil(L_); // L_: ... {i_} {bfc} nil |
| 275 | while (lua_next(L_, _breadthFirstCache) != 0) { // L_: ... {i_} {bfc} k {} | 275 | while (lua_next(L_, _breadthFirstCache) != 0) { // L_: ... {i_} {bfc} k {} |
| 276 | DEBUGSPEW_CODE(std::string_view const _key{ (luaG_type(L_, StackIndex{ -2 }) == LuaType::STRING) ? luaG_tostring(L_, StackIndex{ -2 }) : std::string_view{ "<not a string>" } }); | 276 | DEBUGSPEW_CODE(std::string_view const _key{ (luaW_type(L_, StackIndex{ -2 }) == LuaType::STRING) ? luaW_tostring(L_, StackIndex{ -2 }) : std::string_view{ "<not a string>" } }); |
| 277 | DEBUGSPEW_CODE(DebugSpew(_U) << "table '"<< _key <<"'" << std::endl); | 277 | DEBUGSPEW_CODE(DebugSpew(_U) << "table '"<< _key <<"'" << std::endl); |
| 278 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope2{ _U }); | 278 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope2{ _U }); |
| 279 | // un-visit this table in case we do need to process it | 279 | // un-visit this table in case we do need to process it |
| 280 | lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} | 280 | lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} |
| 281 | lua_rawget(L_, _cache); // L_: ... {i_} {bfc} k {} n | 281 | lua_rawget(L_, _cache); // L_: ... {i_} {bfc} k {} n |
| 282 | LUA_ASSERT(L_, luaG_type(L_, kIdxTop) == LuaType::NUMBER); | 282 | LUA_ASSERT(L_, luaW_type(L_, kIdxTop) == LuaType::NUMBER); |
| 283 | _visit_count = lua_tointeger(L_, -1) - 1; | 283 | _visit_count = lua_tointeger(L_, -1) - 1; |
| 284 | lua_pop(L_, 1); // L_: ... {i_} {bfc} k {} | 284 | lua_pop(L_, 1); // L_: ... {i_} {bfc} k {} |
| 285 | lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} | 285 | lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} |
| @@ -312,7 +312,7 @@ namespace tools { | |||
| 312 | // create a "fully.qualified.name" <-> function equivalence database | 312 | // create a "fully.qualified.name" <-> function equivalence database |
| 313 | void PopulateFuncLookupTable(lua_State* const L_, StackIndex const i_, std::string_view const& name_) | 313 | void PopulateFuncLookupTable(lua_State* const L_, StackIndex const i_, std::string_view const& name_) |
| 314 | { | 314 | { |
| 315 | StackIndex const _in_base{ luaG_absindex(L_, i_) }; | 315 | StackIndex const _in_base{ luaW_absindex(L_, i_) }; |
| 316 | DEBUGSPEW_CODE(Universe* _U = Universe::Get(L_)); | 316 | DEBUGSPEW_CODE(Universe* _U = Universe::Get(L_)); |
| 317 | std::string_view _name{ name_.empty() ? std::string_view{} : name_ }; | 317 | std::string_view _name{ name_.empty() ? std::string_view{} : name_ }; |
| 318 | DEBUGSPEW_CODE(DebugSpew(_U) << L_ << ": PopulateFuncLookupTable('" << _name << "')" << std::endl); | 318 | DEBUGSPEW_CODE(DebugSpew(_U) << L_ << ": PopulateFuncLookupTable('" << _name << "')" << std::endl); |
| @@ -323,24 +323,24 @@ namespace tools { | |||
| 323 | StackIndex const _dbIdx{ lua_gettop(L_) }; | 323 | StackIndex const _dbIdx{ lua_gettop(L_) }; |
| 324 | STACK_CHECK(L_, 1); | 324 | STACK_CHECK(L_, 1); |
| 325 | LUA_ASSERT(L_, lua_istable(L_, -1)); | 325 | LUA_ASSERT(L_, lua_istable(L_, -1)); |
| 326 | LuaType const _moduleType{ luaG_type(L_, _in_base) }; | 326 | LuaType const _moduleType{ luaW_type(L_, _in_base) }; |
| 327 | if ((_moduleType == LuaType::FUNCTION) || (_moduleType == LuaType::USERDATA)) { // for example when a module is a simple function | 327 | if ((_moduleType == LuaType::FUNCTION) || (_moduleType == LuaType::USERDATA)) { // for example when a module is a simple function |
| 328 | if (_name.empty()) { | 328 | if (_name.empty()) { |
| 329 | _name = "nullptr"; | 329 | _name = "nullptr"; |
| 330 | } | 330 | } |
| 331 | lua_pushvalue(L_, _in_base); // L_: {} f | 331 | lua_pushvalue(L_, _in_base); // L_: {} f |
| 332 | luaG_pushstring(L_, _name); // L_: {} f name_ | 332 | luaW_pushstring(L_, _name); // L_: {} f name_ |
| 333 | lua_rawset(L_, -3); // L_: {} | 333 | lua_rawset(L_, -3); // L_: {} |
| 334 | luaG_pushstring(L_, _name); // L_: {} name_ | 334 | luaW_pushstring(L_, _name); // L_: {} name_ |
| 335 | lua_pushvalue(L_, _in_base); // L_: {} name_ f | 335 | lua_pushvalue(L_, _in_base); // L_: {} name_ f |
| 336 | lua_rawset(L_, -3); // L_: {} | 336 | lua_rawset(L_, -3); // L_: {} |
| 337 | lua_pop(L_, 1); // L_: | 337 | lua_pop(L_, 1); // L_: |
| 338 | } else if (luaG_type(L_, _in_base) == LuaType::TABLE) { | 338 | } else if (luaW_type(L_, _in_base) == LuaType::TABLE) { |
| 339 | lua_newtable(L_); // L_: {} {fqn} | 339 | lua_newtable(L_); // L_: {} {fqn} |
| 340 | TableIndex _startDepth{ 0 }; | 340 | TableIndex _startDepth{ 0 }; |
| 341 | if (!_name.empty()) { | 341 | if (!_name.empty()) { |
| 342 | STACK_CHECK(L_, 2); | 342 | STACK_CHECK(L_, 2); |
| 343 | luaG_pushstring(L_, _name); // L_: {} {fqn} "name" | 343 | luaW_pushstring(L_, _name); // L_: {} {fqn} "name" |
| 344 | // generate a name, and if we already had one name, keep whichever is the shorter | 344 | // generate a name, and if we already had one name, keep whichever is the shorter |
| 345 | lua_pushvalue(L_, _in_base); // L_: {} {fqn} "name" t | 345 | lua_pushvalue(L_, _in_base); // L_: {} {fqn} "name" t |
| 346 | update_lookup_entry(L_, _dbIdx, _startDepth); // L_: {} {fqn} "name" | 346 | update_lookup_entry(L_, _dbIdx, _startDepth); // L_: {} {fqn} "name" |
| @@ -355,7 +355,7 @@ namespace tools { | |||
| 355 | lua_pop(L_, 3); // L_: | 355 | lua_pop(L_, 3); // L_: |
| 356 | } else { | 356 | } else { |
| 357 | lua_pop(L_, 1); // L_: | 357 | lua_pop(L_, 1); // L_: |
| 358 | raise_luaL_error(L_, "unsupported module type %s", luaG_typename(L_, _in_base).data()); | 358 | raise_luaL_error(L_, "unsupported module type %s", luaW_typename(L_, _in_base).data()); |
| 359 | } | 359 | } |
| 360 | STACK_CHECK(L_, 0); | 360 | STACK_CHECK(L_, 0); |
| 361 | } | 361 | } |
| @@ -373,7 +373,7 @@ namespace tools { | |||
| 373 | +[](lua_State* L_) | 373 | +[](lua_State* L_) |
| 374 | { | 374 | { |
| 375 | int const _args{ lua_gettop(L_) }; // L_: args... | 375 | int const _args{ lua_gettop(L_) }; // L_: args... |
| 376 | //[[maybe_unused]] std::string_view const _modname{ luaG_checkstring(L_, 1) }; | 376 | //[[maybe_unused]] std::string_view const _modname{ luaW_checkstring(L_, 1) }; |
| 377 | 377 | ||
| 378 | STACK_GROW(L_, 1); | 378 | STACK_GROW(L_, 1); |
| 379 | 379 | ||
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 | |||
| 21 | }; | 21 | }; |
| 22 | 22 | ||
| 23 | [[nodiscard]] | 23 | [[nodiscard]] |
| 24 | FuncSubType luaG_getfuncsubtype(lua_State* L_, StackIndex i_); | 24 | FuncSubType luaW_getfuncsubtype(lua_State* L_, StackIndex i_); |
| 25 | 25 | ||
| 26 | // ################################################################################################# | 26 | // ################################################################################################# |
| 27 | 27 | ||
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 | |||
| 96 | while (_lane != TRACKING_END) { | 96 | while (_lane != TRACKING_END) { |
| 97 | // insert a { name='<name>', status='<status>' } tuple, so that several lanes with the same name can't clobber each other | 97 | // insert a { name='<name>', status='<status>' } tuple, so that several lanes with the same name can't clobber each other |
| 98 | lua_createtable(L_, 0, 2); // L_: {} {} | 98 | lua_createtable(L_, 0, 2); // L_: {} {} |
| 99 | luaG_pushstring(L_, _lane->getDebugName()); // L_: {} {} "name" | 99 | luaW_pushstring(L_, _lane->getDebugName()); // L_: {} {} "name" |
| 100 | lua_setfield(L_, -2, "name"); // L_: {} {} | 100 | lua_setfield(L_, -2, "name"); // L_: {} {} |
| 101 | _lane->pushStatusString(L_); // L_: {} {} "<status>" | 101 | _lane->pushStatusString(L_); // L_: {} {} "<status>" |
| 102 | lua_setfield(L_, -2, "status"); // L_: {} {} | 102 | 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 | |||
| 80 | STACK_GROW(L_, 1); | 80 | STACK_GROW(L_, 1); |
| 81 | STACK_CHECK_START_REL(L_, 0); | 81 | STACK_CHECK_START_REL(L_, 0); |
| 82 | pushValue(L_); // L_: ... {}|nil | 82 | pushValue(L_); // L_: ... {}|nil |
| 83 | T* const value{ luaG_tolightuserdata<T>(L_, kIdxTop) }; | 83 | T* const value{ luaW_tolightuserdata<T>(L_, kIdxTop) }; |
| 84 | lua_pop(L_, 1); // L_: ... | 84 | lua_pop(L_, 1); // L_: ... |
| 85 | STACK_CHECK(L_, 0); | 85 | STACK_CHECK(L_, 0); |
| 86 | return value; | 86 | return value; |
| @@ -125,8 +125,8 @@ class RegistryUniqueKey final | |||
| 125 | if (!mode_.empty()) { | 125 | if (!mode_.empty()) { |
| 126 | STACK_GROW(L_, 3); | 126 | STACK_GROW(L_, 3); |
| 127 | lua_createtable(L_, 0, 1); // L_: {} mt | 127 | lua_createtable(L_, 0, 1); // L_: {} mt |
| 128 | luaG_pushstring(L_, "__mode"); // L_: {} mt "__mode" | 128 | luaW_pushstring(L_, "__mode"); // L_: {} mt "__mode" |
| 129 | luaG_pushstring(L_, mode_); // L_: {} mt "__mode" mode | 129 | luaW_pushstring(L_, mode_); // L_: {} mt "__mode" mode |
| 130 | lua_rawset(L_, -3); // L_: {} mt | 130 | lua_rawset(L_, -3); // L_: {} mt |
| 131 | lua_setmetatable(L_, -2); // L_: {} | 131 | lua_setmetatable(L_, -2); // L_: {} |
| 132 | } | 132 | } |
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 | |||
| 111 | } | 111 | } |
| 112 | kConfigRegKey.pushValue(L_); // L_: config | 112 | kConfigRegKey.pushValue(L_); // L_: config |
| 113 | STACK_CHECK(L_, 1); | 113 | STACK_CHECK(L_, 1); |
| 114 | LuaType const _funcType{ luaG_getfield(L_, kIdxTop, kOnStateCreate) }; // L_: config on_state_create() | 114 | LuaType const _funcType{ luaW_getfield(L_, kIdxTop, kOnStateCreate) }; // L_: config on_state_create() |
| 115 | if (_funcType != LuaType::FUNCTION) { | 115 | if (_funcType != LuaType::FUNCTION) { |
| 116 | raise_luaL_error(L_, "INTERNAL ERROR: %s is a %s, not a function", kOnStateCreate.data(), luaG_typename(L_, _funcType).data()); | 116 | raise_luaL_error(L_, "INTERNAL ERROR: %s is a %s, not a function", kOnStateCreate.data(), luaW_typename(L_, _funcType).data()); |
| 117 | } | 117 | } |
| 118 | lua_remove(L_, -2); // L_: on_state_create() | 118 | lua_remove(L_, -2); // L_: on_state_create() |
| 119 | } | 119 | } |
| 120 | STACK_CHECK(L_, 1); | 120 | STACK_CHECK(L_, 1); |
| 121 | // capture error and raise it in caller state | 121 | // capture error and raise it in caller state |
| 122 | std::string_view const _stateType{ mode_ == LookupMode::LaneBody ? "lane" : "keeper" }; | 122 | std::string_view const _stateType{ mode_ == LookupMode::LaneBody ? "lane" : "keeper" }; |
| 123 | luaG_pushstring(L_, _stateType); // L_: on_state_create() "<type>" | 123 | luaW_pushstring(L_, _stateType); // L_: on_state_create() "<type>" |
| 124 | if (lua_pcall(L_, 1, 0, 0) != LUA_OK) { | 124 | if (lua_pcall(L_, 1, 0, 0) != LUA_OK) { |
| 125 | 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()); | 125 | 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()); |
| 126 | } | 126 | } |
| 127 | STACK_CHECK(L_, 0); | 127 | STACK_CHECK(L_, 0); |
| 128 | } | 128 | } |
| @@ -137,14 +137,14 @@ Universe* Universe::Create(lua_State* const L_) | |||
| 137 | static constexpr StackIndex kIdxSettings{ 1 }; | 137 | static constexpr StackIndex kIdxSettings{ 1 }; |
| 138 | LUA_ASSERT(L_, lua_gettop(L_) == 1 && lua_istable(L_, 1)); | 138 | LUA_ASSERT(L_, lua_gettop(L_) == 1 && lua_istable(L_, 1)); |
| 139 | STACK_CHECK_START_REL(L_, 0); // L_: settings | 139 | STACK_CHECK_START_REL(L_, 0); // L_: settings |
| 140 | std::ignore = luaG_getfield(L_, kIdxSettings, "nb_user_keepers"); // L_: settings nb_user_keepers | 140 | std::ignore = luaW_getfield(L_, kIdxSettings, "nb_user_keepers"); // L_: settings nb_user_keepers |
| 141 | int const _nbUserKeepers{ static_cast<int>(lua_tointeger(L_, -1)) + 1}; | 141 | int const _nbUserKeepers{ static_cast<int>(lua_tointeger(L_, -1)) + 1}; |
| 142 | lua_pop(L_, 1); // L_: settings | 142 | lua_pop(L_, 1); // L_: settings |
| 143 | if (_nbUserKeepers < 1) { | 143 | if (_nbUserKeepers < 1) { |
| 144 | raise_luaL_error(L_, "Bad number of additional keepers (%d)", _nbUserKeepers); | 144 | raise_luaL_error(L_, "Bad number of additional keepers (%d)", _nbUserKeepers); |
| 145 | } | 145 | } |
| 146 | STACK_CHECK(L_, 0); | 146 | STACK_CHECK(L_, 0); |
| 147 | std::ignore = luaG_getfield(L_, kIdxSettings, "keepers_gc_threshold"); // L_: settings keepers_gc_threshold | 147 | std::ignore = luaW_getfield(L_, kIdxSettings, "keepers_gc_threshold"); // L_: settings keepers_gc_threshold |
| 148 | int const _keepers_gc_threshold{ static_cast<int>(lua_tointeger(L_, -1)) }; | 148 | int const _keepers_gc_threshold{ static_cast<int>(lua_tointeger(L_, -1)) }; |
| 149 | lua_pop(L_, 1); // L_: settings | 149 | lua_pop(L_, 1); // L_: settings |
| 150 | STACK_CHECK(L_, 0); | 150 | STACK_CHECK(L_, 0); |
| @@ -157,30 +157,30 @@ Universe* Universe::Create(lua_State* const L_) | |||
| 157 | 157 | ||
| 158 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); | 158 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); |
| 159 | lua_createtable(L_, 0, 1); // L_: settings universe {mt} | 159 | lua_createtable(L_, 0, 1); // L_: settings universe {mt} |
| 160 | std::ignore = luaG_getfield(L_, kIdxSettings, "shutdown_timeout"); // L_: settings universe {mt} shutdown_timeout | 160 | std::ignore = luaW_getfield(L_, kIdxSettings, "shutdown_timeout"); // L_: settings universe {mt} shutdown_timeout |
| 161 | lua_pushcclosure(L_, UniverseGC, 1); // L_: settings universe {mt} UniverseGC | 161 | lua_pushcclosure(L_, UniverseGC, 1); // L_: settings universe {mt} UniverseGC |
| 162 | lua_setfield(L_, -2, "__gc"); // L_: settings universe {mt} | 162 | lua_setfield(L_, -2, "__gc"); // L_: settings universe {mt} |
| 163 | lua_setmetatable(L_, -2); // L_: settings universe | 163 | lua_setmetatable(L_, -2); // L_: settings universe |
| 164 | lua_pop(L_, 1); // L_: settings | 164 | lua_pop(L_, 1); // L_: settings |
| 165 | 165 | ||
| 166 | std::ignore = luaG_getfield(L_, kIdxSettings, "linda_wake_period"); // L_: settings linda_wake_period | 166 | std::ignore = luaW_getfield(L_, kIdxSettings, "linda_wake_period"); // L_: settings linda_wake_period |
| 167 | if (luaG_type(L_, kIdxTop) == LuaType::NUMBER) { | 167 | if (luaW_type(L_, kIdxTop) == LuaType::NUMBER) { |
| 168 | _U->lindaWakePeriod = lua_Duration{ lua_tonumber(L_, kIdxTop) }; | 168 | _U->lindaWakePeriod = lua_Duration{ lua_tonumber(L_, kIdxTop) }; |
| 169 | } else { | 169 | } else { |
| 170 | LUA_ASSERT(L_, luaG_tostring(L_, kIdxTop) == "never"); | 170 | LUA_ASSERT(L_, luaW_tostring(L_, kIdxTop) == "never"); |
| 171 | } | 171 | } |
| 172 | lua_pop(L_, 1); // L_: settings | 172 | lua_pop(L_, 1); // L_: settings |
| 173 | 173 | ||
| 174 | std::ignore = luaG_getfield(L_, kIdxSettings, "strip_functions"); // L_: settings strip_functions | 174 | std::ignore = luaW_getfield(L_, kIdxSettings, "strip_functions"); // L_: settings strip_functions |
| 175 | _U->stripFunctions = lua_toboolean(L_, -1) ? true : false; | 175 | _U->stripFunctions = lua_toboolean(L_, -1) ? true : false; |
| 176 | lua_pop(L_, 1); // L_: settings | 176 | lua_pop(L_, 1); // L_: settings |
| 177 | 177 | ||
| 178 | std::ignore = luaG_getfield(L_, kIdxSettings, "verbose_errors"); // L_: settings verbose_errors | 178 | std::ignore = luaW_getfield(L_, kIdxSettings, "verbose_errors"); // L_: settings verbose_errors |
| 179 | _U->verboseErrors = lua_toboolean(L_, -1) ? true : false; | 179 | _U->verboseErrors = lua_toboolean(L_, -1) ? true : false; |
| 180 | lua_pop(L_, 1); // L_: settings | 180 | lua_pop(L_, 1); // L_: settings |
| 181 | 181 | ||
| 182 | // tracking | 182 | // tracking |
| 183 | std::ignore = luaG_getfield(L_, kIdxSettings, "track_lanes"); // L_: settings track_lanes | 183 | std::ignore = luaW_getfield(L_, kIdxSettings, "track_lanes"); // L_: settings track_lanes |
| 184 | if (lua_toboolean(L_, -1)) { | 184 | if (lua_toboolean(L_, -1)) { |
| 185 | _U->tracker.activate(); | 185 | _U->tracker.activate(); |
| 186 | } | 186 | } |
| @@ -217,7 +217,7 @@ static void* libc_lua_Alloc([[maybe_unused]] void* const ud_, [[maybe_unused]] v | |||
| 217 | // ################################################################################################# | 217 | // ################################################################################################# |
| 218 | 218 | ||
| 219 | [[nodiscard]] | 219 | [[nodiscard]] |
| 220 | static int luaG_provide_protected_allocator(lua_State* const L_) | 220 | static int luaW_provide_protected_allocator(lua_State* const L_) |
| 221 | { | 221 | { |
| 222 | Universe* const _U{ Universe::Get(L_) }; | 222 | Universe* const _U{ Universe::Get(L_) }; |
| 223 | // push a new full userdata on the stack, giving access to the universe's protected allocator | 223 | // 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_) | |||
| 245 | // start by just grabbing whatever allocator was provided to the master state | 245 | // start by just grabbing whatever allocator was provided to the master state |
| 246 | protectedAllocator.initFrom(L_); | 246 | protectedAllocator.initFrom(L_); |
| 247 | STACK_CHECK_START_REL(L_, 1); // L_: settings | 247 | STACK_CHECK_START_REL(L_, 1); // L_: settings |
| 248 | switch (luaG_getfield(L_, kIdxTop, "allocator")) { // L_: settings allocator|nil|"protected" | 248 | switch (luaW_getfield(L_, kIdxTop, "allocator")) { // L_: settings allocator|nil|"protected" |
| 249 | case LuaType::NIL: | 249 | case LuaType::NIL: |
| 250 | // nothing else to do | 250 | // nothing else to do |
| 251 | break; | 251 | break; |
| 252 | 252 | ||
| 253 | case LuaType::STRING: | 253 | case LuaType::STRING: |
| 254 | LUA_ASSERT(L_, luaG_tostring(L_, kIdxTop) == "protected"); | 254 | LUA_ASSERT(L_, luaW_tostring(L_, kIdxTop) == "protected"); |
| 255 | // set the original allocator to call from inside protection by the mutex | 255 | // set the original allocator to call from inside protection by the mutex |
| 256 | protectedAllocator.installIn(L_); | 256 | protectedAllocator.installIn(L_); |
| 257 | // before a state is created, this function will be called to obtain the allocator | 257 | // before a state is created, this function will be called to obtain the allocator |
| 258 | provideAllocator = luaG_provide_protected_allocator; | 258 | provideAllocator = luaW_provide_protected_allocator; |
| 259 | break; | 259 | break; |
| 260 | 260 | ||
| 261 | case LuaType::FUNCTION: | 261 | case LuaType::FUNCTION: |
| @@ -276,14 +276,14 @@ void Universe::initializeAllocatorFunction(lua_State* const L_) | |||
| 276 | break; | 276 | break; |
| 277 | 277 | ||
| 278 | default: // should be filtered out in lanes.lua | 278 | default: // should be filtered out in lanes.lua |
| 279 | raise_luaL_error(L_, "Bad config.allocator type %s", luaG_typename(L_, kIdxTop).data()); | 279 | raise_luaL_error(L_, "Bad config.allocator type %s", luaW_typename(L_, kIdxTop).data()); |
| 280 | } | 280 | } |
| 281 | lua_pop(L_, 1); // L_: settings | 281 | lua_pop(L_, 1); // L_: settings |
| 282 | STACK_CHECK(L_, 1); | 282 | STACK_CHECK(L_, 1); |
| 283 | 283 | ||
| 284 | std::ignore = luaG_getfield(L_, kIdxTop, "internal_allocator"); // L_: settings "libc"|"allocator" | 284 | std::ignore = luaW_getfield(L_, kIdxTop, "internal_allocator"); // L_: settings "libc"|"allocator" |
| 285 | LUA_ASSERT(L_, lua_isstring(L_, kIdxTop)); // should be the case due to lanes.lua parameter validation | 285 | LUA_ASSERT(L_, lua_isstring(L_, kIdxTop)); // should be the case due to lanes.lua parameter validation |
| 286 | std::string_view const _allocator{ luaG_tostring(L_, kIdxTop) }; | 286 | std::string_view const _allocator{ luaW_tostring(L_, kIdxTop) }; |
| 287 | // use whatever the provider provides. This performs validation of what provideAllocator is giving | 287 | // use whatever the provider provides. This performs validation of what provideAllocator is giving |
| 288 | // we do this even if _allocator == "libc", to have the validation part | 288 | // we do this even if _allocator == "libc", to have the validation part |
| 289 | internalAllocator = resolveAndValidateAllocator(L_, "internal"); | 289 | internalAllocator = resolveAndValidateAllocator(L_, "internal"); |
| @@ -305,7 +305,7 @@ int Universe::InitializeFinalizer(lua_State* const L_) | |||
| 305 | 305 | ||
| 306 | // make sure we are only called from the Master Lua State! | 306 | // make sure we are only called from the Master Lua State! |
| 307 | kUniverseFullRegKey.pushValue(L_); // L_: f U | 307 | kUniverseFullRegKey.pushValue(L_); // L_: f U |
| 308 | if (luaG_type(L_, kIdxTop) != LuaType::USERDATA) { | 308 | if (luaW_type(L_, kIdxTop) != LuaType::USERDATA) { |
| 309 | raise_luaL_error(L_, "lanes.%s called from inside a lane", kFinally); | 309 | raise_luaL_error(L_, "lanes.%s called from inside a lane", kFinally); |
| 310 | } | 310 | } |
| 311 | lua_pop(L_, 1); // L_: f | 311 | lua_pop(L_, 1); // L_: f |
| @@ -321,8 +321,8 @@ int Universe::InitializeFinalizer(lua_State* const L_) | |||
| 321 | void Universe::initializeOnStateCreate(lua_State* const L_) | 321 | void Universe::initializeOnStateCreate(lua_State* const L_) |
| 322 | { | 322 | { |
| 323 | STACK_CHECK_START_REL(L_, 0); // L_: settings | 323 | STACK_CHECK_START_REL(L_, 0); // L_: settings |
| 324 | if (luaG_getfield(L_, kIdxTop, kOnStateCreate) != LuaType::NIL) { // L_: settings on_state_create|nil | 324 | if (luaW_getfield(L_, kIdxTop, kOnStateCreate) != LuaType::NIL) { // L_: settings on_state_create|nil |
| 325 | LUA_ASSERT(L_, luaG_type(L_, kIdxTop) == LuaType::FUNCTION); // ensured by lanes.lua parameter validation | 325 | LUA_ASSERT(L_, luaW_type(L_, kIdxTop) == LuaType::FUNCTION); // ensured by lanes.lua parameter validation |
| 326 | // store C function pointer in an internal variable | 326 | // store C function pointer in an internal variable |
| 327 | lua_CFunction const _func{ lua_tocfunction(L_, -1) }; // L_: settings on_state_create | 327 | lua_CFunction const _func{ lua_tocfunction(L_, -1) }; // L_: settings on_state_create |
| 328 | if (_func) { | 328 | if (_func) { |
| @@ -335,7 +335,7 @@ void Universe::initializeOnStateCreate(lua_State* const L_) | |||
| 335 | // remove this C function from the config table so that it doesn't cause problems | 335 | // remove this C function from the config table so that it doesn't cause problems |
| 336 | // when we transfer the config table in newly created Lua states | 336 | // when we transfer the config table in newly created Lua states |
| 337 | lua_pushnil(L_); // L_: settings on_state_create nil | 337 | lua_pushnil(L_); // L_: settings on_state_create nil |
| 338 | luaG_setfield(L_, StackIndex{ -3 }, kOnStateCreate); // L_: settings on_state_create | 338 | luaW_setfield(L_, StackIndex{ -3 }, kOnStateCreate); // L_: settings on_state_create |
| 339 | } else { | 339 | } else { |
| 340 | // the function is still in the config table. we indicate this with the uintptr_t alternative (actual value is irrelevant) | 340 | // the function is still in the config table. we indicate this with the uintptr_t alternative (actual value is irrelevant) |
| 341 | onStateCreateFunc.emplace<uintptr_t>(std::bit_cast<uintptr_t>(kOnStateCreate.data())); | 341 | onStateCreateFunc.emplace<uintptr_t>(std::bit_cast<uintptr_t>(kOnStateCreate.data())); |
| @@ -358,7 +358,7 @@ lanes::AllocatorDefinition Universe::resolveAndValidateAllocator(lua_State* cons | |||
| 358 | 358 | ||
| 359 | STACK_CHECK_START_REL(L_, 0); // here, we have a function we can call to obtain an allocator | 359 | STACK_CHECK_START_REL(L_, 0); // here, we have a function we can call to obtain an allocator |
| 360 | lua_pushcclosure(L_, provideAllocator, 0); // L_: provideAllocator() | 360 | lua_pushcclosure(L_, provideAllocator, 0); // L_: provideAllocator() |
| 361 | luaG_pushstring(L_, hint_); // L_: provideAllocator() "<hint>" | 361 | luaW_pushstring(L_, hint_); // L_: provideAllocator() "<hint>" |
| 362 | lua_call(L_, 1, 1); // L_: result | 362 | lua_call(L_, 1, 1); // L_: result |
| 363 | // make sure we have a valid AllocatorDefinition on the stack (an error is raised instead if it is not the case) | 363 | // make sure we have a valid AllocatorDefinition on the stack (an error is raised instead if it is not the case) |
| 364 | _ret = lanes::AllocatorDefinition::Validated(L_, kIdxTop); | 364 | _ret = lanes::AllocatorDefinition::Validated(L_, kIdxTop); |
| @@ -433,7 +433,7 @@ int Universe::UniverseGC(lua_State* const L_) | |||
| 433 | { | 433 | { |
| 434 | lua_Duration const _shutdown_timeout{ lua_tonumber(L_, lua_upvalueindex(1)) }; | 434 | lua_Duration const _shutdown_timeout{ lua_tonumber(L_, lua_upvalueindex(1)) }; |
| 435 | STACK_CHECK_START_ABS(L_, 1); | 435 | STACK_CHECK_START_ABS(L_, 1); |
| 436 | Universe* const _U{ luaG_tofulluserdata<Universe>(L_, StackIndex{ 1 }) }; // L_: U | 436 | Universe* const _U{ luaW_tofulluserdata<Universe>(L_, StackIndex{ 1 }) }; // L_: U |
| 437 | 437 | ||
| 438 | // attempt to terminate all lanes with increasingly stronger cancel methods | 438 | // attempt to terminate all lanes with increasingly stronger cancel methods |
| 439 | bool const _allLanesTerminated{ | 439 | bool const _allLanesTerminated{ |
| @@ -456,7 +456,7 @@ int Universe::UniverseGC(lua_State* const L_) | |||
| 456 | if (lua_isnil(L_, kIdxTop)) { | 456 | if (lua_isnil(L_, kIdxTop)) { |
| 457 | lua_pop(L_, 1); // L_: U | 457 | lua_pop(L_, 1); // L_: U |
| 458 | // no finalizer, or it returned no value: push some default message on the stack, in case it is necessary | 458 | // no finalizer, or it returned no value: push some default message on the stack, in case it is necessary |
| 459 | luaG_pushstring(L_, "uncooperative lanes detected at shutdown"); // L_: U "msg" | 459 | luaW_pushstring(L_, "uncooperative lanes detected at shutdown"); // L_: U "msg" |
| 460 | } | 460 | } |
| 461 | STACK_CHECK(L_, 2); | 461 | STACK_CHECK(L_, 2); |
| 462 | 462 | ||
| @@ -466,7 +466,7 @@ int Universe::UniverseGC(lua_State* const L_) | |||
| 466 | bool const _detectedUncooperativeLanes{ _U->selfdestructFirst != SELFDESTRUCT_END }; | 466 | bool const _detectedUncooperativeLanes{ _U->selfdestructFirst != SELFDESTRUCT_END }; |
| 467 | if (_detectedUncooperativeLanes) { | 467 | if (_detectedUncooperativeLanes) { |
| 468 | _U->flagDanglingLanes(); | 468 | _U->flagDanglingLanes(); |
| 469 | if (luaG_tostring(L_, kIdxTop) == "freeze") { | 469 | if (luaW_tostring(L_, kIdxTop) == "freeze") { |
| 470 | std::this_thread::sleep_until(std::chrono::time_point<std::chrono::steady_clock>::max()); | 470 | std::this_thread::sleep_until(std::chrono::time_point<std::chrono::steady_clock>::max()); |
| 471 | } else { | 471 | } else { |
| 472 | // take the value returned by the finalizer (or our default message) and throw it as an error | 472 | // 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 | |||
| 128 | 128 | ||
| 129 | public: | 129 | public: |
| 130 | [[nodiscard]] | 130 | [[nodiscard]] |
| 131 | static void* operator new([[maybe_unused]] size_t const size_, lua_State* const L_) noexcept { return luaG_newuserdatauv<Universe>(L_, UserValueCount{ 0 }); }; | 131 | static void* operator new([[maybe_unused]] size_t const size_, lua_State* const L_) noexcept { return luaW_newuserdatauv<Universe>(L_, UserValueCount{ 0 }); }; |
| 132 | // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception | 132 | // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception |
| 133 | static void operator delete([[maybe_unused]] void* const p_, [[maybe_unused]] lua_State* const L_) {} // nothing to do, as nothing is allocated independently | 133 | static void operator delete([[maybe_unused]] void* const p_, [[maybe_unused]] lua_State* const L_) {} // nothing to do, as nothing is allocated independently |
| 134 | 134 | ||
