diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-05 16:07:08 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-05 16:07:08 +0200 |
commit | 4670b7deee3eeca20f72d91d9fb7094b51348956 (patch) | |
tree | 7064c7de946cfa717e128dc680756ecd6dc4e13f /src | |
parent | b6d344fe7991b525958a5825fbd22d7c529d21cc (diff) | |
download | lanes-4670b7deee3eeca20f72d91d9fb7094b51348956.tar.gz lanes-4670b7deee3eeca20f72d91d9fb7094b51348956.tar.bz2 lanes-4670b7deee3eeca20f72d91d9fb7094b51348956.zip |
Modernize compat
Diffstat (limited to 'src')
-rw-r--r-- | src/cancel.cpp | 6 | ||||
-rw-r--r-- | src/compat.h | 145 | ||||
-rw-r--r-- | src/deep.cpp | 8 | ||||
-rw-r--r-- | src/intercopycontext.cpp | 42 | ||||
-rw-r--r-- | src/lane.cpp | 32 | ||||
-rw-r--r-- | src/lanes.cpp | 34 | ||||
-rw-r--r-- | src/linda.cpp | 20 | ||||
-rw-r--r-- | src/lindafactory.cpp | 6 | ||||
-rw-r--r-- | src/nameof.cpp | 14 | ||||
-rw-r--r-- | src/state.cpp | 10 | ||||
-rw-r--r-- | src/tools.cpp | 34 | ||||
-rw-r--r-- | src/tracker.cpp | 2 | ||||
-rw-r--r-- | src/universe.cpp | 10 |
13 files changed, 206 insertions, 157 deletions
diff --git a/src/cancel.cpp b/src/cancel.cpp index 23d9d04..f53dc36 100644 --- a/src/cancel.cpp +++ b/src/cancel.cpp | |||
@@ -185,8 +185,8 @@ CancelOp which_cancel_op(std::string_view const& opString_) | |||
185 | 185 | ||
186 | [[nodiscard]] static CancelOp which_cancel_op(lua_State* L_, int idx_) | 186 | [[nodiscard]] static CancelOp which_cancel_op(lua_State* L_, int idx_) |
187 | { | 187 | { |
188 | if (lua_type(L_, idx_) == LUA_TSTRING) { | 188 | if (luaG_type(L_, idx_) == LuaType::STRING) { |
189 | std::string_view const _str{ lua_tostringview(L_, idx_) }; | 189 | std::string_view const _str{ luaG_tostringview(L_, idx_) }; |
190 | CancelOp _op{ which_cancel_op(_str) }; | 190 | CancelOp _op{ which_cancel_op(_str) }; |
191 | lua_remove(L_, idx_); // argument is processed, remove it | 191 | lua_remove(L_, idx_); // argument is processed, remove it |
192 | if (_op == CancelOp::Invalid) { | 192 | if (_op == CancelOp::Invalid) { |
@@ -215,7 +215,7 @@ LUAG_FUNC(thread_cancel) | |||
215 | } | 215 | } |
216 | 216 | ||
217 | std::chrono::time_point<std::chrono::steady_clock> _until{ std::chrono::time_point<std::chrono::steady_clock>::max() }; | 217 | std::chrono::time_point<std::chrono::steady_clock> _until{ std::chrono::time_point<std::chrono::steady_clock>::max() }; |
218 | if (lua_type(L_, 2) == LUA_TNUMBER) { // we don't want to use lua_isnumber() because of autocoercion | 218 | if (luaG_type(L_, 2) == LuaType::NUMBER) { // we don't want to use lua_isnumber() because of autocoercion |
219 | lua_Duration const duration{ lua_tonumber(L_, 2) }; | 219 | lua_Duration const duration{ lua_tonumber(L_, 2) }; |
220 | if (duration.count() >= 0.0) { | 220 | if (duration.count() >= 0.0) { |
221 | _until = std::chrono::steady_clock::now() + std::chrono::duration_cast<std::chrono::steady_clock::duration>(duration); | 221 | _until = std::chrono::steady_clock::now() + std::chrono::duration_cast<std::chrono::steady_clock::duration>(duration); |
diff --git a/src/compat.h b/src/compat.h index 43f8922..6307d86 100644 --- a/src/compat.h +++ b/src/compat.h | |||
@@ -47,11 +47,11 @@ enum class LuaType | |||
47 | CDATA = 10 // LuaJIT CDATA | 47 | CDATA = 10 // LuaJIT CDATA |
48 | }; | 48 | }; |
49 | 49 | ||
50 | inline LuaType lua_type_as_enum(lua_State* L_, int idx_) | 50 | inline LuaType luaG_type(lua_State* L_, int idx_) |
51 | { | 51 | { |
52 | return static_cast<LuaType>(lua_type(L_, idx_)); | 52 | return static_cast<LuaType>(lua_type(L_, idx_)); |
53 | } | 53 | } |
54 | inline char const* lua_typename(lua_State* L_, LuaType t_) | 54 | inline char const* luaG_typename(lua_State* L_, LuaType t_) |
55 | { | 55 | { |
56 | return lua_typename(L_, static_cast<int>(t_)); | 56 | return lua_typename(L_, static_cast<int>(t_)); |
57 | } | 57 | } |
@@ -79,18 +79,10 @@ inline size_t lua_rawlen(lua_State* L_, int idx_) | |||
79 | { | 79 | { |
80 | return lua_objlen(L_, idx_); | 80 | return lua_objlen(L_, idx_); |
81 | } | 81 | } |
82 | inline void luaG_registerlibfuncs(lua_State* L_, luaL_Reg const funcs_[]) | ||
83 | { | ||
84 | luaL_register(L_, nullptr, funcs_); | ||
85 | } | ||
86 | // keep as macros to be consistent with Lua headers | 82 | // keep as macros to be consistent with Lua headers |
87 | #define LUA_OK 0 | 83 | #define LUA_OK 0 |
88 | #define LUA_ERRGCMM 666 // doesn't exist in Lua 5.1, we don't care about the actual value | 84 | #define LUA_ERRGCMM 666 // doesn't exist in Lua 5.1, we don't care about the actual value |
89 | void luaL_requiref(lua_State* L_, const char* modname_, lua_CFunction openf_, int glb_); // implementation copied from Lua 5.2 sources | 85 | void luaL_requiref(lua_State* L_, const char* modname_, lua_CFunction openf_, int glb_); // implementation copied from Lua 5.2 sources |
90 | inline int lua504_dump(lua_State* L_, lua_Writer writer_, void* data_, [[maybe_unused]] int strip_) | ||
91 | { | ||
92 | return lua_dump(L_, writer_, data_); | ||
93 | } | ||
94 | #define LUA_LOADED_TABLE "_LOADED" // // doesn't exist in Lua 5.1 | 86 | #define LUA_LOADED_TABLE "_LOADED" // // doesn't exist in Lua 5.1 |
95 | 87 | ||
96 | int luaL_getsubtable(lua_State* L_, int idx_, const char* fname_); | 88 | int luaL_getsubtable(lua_State* L_, int idx_, const char* fname_); |
@@ -102,14 +94,6 @@ int luaL_getsubtable(lua_State* L_, int idx_, const char* fname_); | |||
102 | // wrap Lua 5.2 calls under Lua 5.1 API when it is simpler that way | 94 | // wrap Lua 5.2 calls under Lua 5.1 API when it is simpler that way |
103 | #if LUA_VERSION_NUM == 502 | 95 | #if LUA_VERSION_NUM == 502 |
104 | 96 | ||
105 | inline void luaG_registerlibfuncs(lua_State* L_, luaL_Reg const funcs_[]) | ||
106 | { | ||
107 | luaL_setfuncs(L_, funcs_, 0); | ||
108 | } | ||
109 | inline int lua504_dump(lua_State* L_, lua_Writer writer_, void* data_, [[maybe_unused]] int strip_) | ||
110 | { | ||
111 | return lua_dump(L_, writer_, data_); | ||
112 | } | ||
113 | #define LUA_LOADED_TABLE "_LOADED" // // doesn't exist in Lua 5.2 | 97 | #define LUA_LOADED_TABLE "_LOADED" // // doesn't exist in Lua 5.2 |
114 | 98 | ||
115 | #endif // LUA_VERSION_NUM == 502 | 99 | #endif // LUA_VERSION_NUM == 502 |
@@ -121,7 +105,7 @@ inline int lua504_dump(lua_State* L_, lua_Writer writer_, void* data_, [[maybe_u | |||
121 | // starting with Lua 5.3, lua_getfield returns the type of the value it found | 105 | // starting with Lua 5.3, lua_getfield returns the type of the value it found |
122 | #if LUA_VERSION_NUM < 503 | 106 | #if LUA_VERSION_NUM < 503 |
123 | lua_getfield(L_, idx_, k_.data()); | 107 | lua_getfield(L_, idx_, k_.data()); |
124 | return lua_type_as_enum(L_, -1); | 108 | return luaG_type(L_, -1); |
125 | #else // LUA_VERSION_NUM >= 503 | 109 | #else // LUA_VERSION_NUM >= 503 |
126 | return static_cast<LuaType>(lua_getfield(L_, idx_, k_.data())); | 110 | return static_cast<LuaType>(lua_getfield(L_, idx_, k_.data())); |
127 | #endif // LUA_VERSION_NUM >= 503 | 111 | #endif // LUA_VERSION_NUM >= 503 |
@@ -132,14 +116,6 @@ inline int lua504_dump(lua_State* L_, lua_Writer writer_, void* data_, [[maybe_u | |||
132 | // wrap Lua 5.3 calls under Lua 5.1 API when it is simpler that way | 116 | // wrap Lua 5.3 calls under Lua 5.1 API when it is simpler that way |
133 | #if LUA_VERSION_NUM == 503 | 117 | #if LUA_VERSION_NUM == 503 |
134 | 118 | ||
135 | inline void luaG_registerlibfuncs(lua_State* L_, luaL_Reg const funcs_[]) | ||
136 | { | ||
137 | luaL_setfuncs(L_, funcs_, 0); | ||
138 | } | ||
139 | inline int lua504_dump(lua_State* L_, lua_Writer writer_, void* data_, int strip_) | ||
140 | { | ||
141 | return lua_dump(L_, writer_, data_, strip_); | ||
142 | } | ||
143 | inline int luaL_optint(lua_State* L_, int n_, lua_Integer d_) | 119 | inline int luaL_optint(lua_State* L_, int n_, lua_Integer d_) |
144 | { | 120 | { |
145 | return static_cast<int>(luaL_optinteger(L_, n_, d_)); | 121 | return static_cast<int>(luaL_optinteger(L_, n_, d_)); |
@@ -164,14 +140,6 @@ int lua_setiuservalue(lua_State* L_, int idx_, int n_); | |||
164 | // wrap Lua 5.4 calls under Lua 5.1 API when it is simpler that way | 140 | // wrap Lua 5.4 calls under Lua 5.1 API when it is simpler that way |
165 | #if LUA_VERSION_NUM == 504 | 141 | #if LUA_VERSION_NUM == 504 |
166 | 142 | ||
167 | inline void luaG_registerlibfuncs(lua_State* L_, luaL_Reg const funcs_[]) | ||
168 | { | ||
169 | luaL_setfuncs(L_, funcs_, 0); | ||
170 | } | ||
171 | inline int lua504_dump(lua_State* L_, lua_Writer writer_, void* data_, int strip_) | ||
172 | { | ||
173 | return lua_dump(L_, writer_, data_, strip_); | ||
174 | } | ||
175 | inline int luaL_optint(lua_State* L_, int n_, lua_Integer d_) | 143 | inline int luaL_optint(lua_State* L_, int n_, lua_Integer d_) |
176 | { | 144 | { |
177 | return static_cast<int>(luaL_optinteger(L_, n_, d_)); | 145 | return static_cast<int>(luaL_optinteger(L_, n_, d_)); |
@@ -182,14 +150,6 @@ inline int luaL_optint(lua_State* L_, int n_, lua_Integer d_) | |||
182 | 150 | ||
183 | // ################################################################################################# | 151 | // ################################################################################################# |
184 | 152 | ||
185 | // use this in place of lua_absindex to save a function call | ||
186 | inline int luaG_absindex(lua_State* L_, int idx_) | ||
187 | { | ||
188 | return (((idx_) >= 0 || (idx_) <= LUA_REGISTRYINDEX) ? (idx_) : lua_gettop(L_) + (idx_) + 1); | ||
189 | } | ||
190 | |||
191 | // ################################################################################################# | ||
192 | |||
193 | // a strong-typed wrapper over lua error codes to see them easier in a debugger | 153 | // a strong-typed wrapper over lua error codes to see them easier in a debugger |
194 | enum class LuaError | 154 | enum class LuaError |
195 | { | 155 | { |
@@ -211,28 +171,117 @@ inline constexpr LuaError ToLuaError(int rc_) | |||
211 | 171 | ||
212 | // ################################################################################################# | 172 | // ################################################################################################# |
213 | 173 | ||
174 | // Default matches Lua 5.4 as of now | ||
175 | template <int VERSION, typename SPECIALIZE = void> | ||
176 | struct Wrap | ||
177 | { | ||
178 | static inline int lua_dump(lua_State* const L_, lua_Writer const writer_, void* const data_, int const strip_) | ||
179 | { | ||
180 | return ::lua_dump(L_, writer_, data_, strip_); | ||
181 | } | ||
182 | |||
183 | static void luaL_setfuncs(lua_State* const L_, luaL_Reg const funcs_[], int nup_) | ||
184 | { | ||
185 | ::luaL_setfuncs(L_, funcs_, nup_); | ||
186 | } | ||
187 | }; | ||
188 | |||
189 | // ################################################################################################# | ||
190 | |||
191 | template <int VERSION> | ||
192 | struct Wrap<VERSION, typename std::enable_if<VERSION == 503>::type> | ||
193 | { | ||
194 | static inline int lua_dump(lua_State* L_, lua_Writer writer_, void* data_, int strip_) | ||
195 | { | ||
196 | return ::lua_dump(L_, writer_, data_, strip_); | ||
197 | } | ||
198 | |||
199 | static void luaL_setfuncs(lua_State* const L_, luaL_Reg const funcs_[], int const nup_) | ||
200 | { | ||
201 | ::luaL_setfuncs(L_, funcs_, nup_); | ||
202 | } | ||
203 | }; | ||
204 | |||
205 | // ################################################################################################# | ||
206 | |||
207 | template <int VERSION> | ||
208 | struct Wrap<VERSION, typename std::enable_if<VERSION == 502>::type> | ||
209 | { | ||
210 | static inline int lua_dump(lua_State* const L_, lua_Writer const writer_, void* const data_, [[maybe_unused]] int const strip_) | ||
211 | { | ||
212 | return ::lua_dump(L_, writer_, data_); | ||
213 | } | ||
214 | |||
215 | static void luaL_setfuncs(lua_State* const L_, luaL_Reg const funcs_[], int const nup_) | ||
216 | { | ||
217 | ::luaL_setfuncs(L_, funcs_, nup_); | ||
218 | } | ||
219 | }; | ||
220 | |||
221 | // ################################################################################################# | ||
222 | |||
223 | template <int VERSION> | ||
224 | struct Wrap<VERSION, typename std::enable_if<VERSION == 501>::type> | ||
225 | { | ||
226 | static inline int lua_dump(lua_State* const L_, lua_Writer const writer_, void* const data_, [[maybe_unused]] int const strip_) | ||
227 | { | ||
228 | return ::lua_dump(L_, writer_, data_); | ||
229 | } | ||
230 | |||
231 | static void luaL_setfuncs(lua_State* const L_, luaL_Reg const funcs_[], [[maybe_unused]] int const nup_) | ||
232 | { | ||
233 | ::luaL_register(L_, nullptr, funcs_); | ||
234 | } | ||
235 | }; | ||
236 | |||
237 | // ################################################################################################# | ||
238 | // All the compatibility wrappers we expose start with luaG_ | ||
239 | |||
240 | // use this in place of lua_absindex to save a function call | ||
241 | inline int luaG_absindex(lua_State* L_, int idx_) | ||
242 | { | ||
243 | return (((idx_) >= 0 || (idx_) <= LUA_REGISTRYINDEX) ? (idx_) : lua_gettop(L_) + (idx_) + 1); | ||
244 | } | ||
245 | |||
246 | // ------------------------------------------------------------------------------------------------- | ||
247 | |||
248 | inline int luaG_dump(lua_State* L_, lua_Writer writer_, void* data_, int strip_) | ||
249 | { | ||
250 | return Wrap<LUA_VERSION_NUM>::lua_dump(L_, writer_, data_, strip_); | ||
251 | } | ||
252 | |||
253 | // ------------------------------------------------------------------------------------------------- | ||
254 | |||
214 | LuaType luaG_getmodule(lua_State* L_, std::string_view const& name_); | 255 | LuaType luaG_getmodule(lua_State* L_, std::string_view const& name_); |
215 | 256 | ||
257 | // ------------------------------------------------------------------------------------------------- | ||
258 | |||
259 | inline void luaG_registerlibfuncs(lua_State* L_, luaL_Reg const funcs_[]) | ||
260 | { | ||
261 | Wrap<LUA_VERSION_NUM>::luaL_setfuncs(L_, funcs_, 0); | ||
262 | } | ||
263 | |||
216 | // ################################################################################################# | 264 | // ################################################################################################# |
217 | 265 | ||
266 | // must keep as a macro as long as we do constant string concatenations | ||
218 | #define STRINGVIEW_FMT "%.*s" | 267 | #define STRINGVIEW_FMT "%.*s" |
219 | 268 | ||
220 | // a replacement of lua_tolstring | 269 | // a replacement of lua_tolstring |
221 | [[nodiscard]] inline std::string_view lua_tostringview(lua_State* L_, int idx_) | 270 | [[nodiscard]] inline std::string_view luaG_tostringview(lua_State* L_, int idx_) |
222 | { | 271 | { |
223 | size_t _len{ 0 }; | 272 | size_t _len{ 0 }; |
224 | char const* _str{ lua_tolstring(L_, idx_, &_len) }; | 273 | char const* _str{ lua_tolstring(L_, idx_, &_len) }; |
225 | return std::string_view{ _str, _len }; | 274 | return std::string_view{ _str, _len }; |
226 | } | 275 | } |
227 | 276 | ||
228 | [[nodiscard]] inline std::string_view luaL_checkstringview(lua_State* L_, int idx_) | 277 | [[nodiscard]] inline std::string_view luaG_checkstringview(lua_State* L_, int idx_) |
229 | { | 278 | { |
230 | size_t _len{ 0 }; | 279 | size_t _len{ 0 }; |
231 | char const* _str{ luaL_checklstring(L_, idx_, &_len) }; | 280 | char const* _str{ luaL_checklstring(L_, idx_, &_len) }; |
232 | return std::string_view{ _str, _len }; | 281 | return std::string_view{ _str, _len }; |
233 | } | 282 | } |
234 | 283 | ||
235 | [[nodiscard]] inline std::string_view luaL_optstringview(lua_State* L_, int idx_, std::string_view const& default_) | 284 | [[nodiscard]] inline std::string_view luaG_optstringview(lua_State* L_, int idx_, std::string_view const& default_) |
236 | { | 285 | { |
237 | if (lua_isnoneornil(L_, idx_)) { | 286 | if (lua_isnoneornil(L_, idx_)) { |
238 | return default_; | 287 | return default_; |
@@ -242,12 +291,12 @@ LuaType luaG_getmodule(lua_State* L_, std::string_view const& name_); | |||
242 | return std::string_view{ _str, _len }; | 291 | return std::string_view{ _str, _len }; |
243 | } | 292 | } |
244 | 293 | ||
245 | [[nodiscard]] inline std::string_view lua_pushstringview(lua_State* L_, std::string_view const& str_) | 294 | [[nodiscard]] inline std::string_view luaG_pushstringview(lua_State* L_, std::string_view const& str_) |
246 | { | 295 | { |
247 | #if LUA_VERSION_NUM == 501 | 296 | #if LUA_VERSION_NUM == 501 |
248 | // lua_pushlstring doesn't return a value in Lua 5.1 | 297 | // lua_pushlstring doesn't return a value in Lua 5.1 |
249 | lua_pushlstring(L_, str_.data(), str_.size()); | 298 | lua_pushlstring(L_, str_.data(), str_.size()); |
250 | return lua_tostringview(L_, -1); | 299 | return luaG_tostringview(L_, -1); |
251 | #else | 300 | #else |
252 | return std::string_view{ lua_pushlstring(L_, str_.data(), str_.size()), str_.size() }; | 301 | return std::string_view{ lua_pushlstring(L_, str_.data(), str_.size()), str_.size() }; |
253 | #endif // LUA_VERSION_NUM > 501 | 302 | #endif // LUA_VERSION_NUM > 501 |
diff --git a/src/deep.cpp b/src/deep.cpp index 76397ae..97442cf 100644 --- a/src/deep.cpp +++ b/src/deep.cpp | |||
@@ -240,7 +240,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
240 | raise_luaL_error(errL_, "lanes receiving deep userdata should register the 'package' library"); | 240 | raise_luaL_error(errL_, "lanes receiving deep userdata should register the 'package' library"); |
241 | } | 241 | } |
242 | 242 | ||
243 | std::ignore = lua_pushstringview(L_, _modname); // L_: DPC proxy metatable require() "module" | 243 | std::ignore = luaG_pushstringview(L_, _modname); // L_: DPC proxy metatable require() "module" |
244 | if (luaG_getfield(L_, LUA_REGISTRYINDEX, LUA_LOADED_TABLE) != LuaType::TABLE) { // L_: DPC proxy metatable require() "module" _R._LOADED | 244 | if (luaG_getfield(L_, LUA_REGISTRYINDEX, LUA_LOADED_TABLE) != LuaType::TABLE) { // L_: DPC proxy metatable require() "module" _R._LOADED |
245 | // no L.registry._LOADED; can this ever happen? | 245 | // no L.registry._LOADED; can this ever happen? |
246 | lua_pop(L_, 6); // L_: | 246 | lua_pop(L_, 6); // L_: |
@@ -259,7 +259,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
259 | LuaError const _require_result{ lua_pcall(L_, 1, 0, 0) }; // L_: DPC proxy metatable error? | 259 | LuaError const _require_result{ lua_pcall(L_, 1, 0, 0) }; // L_: DPC proxy metatable error? |
260 | if (_require_result != LuaError::OK) { | 260 | if (_require_result != LuaError::OK) { |
261 | // failed, raise the error in the proper state | 261 | // failed, raise the error in the proper state |
262 | std::ignore = lua_pushstringview(errL_, lua_tostringview(L_, -1)); | 262 | std::ignore = luaG_pushstringview(errL_, luaG_tostringview(L_, -1)); |
263 | raise_lua_error(errL_); | 263 | raise_lua_error(errL_); |
264 | } | 264 | } |
265 | } | 265 | } |
@@ -269,7 +269,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
269 | } | 269 | } |
270 | } | 270 | } |
271 | STACK_CHECK(L_, 3); // L_: DPC proxy metatable | 271 | STACK_CHECK(L_, 3); // L_: DPC proxy metatable |
272 | LUA_ASSERT(L_, lua_type_as_enum(L_, -2) == LuaType::USERDATA); | 272 | LUA_ASSERT(L_, luaG_type(L_, -2) == LuaType::USERDATA); |
273 | LUA_ASSERT(L_, lua_istable(L_, -1)); | 273 | LUA_ASSERT(L_, lua_istable(L_, -1)); |
274 | lua_setmetatable(L_, -2); // L_: DPC proxy | 274 | lua_setmetatable(L_, -2); // L_: DPC proxy |
275 | 275 | ||
@@ -278,7 +278,7 @@ void DeepFactory::PushDeepProxy(DestState const L_, DeepPrelude* const prelude_, | |||
278 | lua_pushvalue(L_, -2); // L_: DPC proxy deep proxy | 278 | lua_pushvalue(L_, -2); // L_: DPC proxy deep proxy |
279 | lua_rawset(L_, -4); // L_: DPC proxy | 279 | lua_rawset(L_, -4); // L_: DPC proxy |
280 | lua_remove(L_, -2); // L_: proxy | 280 | lua_remove(L_, -2); // L_: proxy |
281 | LUA_ASSERT(L_, lua_type_as_enum(L_, -1) == LuaType::USERDATA); | 281 | LUA_ASSERT(L_, luaG_type(L_, -1) == LuaType::USERDATA); |
282 | STACK_CHECK(L_, 1); | 282 | STACK_CHECK(L_, 1); |
283 | } | 283 | } |
284 | 284 | ||
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index 670b955..aa802d5 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp | |||
@@ -100,7 +100,7 @@ THE SOFTWARE. | |||
100 | lua_pushvalue(L1, L1_i); // L1: ... v ... {} v | 100 | lua_pushvalue(L1, L1_i); // L1: ... v ... {} v |
101 | lua_rawget(L1, -2); // L1: ... v ... {} "f.q.n" | 101 | lua_rawget(L1, -2); // L1: ... v ... {} "f.q.n" |
102 | } | 102 | } |
103 | std::string_view _fqn{ lua_tostringview(L1, -1) }; | 103 | std::string_view _fqn{ luaG_tostringview(L1, -1) }; |
104 | DEBUGSPEW_CODE(DebugSpew(Universe::Get(L1)) << "function [C] " << _fqn << std::endl); | 104 | DEBUGSPEW_CODE(DebugSpew(Universe::Get(L1)) << "function [C] " << _fqn << std::endl); |
105 | // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database | 105 | // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database |
106 | lua_pop(L1, (mode == LookupMode::FromKeeper) ? 1 : 2); // L1: ... v ... | 106 | lua_pop(L1, (mode == LookupMode::FromKeeper) ? 1 : 2); // L1: ... v ... |
@@ -113,7 +113,7 @@ THE SOFTWARE. | |||
113 | lua_pushcfunction(L1, LG_nameof); // L1: ... v ... lane_name LG_nameof | 113 | lua_pushcfunction(L1, LG_nameof); // L1: ... v ... lane_name LG_nameof |
114 | lua_pushvalue(L1, L1_i); // L1: ... v ... lane_name LG_nameof t | 114 | lua_pushvalue(L1, L1_i); // L1: ... v ... lane_name LG_nameof t |
115 | lua_call(L1, 1, 2); // L1: ... v ... lane_name "type" "name"|nil | 115 | lua_call(L1, 1, 2); // L1: ... v ... lane_name "type" "name"|nil |
116 | char const* _typewhat{ (lua_type(L1, -2) == LUA_TSTRING) ? lua_tostring(L1, -2) : luaL_typename(L1, -2) }; | 116 | char const* _typewhat{ (luaG_type(L1, -2) == LuaType::STRING) ? lua_tostring(L1, -2) : luaL_typename(L1, -2) }; |
117 | // second return value can be nil if the table was not found | 117 | // second return value can be nil if the table was not found |
118 | // probable reason: the function was removed from the source Lua state before Lanes was required. | 118 | // probable reason: the function was removed from the source Lua state before Lanes was required. |
119 | char const *_what, *_gotchaA, *_gotchaB; | 119 | char const *_what, *_gotchaA, *_gotchaB; |
@@ -124,7 +124,7 @@ THE SOFTWARE. | |||
124 | } else { | 124 | } else { |
125 | _gotchaA = ""; | 125 | _gotchaA = ""; |
126 | _gotchaB = ""; | 126 | _gotchaB = ""; |
127 | _what = (lua_type(L1, -1) == LUA_TSTRING) ? lua_tostring(L1, -1) : luaL_typename(L1, -1); | 127 | _what = (luaG_type(L1, -1) == LuaType::STRING) ? lua_tostring(L1, -1) : luaL_typename(L1, -1); |
128 | } | 128 | } |
129 | raise_luaL_error(L1, "%s%s '%s' not found in %s origin transfer database.%s", _typewhat, _gotchaA, _what, _from ? _from : "main", _gotchaB); | 129 | raise_luaL_error(L1, "%s%s '%s' not found in %s origin transfer database.%s", _typewhat, _gotchaA, _what, _from ? _from : "main", _gotchaB); |
130 | } | 130 | } |
@@ -196,7 +196,7 @@ void InterCopyContext::copy_func() const | |||
196 | // not sure this could ever fail but for memory shortage reasons | 196 | // not sure this could ever fail but for memory shortage reasons |
197 | // last parameter is Lua 5.4-specific (no stripping) | 197 | // last parameter is Lua 5.4-specific (no stripping) |
198 | luaL_Buffer B{}; | 198 | luaL_Buffer B{}; |
199 | if (lua504_dump(L1, buf_writer, &B, U->stripFunctions) != 0) { | 199 | if (luaG_dump(L1, buf_writer, &B, U->stripFunctions) != 0) { |
200 | raise_luaL_error(getErrL(), "internal error: function dump failed."); | 200 | raise_luaL_error(getErrL(), "internal error: function dump failed."); |
201 | } | 201 | } |
202 | 202 | ||
@@ -224,7 +224,7 @@ void InterCopyContext::copy_func() const | |||
224 | } | 224 | } |
225 | 225 | ||
226 | { | 226 | { |
227 | std::string_view const _bytecode{ lua_tostringview(L1, -1) }; // L1: ... b | 227 | std::string_view const _bytecode{ luaG_tostringview(L1, -1) }; // L1: ... b |
228 | LUA_ASSERT(L1, !_bytecode.empty()); | 228 | LUA_ASSERT(L1, !_bytecode.empty()); |
229 | STACK_GROW(L2, 2); | 229 | STACK_GROW(L2, 2); |
230 | // Note: Line numbers seem to be taken precisely from the | 230 | // Note: Line numbers seem to be taken precisely from the |
@@ -313,7 +313,7 @@ void InterCopyContext::lookup_native_func() const | |||
313 | 313 | ||
314 | case LookupMode::ToKeeper: | 314 | case LookupMode::ToKeeper: |
315 | // push a sentinel closure that holds the lookup name as upvalue | 315 | // push a sentinel closure that holds the lookup name as upvalue |
316 | std::ignore = lua_pushstringview(L2, _fqn); // L1: ... f ... L2: "f.q.n" | 316 | std::ignore = luaG_pushstringview(L2, _fqn); // L1: ... f ... L2: "f.q.n" |
317 | lua_pushcclosure(L2, func_lookup_sentinel, 1); // L1: ... f ... L2: f | 317 | lua_pushcclosure(L2, func_lookup_sentinel, 1); // L1: ... f ... L2: f |
318 | break; | 318 | break; |
319 | 319 | ||
@@ -322,7 +322,7 @@ void InterCopyContext::lookup_native_func() const | |||
322 | kLookupRegKey.pushValue(L2); // L1: ... f ... L2: {} | 322 | kLookupRegKey.pushValue(L2); // L1: ... f ... L2: {} |
323 | STACK_CHECK(L2, 1); | 323 | STACK_CHECK(L2, 1); |
324 | LUA_ASSERT(L1, lua_istable(L2, -1)); | 324 | LUA_ASSERT(L1, lua_istable(L2, -1)); |
325 | std::ignore = lua_pushstringview(L2, _fqn); // L1: ... f ... L2: {} "f.q.n" | 325 | std::ignore = luaG_pushstringview(L2, _fqn); // L1: ... f ... L2: {} "f.q.n" |
326 | lua_rawget(L2, -2); // L1: ... f ... L2: {} f | 326 | lua_rawget(L2, -2); // L1: ... f ... L2: {} f |
327 | // nil means we don't know how to transfer stuff: user should do something | 327 | // nil means we don't know how to transfer stuff: user should do something |
328 | // anything other than function or table should not happen! | 328 | // anything other than function or table should not happen! |
@@ -388,7 +388,7 @@ void InterCopyContext::copy_cached_func() const | |||
388 | // push a light userdata uniquely representing the function | 388 | // push a light userdata uniquely representing the function |
389 | lua_pushlightuserdata(L2, _aspointer); // L2: ... {cache} ... p | 389 | lua_pushlightuserdata(L2, _aspointer); // L2: ... {cache} ... p |
390 | 390 | ||
391 | //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << lua_tostringview(L2, -1) << " >>" << std::endl); | 391 | //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaG_tostringview(L2, -1) << " >>" << std::endl); |
392 | 392 | ||
393 | lua_pushvalue(L2, -1); // L2: ... {cache} ... p p | 393 | lua_pushvalue(L2, -1); // L2: ... {cache} ... p p |
394 | lua_rawget(L2, L2_cache_i); // L2: ... {cache} ... p function|nil|true | 394 | lua_rawget(L2, L2_cache_i); // L2: ... {cache} ... p function|nil|true |
@@ -433,7 +433,7 @@ void InterCopyContext::copy_cached_func() const | |||
433 | 433 | ||
434 | case LookupMode::ToKeeper: | 434 | case LookupMode::ToKeeper: |
435 | // push a sentinel closure that holds the lookup name as upvalue | 435 | // push a sentinel closure that holds the lookup name as upvalue |
436 | std::ignore = lua_pushstringview(L2, _fqn); // L1: ... t ... L2: "f.q.n" | 436 | std::ignore = luaG_pushstringview(L2, _fqn); // L1: ... t ... L2: "f.q.n" |
437 | lua_pushcclosure(L2, table_lookup_sentinel, 1); // L1: ... t ... L2: f | 437 | lua_pushcclosure(L2, table_lookup_sentinel, 1); // L1: ... t ... L2: f |
438 | break; | 438 | break; |
439 | 439 | ||
@@ -442,7 +442,7 @@ void InterCopyContext::copy_cached_func() const | |||
442 | kLookupRegKey.pushValue(L2); // L1: ... t ... L2: {} | 442 | kLookupRegKey.pushValue(L2); // L1: ... t ... L2: {} |
443 | STACK_CHECK(L2, 1); | 443 | STACK_CHECK(L2, 1); |
444 | LUA_ASSERT(L1, lua_istable(L2, -1)); | 444 | LUA_ASSERT(L1, lua_istable(L2, -1)); |
445 | std::ignore = lua_pushstringview(L2, _fqn); // L2: {} "f.q.n" | 445 | std::ignore = luaG_pushstringview(L2, _fqn); // L2: {} "f.q.n" |
446 | lua_rawget(L2, -2); // L2: {} t | 446 | lua_rawget(L2, -2); // L2: {} t |
447 | // we accept destination lookup failures in the case of transfering the Lanes body function (this will result in the source table being cloned instead) | 447 | // we accept destination lookup failures in the case of transfering the Lanes body function (this will result in the source table being cloned instead) |
448 | // but not when we extract something out of a keeper, as there is nothing to clone! | 448 | // but not when we extract something out of a keeper, as there is nothing to clone! |
@@ -462,7 +462,7 @@ void InterCopyContext::copy_cached_func() const | |||
462 | "%s: source table '%s' found as %s in %s destination transfer database.", | 462 | "%s: source table '%s' found as %s in %s destination transfer database.", |
463 | _from ? _from : "main", | 463 | _from ? _from : "main", |
464 | _fqn, | 464 | _fqn, |
465 | lua_typename(L2, lua_type_as_enum(L2, -1)), | 465 | luaG_typename(L2, luaG_type(L2, -1)), |
466 | _to ? _to : "main"); | 466 | _to ? _to : "main"); |
467 | } | 467 | } |
468 | lua_remove(L2, -2); // L1: ... t ... L2: t | 468 | lua_remove(L2, -2); // L1: ... t ... L2: t |
@@ -491,8 +491,8 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
491 | char* _valPath{ nullptr }; | 491 | char* _valPath{ nullptr }; |
492 | if (U->verboseErrors) { | 492 | if (U->verboseErrors) { |
493 | // for debug purposes, let's try to build a useful name | 493 | // for debug purposes, let's try to build a useful name |
494 | if (lua_type(L1, _key_i) == LUA_TSTRING) { | 494 | if (luaG_type(L1, _key_i) == LuaType::STRING) { |
495 | std::string_view const _key{ lua_tostringview(L1, _key_i) }; | 495 | std::string_view const _key{ luaG_tostringview(L1, _key_i) }; |
496 | size_t const _bufLen{ strlen(name) + _key.size() + 2 }; // +2 for separator dot and terminating 0 | 496 | size_t const _bufLen{ strlen(name) + _key.size() + 2 }; // +2 for separator dot and terminating 0 |
497 | _valPath = static_cast<char*>(alloca(_bufLen)); | 497 | _valPath = static_cast<char*>(alloca(_bufLen)); |
498 | sprintf(_valPath, "%s." STRINGVIEW_FMT, name, (int) _key.size(), _key.data()); | 498 | sprintf(_valPath, "%s." STRINGVIEW_FMT, name, (int) _key.size(), _key.data()); |
@@ -504,15 +504,15 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
504 | sprintf(_valPath, "%s[" LUA_INTEGER_FMT "]", name, key); | 504 | sprintf(_valPath, "%s[" LUA_INTEGER_FMT "]", name, key); |
505 | } | 505 | } |
506 | #endif // defined LUA_LNUM || LUA_VERSION_NUM >= 503 | 506 | #endif // defined LUA_LNUM || LUA_VERSION_NUM >= 503 |
507 | else if (lua_type(L1, _key_i) == LUA_TNUMBER) { | 507 | else if (luaG_type(L1, _key_i) == LuaType::NUMBER) { |
508 | lua_Number const key{ lua_tonumber(L1, _key_i) }; | 508 | lua_Number const key{ lua_tonumber(L1, _key_i) }; |
509 | _valPath = (char*) alloca(strlen(name) + 32 + 3); // +3 for [] and terminating 0 | 509 | _valPath = (char*) alloca(strlen(name) + 32 + 3); // +3 for [] and terminating 0 |
510 | sprintf(_valPath, "%s[" LUA_NUMBER_FMT "]", name, key); | 510 | sprintf(_valPath, "%s[" LUA_NUMBER_FMT "]", name, key); |
511 | } else if (lua_type(L1, _key_i) == LUA_TLIGHTUSERDATA) { | 511 | } else if (luaG_type(L1, _key_i) == LuaType::LIGHTUSERDATA) { |
512 | void* const key{ lua_touserdata(L1, _key_i) }; | 512 | void* const key{ lua_touserdata(L1, _key_i) }; |
513 | _valPath = (char*) alloca(strlen(name) + 16 + 5); // +5 for [U:] and terminating 0 | 513 | _valPath = (char*) alloca(strlen(name) + 16 + 5); // +5 for [U:] and terminating 0 |
514 | sprintf(_valPath, "%s[U:%p]", name, key); | 514 | sprintf(_valPath, "%s[U:%p]", name, key); |
515 | } else if (lua_type(L1, _key_i) == LUA_TBOOLEAN) { | 515 | } else if (luaG_type(L1, _key_i) == LuaType::BOOLEAN) { |
516 | int const key{ lua_toboolean(L1, _key_i) }; | 516 | int const key{ lua_toboolean(L1, _key_i) }; |
517 | _valPath = (char*) alloca(strlen(name) + 8); // +8 for [], 'false' and terminating 0 | 517 | _valPath = (char*) alloca(strlen(name) + 8); // +8 for [], 'false' and terminating 0 |
518 | sprintf(_valPath, "%s[%s]", name, key ? "true" : "false"); | 518 | sprintf(_valPath, "%s[%s]", name, key ? "true" : "false"); |
@@ -597,7 +597,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
597 | // push a light userdata uniquely representing the table | 597 | // push a light userdata uniquely representing the table |
598 | lua_pushlightuserdata(L2, const_cast<void*>(_p)); // L1: ... t ... L2: ... p | 598 | lua_pushlightuserdata(L2, const_cast<void*>(_p)); // L1: ... t ... L2: ... p |
599 | 599 | ||
600 | //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << lua_tostringview(L2, -1) << " >>" << std::endl); | 600 | //DEBUGSPEW_CODE(DebugSpew(U) << "<< ID: " << luaG_tostringview(L2, -1) << " >>" << std::endl); |
601 | 601 | ||
602 | lua_rawget(L2, L2_cache_i); // L1: ... t ... L2: ... {cached|nil} | 602 | lua_rawget(L2, L2_cache_i); // L1: ... t ... L2: ... {cached|nil} |
603 | bool const _not_found_in_cache{ lua_isnil(L2, -1) }; | 603 | bool const _not_found_in_cache{ lua_isnil(L2, -1) }; |
@@ -940,9 +940,9 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
940 | 940 | ||
941 | [[nodiscard]] bool InterCopyContext::inter_copy_string() const | 941 | [[nodiscard]] bool InterCopyContext::inter_copy_string() const |
942 | { | 942 | { |
943 | std::string_view const _s{ lua_tostringview(L1, L1_i) }; | 943 | std::string_view const _s{ luaG_tostringview(L1, L1_i) }; |
944 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "'" << _s << "'" << std::endl); | 944 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "'" << _s << "'" << std::endl); |
945 | std::ignore = lua_pushstringview(L2, _s); | 945 | std::ignore = luaG_pushstringview(L2, _s); |
946 | return true; | 946 | return true; |
947 | } | 947 | } |
948 | 948 | ||
@@ -1094,7 +1094,7 @@ namespace { | |||
1094 | DEBUGSPEW_CODE(DebugSpew(U) << "inter_copy_one()" << std::endl); | 1094 | DEBUGSPEW_CODE(DebugSpew(U) << "inter_copy_one()" << std::endl); |
1095 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); | 1095 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); |
1096 | 1096 | ||
1097 | LuaType _val_type{ lua_type_as_enum(L1, L1_i) }; | 1097 | LuaType _val_type{ luaG_type(L1, L1_i) }; |
1098 | DEBUGSPEW_CODE(DebugSpew(U) << local::sLuaTypeNames[static_cast<int>(_val_type)] << " " << local::sValueTypeNames[static_cast<int>(vt)] << ": "); | 1098 | DEBUGSPEW_CODE(DebugSpew(U) << local::sLuaTypeNames[static_cast<int>(_val_type)] << " " << local::sValueTypeNames[static_cast<int>(vt)] << ": "); |
1099 | 1099 | ||
1100 | // Non-POD can be skipped if its metatable contains { __lanesignore = true } | 1100 | // Non-POD can be skipped if its metatable contains { __lanesignore = true } |
@@ -1187,7 +1187,7 @@ namespace { | |||
1187 | } const _onExit{ L2 }; | 1187 | } const _onExit{ L2 }; |
1188 | 1188 | ||
1189 | STACK_CHECK_START_REL(L1, 0); | 1189 | STACK_CHECK_START_REL(L1, 0); |
1190 | if (lua_type_as_enum(L1, L1_i) != LuaType::TABLE) { | 1190 | if (luaG_type(L1, L1_i) != LuaType::TABLE) { |
1191 | lua_pushfstring(L1, "expected package as table, got %s", luaL_typename(L1, L1_i)); | 1191 | lua_pushfstring(L1, "expected package as table, got %s", luaL_typename(L1, L1_i)); |
1192 | STACK_CHECK(L1, 1); | 1192 | STACK_CHECK(L1, 1); |
1193 | // raise the error when copying from lane to lane, else just leave it on the stack to be raised later | 1193 | // raise the error when copying from lane to lane, else just leave it on the stack to be raised later |
diff --git a/src/lane.cpp b/src/lane.cpp index f07403f..2a2030d 100644 --- a/src/lane.cpp +++ b/src/lane.cpp | |||
@@ -46,7 +46,7 @@ static LUAG_FUNC(get_debug_threadname) | |||
46 | { | 46 | { |
47 | Lane* const _lane{ ToLane(L_, 1) }; | 47 | Lane* const _lane{ ToLane(L_, 1) }; |
48 | luaL_argcheck(L_, lua_gettop(L_) == 1, 2, "too many arguments"); | 48 | luaL_argcheck(L_, lua_gettop(L_) == 1, 2, "too many arguments"); |
49 | std::ignore = lua_pushstringview(L_, _lane->debugName); | 49 | std::ignore = luaG_pushstringview(L_, _lane->debugName); |
50 | return 1; | 50 | return 1; |
51 | } | 51 | } |
52 | 52 | ||
@@ -104,7 +104,7 @@ static LUAG_FUNC(thread_join) | |||
104 | Lane* const _lane{ ToLane(L_, 1) }; | 104 | Lane* const _lane{ ToLane(L_, 1) }; |
105 | 105 | ||
106 | std::chrono::time_point<std::chrono::steady_clock> _until{ std::chrono::time_point<std::chrono::steady_clock>::max() }; | 106 | std::chrono::time_point<std::chrono::steady_clock> _until{ std::chrono::time_point<std::chrono::steady_clock>::max() }; |
107 | if (lua_type(L_, 2) == LUA_TNUMBER) { // we don't want to use lua_isnumber() because of autocoercion | 107 | if (luaG_type(L_, 2) == LuaType::NUMBER) { // we don't want to use lua_isnumber() because of autocoercion |
108 | lua_Duration const duration{ lua_tonumber(L_, 2) }; | 108 | lua_Duration const duration{ lua_tonumber(L_, 2) }; |
109 | if (duration.count() >= 0.0) { | 109 | if (duration.count() >= 0.0) { |
110 | _until = std::chrono::steady_clock::now() + std::chrono::duration_cast<std::chrono::steady_clock::duration>(duration); | 110 | _until = std::chrono::steady_clock::now() + std::chrono::duration_cast<std::chrono::steady_clock::duration>(duration); |
@@ -300,7 +300,7 @@ static int thread_index_string(lua_State* L_) | |||
300 | Lane* const _lane{ ToLane(L_, kSelf) }; | 300 | Lane* const _lane{ ToLane(L_, kSelf) }; |
301 | LUA_ASSERT(L_, lua_gettop(L_) == 2); // L_: lane "key" | 301 | LUA_ASSERT(L_, lua_gettop(L_) == 2); // L_: lane "key" |
302 | 302 | ||
303 | std::string_view const _keystr{ lua_tostringview(L_, kKey) }; | 303 | std::string_view const _keystr{ luaG_tostringview(L_, kKey) }; |
304 | lua_settop(L_, 2); // keep only our original arguments on the stack | 304 | lua_settop(L_, 2); // keep only our original arguments on the stack |
305 | if (_keystr == "status") { | 305 | if (_keystr == "status") { |
306 | std::ignore = _lane->pushThreadStatus(L_); // L_: lane "key" "<status>" | 306 | std::ignore = _lane->pushThreadStatus(L_); // L_: lane "key" "<status>" |
@@ -331,11 +331,11 @@ static LUAG_FUNC(thread_index) | |||
331 | Lane* const _lane{ ToLane(L_, kSelf) }; | 331 | Lane* const _lane{ ToLane(L_, kSelf) }; |
332 | LUA_ASSERT(L_, lua_gettop(L_) == 2); | 332 | LUA_ASSERT(L_, lua_gettop(L_) == 2); |
333 | 333 | ||
334 | switch (lua_type(L_, kKey)) { | 334 | switch (luaG_type(L_, kKey)) { |
335 | case LUA_TNUMBER: | 335 | case LuaType::NUMBER: |
336 | return thread_index_number(L_); // stack modification is undefined, returned value is at the top | 336 | return thread_index_number(L_); // stack modification is undefined, returned value is at the top |
337 | 337 | ||
338 | case LUA_TSTRING: | 338 | case LuaType::STRING: |
339 | return thread_index_string(L_); // stack modification is undefined, returned value is at the top | 339 | return thread_index_string(L_); // stack modification is undefined, returned value is at the top |
340 | 340 | ||
341 | default: // unknown key | 341 | default: // unknown key |
@@ -345,7 +345,7 @@ static LUAG_FUNC(thread_index) | |||
345 | lua_pushvalue(L_, kKey); // L_: mt error "Unknown key: " k | 345 | lua_pushvalue(L_, kKey); // L_: mt error "Unknown key: " k |
346 | lua_concat(L_, 2); // L_: mt error "Unknown key: <k>" | 346 | lua_concat(L_, 2); // L_: mt error "Unknown key: <k>" |
347 | lua_call(L_, 1, 0); // error( "Unknown key: " .. key) -> doesn't return // L_: mt | 347 | lua_call(L_, 1, 0); // error( "Unknown key: " .. key) -> doesn't return // L_: mt |
348 | raise_luaL_error(L_, "%s[%s]: should not get here!", _lane->debugName.data(), lua_typename(L_, lua_type(L_, kKey))); | 348 | raise_luaL_error(L_, "%s[%s]: should not get here!", _lane->debugName.data(), luaG_typename(L_, luaG_type(L_, kKey))); |
349 | } | 349 | } |
350 | } | 350 | } |
351 | 351 | ||
@@ -498,7 +498,7 @@ static void push_stack_trace(lua_State* L_, Lane::ErrorTraceLevel errorTraceLeve | |||
498 | 498 | ||
499 | // For cancellation the error message is kCancelError, and a stack trace isn't placed | 499 | // For cancellation the error message is kCancelError, and a stack trace isn't placed |
500 | // For other errors, the message can be whatever was thrown, and we should have a stack trace table | 500 | // For other errors, the message can be whatever was thrown, and we should have a stack trace table |
501 | LUA_ASSERT(L_, lua_type(L_, 1 + stk_base_) == (kCancelError.equals(L_, stk_base_) ? LUA_TNIL : LUA_TTABLE)); | 501 | LUA_ASSERT(L_, luaG_type(L_, 1 + stk_base_) == (kCancelError.equals(L_, stk_base_) ? LuaType::NIL : LuaType::TABLE)); |
502 | // Just leaving the stack trace table on the stack is enough to get it through to the master. | 502 | // Just leaving the stack trace table on the stack is enough to get it through to the master. |
503 | } else { | 503 | } else { |
504 | // any kind of error can be thrown with error(), or through a lane/linda cancellation | 504 | // any kind of error can be thrown with error(), or through a lane/linda cancellation |
@@ -510,7 +510,7 @@ static void push_stack_trace(lua_State* L_, Lane::ErrorTraceLevel errorTraceLeve | |||
510 | case LuaError::ERRERR: // error while running the error handler (if any, for example an out-of-memory condition) | 510 | case LuaError::ERRERR: // error while running the error handler (if any, for example an out-of-memory condition) |
511 | default: | 511 | default: |
512 | // the Lua core provides a string error message in those situations | 512 | // the Lua core provides a string error message in those situations |
513 | LUA_ASSERT(L_, (lua_gettop(L_) == stk_base_) && (lua_type(L_, stk_base_) == LUA_TSTRING)); | 513 | LUA_ASSERT(L_, (lua_gettop(L_) == stk_base_) && (luaG_type(L_, stk_base_) == LuaType::STRING)); |
514 | break; | 514 | break; |
515 | } | 515 | } |
516 | } | 516 | } |
@@ -551,7 +551,7 @@ static void push_stack_trace(lua_State* L_, Lane::ErrorTraceLevel errorTraceLeve | |||
551 | LUA_ASSERT(L_, lua_isfunction(L_, -1)); | 551 | LUA_ASSERT(L_, lua_isfunction(L_, -1)); |
552 | if (lua_rc_ != LuaError::OK) { // we have an error message and an optional stack trace at the bottom of the stack | 552 | if (lua_rc_ != LuaError::OK) { // we have an error message and an optional stack trace at the bottom of the stack |
553 | LUA_ASSERT(L_, _finalizers_index == 2 || _finalizers_index == 3); | 553 | LUA_ASSERT(L_, _finalizers_index == 2 || _finalizers_index == 3); |
554 | //std::string_view const _err_msg{ lua_tostringview(L_, 1) }; | 554 | //std::string_view const _err_msg{ luaG_tostringview(L_, 1) }; |
555 | lua_pushvalue(L_, 1); // L_: ... finalizers lane_error finalizer err_msg | 555 | lua_pushvalue(L_, 1); // L_: ... finalizers lane_error finalizer err_msg |
556 | // note we don't always have a stack trace for example when kCancelError, or when we got an error that doesn't call our handler, such as LUA_ERRMEM | 556 | // note we don't always have a stack trace for example when kCancelError, or when we got an error that doesn't call our handler, such as LUA_ERRMEM |
557 | if (_finalizers_index == 3) { | 557 | if (_finalizers_index == 3) { |
@@ -683,7 +683,7 @@ static void lane_main(Lane* lane_) | |||
683 | // in case of error and if it exists, fetch stack trace from registry and push it | 683 | // in case of error and if it exists, fetch stack trace from registry and push it |
684 | push_stack_trace(_L, lane_->errorTraceLevel, _rc, 1); // L: retvals|error [trace] | 684 | push_stack_trace(_L, lane_->errorTraceLevel, _rc, 1); // L: retvals|error [trace] |
685 | 685 | ||
686 | DEBUGSPEW_CODE(DebugSpew(_U) << "Lane " << _L << " body: " << GetErrcodeName(_rc) << " (" << (kCancelError.equals(_L, 1) ? "cancelled" : lua_typename(_L, lua_type(_L, 1))) << ")" << std::endl); | 686 | DEBUGSPEW_CODE(DebugSpew(_U) << "Lane " << _L << " body: " << GetErrcodeName(_rc) << " (" << (kCancelError.equals(_L, 1) ? "cancelled" : luaG_typename(_L, luaG_type(_L, 1))) << ")" << std::endl); |
687 | // Call finalizers, if the script has set them up. | 687 | // Call finalizers, if the script has set them up. |
688 | // | 688 | // |
689 | LuaError const _rc2{ run_finalizers(_L, lane_->errorTraceLevel, _rc) }; | 689 | LuaError const _rc2{ run_finalizers(_L, lane_->errorTraceLevel, _rc) }; |
@@ -745,7 +745,7 @@ static void lane_main(Lane* lane_) | |||
745 | lua_rawget(L_, -2); // L_: ud uservalue gc_cb|nil | 745 | lua_rawget(L_, -2); // L_: ud uservalue gc_cb|nil |
746 | if (!lua_isnil(L_, -1)) { | 746 | if (!lua_isnil(L_, -1)) { |
747 | lua_remove(L_, -2); // L_: ud gc_cb|nil | 747 | lua_remove(L_, -2); // L_: ud gc_cb|nil |
748 | std::ignore = lua_pushstringview(L_, _lane->debugName); // L_: ud gc_cb name | 748 | std::ignore = luaG_pushstringview(L_, _lane->debugName); // L_: ud gc_cb name |
749 | _have_gc_cb = true; | 749 | _have_gc_cb = true; |
750 | } else { | 750 | } else { |
751 | lua_pop(L_, 2); // L_: ud | 751 | lua_pop(L_, 2); // L_: ud |
@@ -810,7 +810,7 @@ void Lane::changeDebugName(int const nameIdx_) | |||
810 | // store a hidden reference in the registry to make sure the string is kept around even if a lane decides to manually change the "decoda_name" global... | 810 | // store a hidden reference in the registry to make sure the string is kept around even if a lane decides to manually change the "decoda_name" global... |
811 | kLaneNameRegKey.setValue(L, [idx = _nameIdx](lua_State* L_) { lua_pushvalue(L_, idx); }); // L: ... "name" ... | 811 | kLaneNameRegKey.setValue(L, [idx = _nameIdx](lua_State* L_) { lua_pushvalue(L_, idx); }); // L: ... "name" ... |
812 | // keep a direct pointer on the string | 812 | // keep a direct pointer on the string |
813 | debugName = lua_tostringview(L, _nameIdx); | 813 | debugName = luaG_tostringview(L, _nameIdx); |
814 | if constexpr (HAVE_DECODA_SUPPORT()) { | 814 | if constexpr (HAVE_DECODA_SUPPORT()) { |
815 | // to see VM name in Decoda debugger Virtual Machine window | 815 | // to see VM name in Decoda debugger Virtual Machine window |
816 | lua_pushvalue(L, _nameIdx); // L: ... "name" ... "name" | 816 | lua_pushvalue(L, _nameIdx); // L: ... "name" ... "name" |
@@ -897,7 +897,7 @@ void Lane::PushMetatable(lua_State* L_) | |||
897 | std::string_view const _str{ threadStatusString() }; | 897 | std::string_view const _str{ threadStatusString() }; |
898 | LUA_ASSERT(L_, !_str.empty()); | 898 | LUA_ASSERT(L_, !_str.empty()); |
899 | 899 | ||
900 | return lua_pushstringview(L_, _str); | 900 | return luaG_pushstringview(L_, _str); |
901 | } | 901 | } |
902 | 902 | ||
903 | // ################################################################################################# | 903 | // ################################################################################################# |
@@ -907,7 +907,7 @@ void Lane::PushMetatable(lua_State* L_) | |||
907 | std::string_view const _str{ errorTraceLevelString() }; | 907 | std::string_view const _str{ errorTraceLevelString() }; |
908 | LUA_ASSERT(L_, !_str.empty()); | 908 | LUA_ASSERT(L_, !_str.empty()); |
909 | 909 | ||
910 | return lua_pushstringview(L_, _str); | 910 | return luaG_pushstringview(L_, _str); |
911 | } | 911 | } |
912 | 912 | ||
913 | // ################################################################################################# | 913 | // ################################################################################################# |
@@ -922,7 +922,7 @@ void Lane::securizeDebugName(lua_State* L_) | |||
922 | LUA_ASSERT(L_, lua_istable(L_, -1)); | 922 | LUA_ASSERT(L_, lua_istable(L_, -1)); |
923 | // we don't care about the actual key, so long as it's unique and can't collide with anything. | 923 | // we don't care about the actual key, so long as it's unique and can't collide with anything. |
924 | lua_newtable(L_); // L_: lane ... {uv} {} | 924 | lua_newtable(L_); // L_: lane ... {uv} {} |
925 | debugName = lua_pushstringview(L_, debugName); // L_: lane ... {uv} {} name | 925 | debugName = luaG_pushstringview(L_, debugName); // L_: lane ... {uv} {} name |
926 | lua_rawset(L_, -3); // L_: lane ... {uv} | 926 | lua_rawset(L_, -3); // L_: lane ... {uv} |
927 | lua_pop(L_, 1); // L_: lane | 927 | lua_pop(L_, 1); // L_: lane |
928 | STACK_CHECK(L_, 0); | 928 | STACK_CHECK(L_, 0); |
diff --git a/src/lanes.cpp b/src/lanes.cpp index 25f44d9..a36e051 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp | |||
@@ -170,7 +170,7 @@ LUAG_FUNC(sleep) | |||
170 | lua_pushcfunction(L_, LG_linda_receive); // L_: duration|nil receive() | 170 | lua_pushcfunction(L_, LG_linda_receive); // L_: duration|nil receive() |
171 | STACK_CHECK_START_REL(L_, 0); // we pushed the function we intend to call, now prepare the arguments | 171 | STACK_CHECK_START_REL(L_, 0); // we pushed the function we intend to call, now prepare the arguments |
172 | _U->timerLinda->push(L_); // L_: duration|nil receive() timerLinda | 172 | _U->timerLinda->push(L_); // L_: duration|nil receive() timerLinda |
173 | if (lua_tostringview(L_, 1) == "indefinitely") { | 173 | if (luaG_tostringview(L_, 1) == "indefinitely") { |
174 | lua_pushnil(L_); // L_: duration? receive() timerLinda nil | 174 | lua_pushnil(L_); // L_: duration? receive() timerLinda nil |
175 | } else if (lua_isnoneornil(L_, 1)) { | 175 | } else if (lua_isnoneornil(L_, 1)) { |
176 | lua_pushnumber(L_, 0); // L_: duration? receive() timerLinda 0 | 176 | lua_pushnumber(L_, 0); // L_: duration? receive() timerLinda 0 |
@@ -180,7 +180,7 @@ LUAG_FUNC(sleep) | |||
180 | else { | 180 | else { |
181 | lua_pushnumber(L_, lua_tonumber(L_, 1)); // L_: duration? receive() timerLinda duration | 181 | lua_pushnumber(L_, lua_tonumber(L_, 1)); // L_: duration? receive() timerLinda duration |
182 | } | 182 | } |
183 | std::ignore = lua_pushstringview(L_, "ac100de1-a696-4619-b2f0-a26de9d58ab8"); // L_: duration? receive() timerLinda duration key | 183 | std::ignore = luaG_pushstringview(L_, "ac100de1-a696-4619-b2f0-a26de9d58ab8"); // L_: duration? receive() timerLinda duration key |
184 | STACK_CHECK(L_, 3); // 3 arguments ready | 184 | STACK_CHECK(L_, 3); // 3 arguments ready |
185 | lua_call(L_, 3, LUA_MULTRET); // timerLinda:receive(duration,key) // L_: duration? result... | 185 | lua_call(L_, 3, LUA_MULTRET); // timerLinda:receive(duration,key) // L_: duration? result... |
186 | return lua_gettop(L_) - 1; | 186 | return lua_gettop(L_) - 1; |
@@ -194,7 +194,7 @@ LUAG_FUNC(sleep) | |||
194 | // upvalue[1]: _G.require | 194 | // upvalue[1]: _G.require |
195 | LUAG_FUNC(require) | 195 | LUAG_FUNC(require) |
196 | { | 196 | { |
197 | std::string_view const _name{ lua_tostringview(L_, 1) }; // L_: "name" ... | 197 | std::string_view const _name{ luaG_tostringview(L_, 1) }; // L_: "name" ... |
198 | int const _nargs{ lua_gettop(L_) }; | 198 | int const _nargs{ lua_gettop(L_) }; |
199 | DEBUGSPEW_CODE(Universe * _U{ Universe::Get(L_) }); | 199 | DEBUGSPEW_CODE(Universe * _U{ Universe::Get(L_) }); |
200 | STACK_CHECK_START_REL(L_, 0); | 200 | STACK_CHECK_START_REL(L_, 0); |
@@ -216,8 +216,8 @@ LUAG_FUNC(require) | |||
216 | // lanes.register( "modname", module) | 216 | // lanes.register( "modname", module) |
217 | LUAG_FUNC(register) | 217 | LUAG_FUNC(register) |
218 | { | 218 | { |
219 | std::string_view const _name{ luaL_checkstringview(L_, 1) }; | 219 | std::string_view const _name{ luaG_checkstringview(L_, 1) }; |
220 | LuaType const _mod_type{ lua_type_as_enum(L_, 2) }; | 220 | LuaType const _mod_type{ luaG_type(L_, 2) }; |
221 | // ignore extra parameters, just in case | 221 | // ignore extra parameters, just in case |
222 | lua_settop(L_, 2); | 222 | lua_settop(L_, 2); |
223 | luaL_argcheck(L_, (_mod_type == LuaType::TABLE) || (_mod_type == LuaType::FUNCTION), 2, "unexpected module type"); | 223 | luaL_argcheck(L_, (_mod_type == LuaType::TABLE) || (_mod_type == LuaType::FUNCTION), 2, "unexpected module type"); |
@@ -266,7 +266,7 @@ LUAG_FUNC(lane_new) | |||
266 | Universe* const _U{ Universe::Get(L_) }; | 266 | Universe* const _U{ Universe::Get(L_) }; |
267 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: setup" << std::endl); | 267 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: setup" << std::endl); |
268 | 268 | ||
269 | std::optional<std::string_view> _libs_str{ lua_isnil(L_, kLibsIdx) ? std::nullopt : std::make_optional(lua_tostringview(L_, kLibsIdx)) }; | 269 | std::optional<std::string_view> _libs_str{ lua_isnil(L_, kLibsIdx) ? std::nullopt : std::make_optional(luaG_tostringview(L_, kLibsIdx)) }; |
270 | lua_State* const _L2{ state::NewLaneState(_U, SourceState{ L_ }, _libs_str) }; // L_: [fixed] ... L2: | 270 | lua_State* const _L2{ state::NewLaneState(_U, SourceState{ L_ }, _libs_str) }; // L_: [fixed] ... L2: |
271 | STACK_CHECK_START_REL(_L2, 0); | 271 | STACK_CHECK_START_REL(_L2, 0); |
272 | 272 | ||
@@ -345,11 +345,11 @@ LUAG_FUNC(lane_new) | |||
345 | lua_State* _L2{ lane->L }; | 345 | lua_State* _L2{ lane->L }; |
346 | STACK_CHECK_START_REL(_L2, 0); | 346 | STACK_CHECK_START_REL(_L2, 0); |
347 | int const _name_idx{ lua_isnoneornil(L, kNameIdx) ? 0 : kNameIdx }; | 347 | int const _name_idx{ lua_isnoneornil(L, kNameIdx) ? 0 : kNameIdx }; |
348 | std::string_view const _debugName{ (_name_idx > 0) ? lua_tostringview(L, _name_idx) : std::string_view{} }; | 348 | std::string_view const _debugName{ (_name_idx > 0) ? luaG_tostringview(L, _name_idx) : std::string_view{} }; |
349 | if (!_debugName.empty()) | 349 | if (!_debugName.empty()) |
350 | { | 350 | { |
351 | if (_debugName != "auto") { | 351 | if (_debugName != "auto") { |
352 | std::ignore = lua_pushstringview(_L2, _debugName); // L: ... lane L2: "<name>" | 352 | std::ignore = luaG_pushstringview(_L2, _debugName); // L: ... lane L2: "<name>" |
353 | } else { | 353 | } else { |
354 | lua_Debug _ar; | 354 | lua_Debug _ar; |
355 | lua_pushvalue(L, 1); // L: ... lane func | 355 | lua_pushvalue(L, 1); // L: ... lane func |
@@ -413,17 +413,17 @@ LUAG_FUNC(lane_new) | |||
413 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: process 'required' list" << std::endl); | 413 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: process 'required' list" << std::endl); |
414 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); | 414 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); |
415 | // should not happen, was checked in lanes.lua before calling lane_new() | 415 | // should not happen, was checked in lanes.lua before calling lane_new() |
416 | if (lua_type(L_, _required_idx) != LUA_TTABLE) { | 416 | if (luaG_type(L_, _required_idx) != LuaType::TABLE) { |
417 | raise_luaL_error(L_, "expected required module list as a table, got %s", luaL_typename(L_, _required_idx)); | 417 | raise_luaL_error(L_, "expected required module list as a table, got %s", luaL_typename(L_, _required_idx)); |
418 | } | 418 | } |
419 | 419 | ||
420 | lua_pushnil(L_); // L_: [fixed] args... nil L2: | 420 | lua_pushnil(L_); // L_: [fixed] args... nil L2: |
421 | while (lua_next(L_, _required_idx) != 0) { // L_: [fixed] args... n "modname" L2: | 421 | while (lua_next(L_, _required_idx) != 0) { // L_: [fixed] args... n "modname" L2: |
422 | if (lua_type(L_, -1) != LUA_TSTRING || lua_type(L_, -2) != LUA_TNUMBER || lua_tonumber(L_, -2) != _nbRequired) { | 422 | if (luaG_type(L_, -1) != LuaType::STRING || luaG_type(L_, -2) != LuaType::NUMBER || lua_tonumber(L_, -2) != _nbRequired) { |
423 | raise_luaL_error(L_, "required module list should be a list of strings"); | 423 | raise_luaL_error(L_, "required module list should be a list of strings"); |
424 | } else { | 424 | } else { |
425 | // require the module in the target state, and populate the lookup table there too | 425 | // require the module in the target state, and populate the lookup table there too |
426 | std::string_view const _name{ lua_tostringview(L_, -1) }; | 426 | std::string_view const _name{ luaG_tostringview(L_, -1) }; |
427 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: require '" << _name << "'" << std::endl); | 427 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: require '" << _name << "'" << std::endl); |
428 | 428 | ||
429 | // require the module in the target lane | 429 | // require the module in the target lane |
@@ -432,7 +432,7 @@ LUAG_FUNC(lane_new) | |||
432 | lua_pop(_L2, 1); // L_: [fixed] args... n "modname" L2: | 432 | lua_pop(_L2, 1); // L_: [fixed] args... n "modname" L2: |
433 | raise_luaL_error(L_, "cannot pre-require modules without loading 'package' library first"); | 433 | raise_luaL_error(L_, "cannot pre-require modules without loading 'package' library first"); |
434 | } else { | 434 | } else { |
435 | std::ignore = lua_pushstringview(_L2, _name); // L_: [fixed] args... n "modname" L2: require() name | 435 | std::ignore = luaG_pushstringview(_L2, _name); // L_: [fixed] args... n "modname" L2: require() name |
436 | LuaError const _rc{ lua_pcall(_L2, 1, 1, 0) }; // L_: [fixed] args... n "modname" L2: ret/errcode | 436 | LuaError const _rc{ lua_pcall(_L2, 1, 1, 0) }; // L_: [fixed] args... n "modname" L2: ret/errcode |
437 | if (_rc != LuaError::OK) { | 437 | if (_rc != LuaError::OK) { |
438 | // propagate error to main state if any | 438 | // propagate error to main state if any |
@@ -481,7 +481,7 @@ LUAG_FUNC(lane_new) | |||
481 | 481 | ||
482 | // Lane main function | 482 | // Lane main function |
483 | [[maybe_unused]] int const errorHandlerCount{ _lane->pushErrorHandler() }; // L_: [fixed] args... L2: eh? | 483 | [[maybe_unused]] int const errorHandlerCount{ _lane->pushErrorHandler() }; // L_: [fixed] args... L2: eh? |
484 | LuaType const _func_type{ lua_type_as_enum(L_, kFuncIdx) }; | 484 | LuaType const _func_type{ luaG_type(L_, kFuncIdx) }; |
485 | if (_func_type == LuaType::FUNCTION) { | 485 | if (_func_type == LuaType::FUNCTION) { |
486 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: transfer lane body" << std::endl); | 486 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: transfer lane body" << std::endl); |
487 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); | 487 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); |
@@ -498,7 +498,7 @@ LUAG_FUNC(lane_new) | |||
498 | raise_luaL_error(L_, "error when parsing lane function code"); | 498 | raise_luaL_error(L_, "error when parsing lane function code"); |
499 | } | 499 | } |
500 | } else { | 500 | } else { |
501 | raise_luaL_error(L_, "Expected function, got %s", lua_typename(L_, _func_type)); | 501 | raise_luaL_error(L_, "Expected function, got %s", luaG_typename(L_, _func_type)); |
502 | } | 502 | } |
503 | STACK_CHECK(L_, 0); | 503 | STACK_CHECK(L_, 0); |
504 | STACK_CHECK(_L2, errorHandlerCount + 1); | 504 | STACK_CHECK(_L2, errorHandlerCount + 1); |
@@ -655,8 +655,8 @@ LUAG_FUNC(configure) | |||
655 | 655 | ||
656 | Universe* _U{ Universe::Get(L_) }; | 656 | Universe* _U{ Universe::Get(L_) }; |
657 | bool const _from_master_state{ _U == nullptr }; | 657 | bool const _from_master_state{ _U == nullptr }; |
658 | std::string_view const _name{ luaL_checkstringview(L_, lua_upvalueindex(1)) }; | 658 | std::string_view const _name{ luaG_checkstringview(L_, lua_upvalueindex(1)) }; |
659 | LUA_ASSERT(L_, lua_type(L_, 1) == LUA_TTABLE); | 659 | LUA_ASSERT(L_, luaG_type(L_, 1) == LuaType::TABLE); |
660 | 660 | ||
661 | STACK_GROW(L_, 4); | 661 | STACK_GROW(L_, 4); |
662 | STACK_CHECK_START_ABS(L_, 1); // L_: settings | 662 | STACK_CHECK_START_ABS(L_, 1); // L_: settings |
@@ -666,7 +666,7 @@ LUAG_FUNC(configure) | |||
666 | 666 | ||
667 | if (_U == nullptr) { | 667 | if (_U == nullptr) { |
668 | // 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... | 668 | // 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... |
669 | kLaneNameRegKey.setValue(L_, [](lua_State* L_) { std::ignore = lua_pushstringview(L_, "main"); }); | 669 | kLaneNameRegKey.setValue(L_, [](lua_State* L_) { std::ignore = luaG_pushstringview(L_, "main"); }); |
670 | 670 | ||
671 | // create the universe | 671 | // create the universe |
672 | _U = Universe::Create(L_); // L_: settings universe | 672 | _U = Universe::Create(L_); // L_: settings universe |
diff --git a/src/linda.cpp b/src/linda.cpp index b623d29..bd3026d 100644 --- a/src/linda.cpp +++ b/src/linda.cpp | |||
@@ -43,7 +43,7 @@ THE SOFTWARE. | |||
43 | static void check_key_types(lua_State* L_, int start_, int end_) | 43 | static void check_key_types(lua_State* L_, int start_, int end_) |
44 | { | 44 | { |
45 | for (int _i{ start_ }; _i <= end_; ++_i) { | 45 | for (int _i{ start_ }; _i <= end_; ++_i) { |
46 | LuaType const t{ lua_type_as_enum(L_, _i) }; | 46 | LuaType const t{ luaG_type(L_, _i) }; |
47 | switch (t) { | 47 | switch (t) { |
48 | case LuaType::BOOLEAN: | 48 | case LuaType::BOOLEAN: |
49 | case LuaType::NUMBER: | 49 | case LuaType::NUMBER: |
@@ -79,10 +79,10 @@ template <bool OPT> | |||
79 | { | 79 | { |
80 | Linda* const _linda{ ToLinda<OPT>(L_, idx_) }; | 80 | Linda* const _linda{ ToLinda<OPT>(L_, idx_) }; |
81 | if (_linda != nullptr) { | 81 | if (_linda != nullptr) { |
82 | std::ignore = lua_pushstringview(L_, "Linda: "); | 82 | std::ignore = luaG_pushstringview(L_, "Linda: "); |
83 | std::string_view const _lindaName{ _linda->getName() }; | 83 | std::string_view const _lindaName{ _linda->getName() }; |
84 | if (!_lindaName.empty()) { | 84 | if (!_lindaName.empty()) { |
85 | std::ignore = lua_pushstringview(L_, _lindaName); | 85 | std::ignore = luaG_pushstringview(L_, _lindaName); |
86 | } else { | 86 | } else { |
87 | lua_pushfstring(L_, "%p", _linda); | 87 | lua_pushfstring(L_, "%p", _linda); |
88 | } | 88 | } |
@@ -247,7 +247,7 @@ void Linda::setName(std::string_view const& name_) | |||
247 | LUAG_FUNC(linda_cancel) | 247 | LUAG_FUNC(linda_cancel) |
248 | { | 248 | { |
249 | Linda* const _linda{ ToLinda<false>(L_, 1) }; | 249 | Linda* const _linda{ ToLinda<false>(L_, 1) }; |
250 | std::string_view const _who{ luaL_optstringview(L_, 2, "both") }; | 250 | std::string_view const _who{ luaG_optstringview(L_, 2, "both") }; |
251 | // make sure we got 2 arguments: the linda and the cancellation mode | 251 | // make sure we got 2 arguments: the linda and the cancellation mode |
252 | luaL_argcheck(L_, lua_gettop(L_) <= 2, 2, "wrong number of arguments"); | 252 | luaL_argcheck(L_, lua_gettop(L_) <= 2, 2, "wrong number of arguments"); |
253 | 253 | ||
@@ -412,7 +412,7 @@ LUAG_FUNC(linda_limit) | |||
412 | _pushed = keeper_call(_K->L, KEEPER_API(limit), L_, _linda, 2); | 412 | _pushed = keeper_call(_K->L, KEEPER_API(limit), L_, _linda, 2); |
413 | LUA_ASSERT(L_, _pushed.has_value() && (_pushed.value() == 0 || _pushed.value() == 1)); // no error, optional boolean value saying if we should wake blocked writer threads | 413 | LUA_ASSERT(L_, _pushed.has_value() && (_pushed.value() == 0 || _pushed.value() == 1)); // no error, optional boolean value saying if we should wake blocked writer threads |
414 | if (_pushed.value() == 1) { | 414 | if (_pushed.value() == 1) { |
415 | LUA_ASSERT(L_, lua_type(L_, -1) == LUA_TBOOLEAN && lua_toboolean(L_, -1) == 1); | 415 | LUA_ASSERT(L_, luaG_type(L_, -1) == LuaType::BOOLEAN && lua_toboolean(L_, -1) == 1); |
416 | _linda->readHappened.notify_all(); // To be done from within the 'K' locking area | 416 | _linda->readHappened.notify_all(); // To be done from within the 'K' locking area |
417 | } | 417 | } |
418 | } else { // linda is cancelled | 418 | } else { // linda is cancelled |
@@ -446,7 +446,7 @@ LUAG_FUNC(linda_receive) | |||
446 | int _key_i{ 2 }; // index of first key, if timeout not there | 446 | int _key_i{ 2 }; // index of first key, if timeout not there |
447 | 447 | ||
448 | std::chrono::time_point<std::chrono::steady_clock> _until{ std::chrono::time_point<std::chrono::steady_clock>::max() }; | 448 | std::chrono::time_point<std::chrono::steady_clock> _until{ std::chrono::time_point<std::chrono::steady_clock>::max() }; |
449 | if (lua_type(L_, 2) == LUA_TNUMBER) { // we don't want to use lua_isnumber() because of autocoercion | 449 | if (luaG_type(L_, 2) == LuaType::NUMBER) { // we don't want to use lua_isnumber() because of autocoercion |
450 | lua_Duration const _duration{ lua_tonumber(L_, 2) }; | 450 | lua_Duration const _duration{ lua_tonumber(L_, 2) }; |
451 | if (_duration.count() >= 0.0) { | 451 | if (_duration.count() >= 0.0) { |
452 | _until = std::chrono::steady_clock::now() + std::chrono::duration_cast<std::chrono::steady_clock::duration>(_duration); | 452 | _until = std::chrono::steady_clock::now() + std::chrono::duration_cast<std::chrono::steady_clock::duration>(_duration); |
@@ -559,7 +559,7 @@ LUAG_FUNC(linda_receive) | |||
559 | if (_nbPushed == 0) { | 559 | if (_nbPushed == 0) { |
560 | // not enough data in the linda slot to fulfill the request, return nil, "timeout" | 560 | // not enough data in the linda slot to fulfill the request, return nil, "timeout" |
561 | lua_pushnil(L_); | 561 | lua_pushnil(L_); |
562 | std::ignore = lua_pushstringview(L_, "timeout"); | 562 | std::ignore = luaG_pushstringview(L_, "timeout"); |
563 | return 2; | 563 | return 2; |
564 | } | 564 | } |
565 | return _nbPushed; | 565 | return _nbPushed; |
@@ -600,7 +600,7 @@ LUAG_FUNC(linda_send) | |||
600 | int _key_i{ 2 }; // index of first key, if timeout not there | 600 | int _key_i{ 2 }; // index of first key, if timeout not there |
601 | 601 | ||
602 | std::chrono::time_point<std::chrono::steady_clock> _until{ std::chrono::time_point<std::chrono::steady_clock>::max() }; | 602 | std::chrono::time_point<std::chrono::steady_clock> _until{ std::chrono::time_point<std::chrono::steady_clock>::max() }; |
603 | if (lua_type(L_, 2) == LUA_TNUMBER) { // we don't want to use lua_isnumber() because of autocoercion | 603 | if (luaG_type(L_, 2) == LuaType::NUMBER) { // we don't want to use lua_isnumber() because of autocoercion |
604 | lua_Duration const _duration{ lua_tonumber(L_, 2) }; | 604 | lua_Duration const _duration{ lua_tonumber(L_, 2) }; |
605 | if (_duration.count() >= 0.0) { | 605 | if (_duration.count() >= 0.0) { |
606 | _until = std::chrono::steady_clock::now() + std::chrono::duration_cast<std::chrono::steady_clock::duration>(_duration); | 606 | _until = std::chrono::steady_clock::now() + std::chrono::duration_cast<std::chrono::steady_clock::duration>(_duration); |
@@ -742,7 +742,7 @@ LUAG_FUNC(linda_set) | |||
742 | } | 742 | } |
743 | if (_pushed.value() == 1) { | 743 | if (_pushed.value() == 1) { |
744 | // the key was full, but it is no longer the case, tell writers they should wake | 744 | // the key was full, but it is no longer the case, tell writers they should wake |
745 | LUA_ASSERT(L_, lua_type(L_, -1) == LUA_TBOOLEAN && lua_toboolean(L_, -1) == 1); | 745 | LUA_ASSERT(L_, luaG_type(L_, -1) == LuaType::BOOLEAN && lua_toboolean(L_, -1) == 1); |
746 | _linda->readHappened.notify_all(); // To be done from within the 'K' locking area | 746 | _linda->readHappened.notify_all(); // To be done from within the 'K' locking area |
747 | } | 747 | } |
748 | } | 748 | } |
@@ -826,7 +826,7 @@ LUAG_FUNC(linda) | |||
826 | int _groupIdx{}; | 826 | int _groupIdx{}; |
827 | luaL_argcheck(L_, _top <= 2, _top, "too many arguments"); | 827 | luaL_argcheck(L_, _top <= 2, _top, "too many arguments"); |
828 | if (_top == 1) { | 828 | if (_top == 1) { |
829 | LuaType const _t{ lua_type_as_enum(L_, 1) }; | 829 | LuaType const _t{ luaG_type(L_, 1) }; |
830 | int const _nameIdx{ (_t == LuaType::STRING) ? 1 : 0 }; | 830 | int const _nameIdx{ (_t == LuaType::STRING) ? 1 : 0 }; |
831 | _groupIdx = (_t == LuaType::NUMBER) ? 1 : 0; | 831 | _groupIdx = (_t == LuaType::NUMBER) ? 1 : 0; |
832 | luaL_argcheck(L_, _nameIdx || _groupIdx, 1, "wrong parameter (should be a string or a number)"); | 832 | luaL_argcheck(L_, _nameIdx || _groupIdx, 1, "wrong parameter (should be a string or a number)"); |
diff --git a/src/lindafactory.cpp b/src/lindafactory.cpp index 94dd3ab..d99d546 100644 --- a/src/lindafactory.cpp +++ b/src/lindafactory.cpp | |||
@@ -111,15 +111,15 @@ DeepPrelude* LindaFactory::newDeepObjectInternal(lua_State* L_) const | |||
111 | break; | 111 | break; |
112 | 112 | ||
113 | case 1: // 1 parameter, either a name or a group | 113 | case 1: // 1 parameter, either a name or a group |
114 | if (lua_type(L_, -1) == LUA_TSTRING) { | 114 | if (luaG_type(L_, -1) == LuaType::STRING) { |
115 | _linda_name = lua_tostringview(L_, -1); | 115 | _linda_name = luaG_tostringview(L_, -1); |
116 | } else { | 116 | } else { |
117 | _linda_group = LindaGroup{ static_cast<int>(lua_tointeger(L_, -1)) }; | 117 | _linda_group = LindaGroup{ static_cast<int>(lua_tointeger(L_, -1)) }; |
118 | } | 118 | } |
119 | break; | 119 | break; |
120 | 120 | ||
121 | case 2: // 2 parameters, a name and group, in that order | 121 | case 2: // 2 parameters, a name and group, in that order |
122 | _linda_name = lua_tostringview(L_, -2); | 122 | _linda_name = luaG_tostringview(L_, -2); |
123 | _linda_group = LindaGroup{ static_cast<int>(lua_tointeger(L_, -1)) }; | 123 | _linda_group = LindaGroup{ static_cast<int>(lua_tointeger(L_, -1)) }; |
124 | break; | 124 | break; |
125 | } | 125 | } |
diff --git a/src/nameof.cpp b/src/nameof.cpp index 7614577..8611239 100644 --- a/src/nameof.cpp +++ b/src/nameof.cpp | |||
@@ -59,8 +59,8 @@ THE SOFTWARE. | |||
59 | // scan table contents | 59 | // scan table contents |
60 | lua_pushnil(L_); // L_: o "r" {c} {fqn} ... {?} nil | 60 | lua_pushnil(L_); // L_: o "r" {c} {fqn} ... {?} nil |
61 | while (lua_next(L_, -2)) { // L_: o "r" {c} {fqn} ... {?} k v | 61 | while (lua_next(L_, -2)) { // L_: o "r" {c} {fqn} ... {?} k v |
62 | // std::string_view const _strKey{ (lua_type(L_, -2) == LUA_TSTRING) ? lua_tostringview(L_, -2) : "" }; // only for debugging | 62 | // std::string_view const _strKey{ (luaG_type(L_, -2) == LuaType::STRING) ? luaG_tostringview(L_, -2) : "" }; // only for debugging |
63 | // lua_Number const numKey = (lua_type(L_, -2) == LUA_TNUMBER) ? lua_tonumber(L_, -2) : -6666; // only for debugging | 63 | // lua_Number const numKey = (luaG_type(L_, -2) == LuaType::NUMBER) ? lua_tonumber(L_, -2) : -6666; // only for debugging |
64 | STACK_CHECK(L_, 2); | 64 | STACK_CHECK(L_, 2); |
65 | // append key name to fqn stack | 65 | // append key name to fqn stack |
66 | ++depth_; | 66 | ++depth_; |
@@ -79,11 +79,11 @@ THE SOFTWARE. | |||
79 | STACK_CHECK(L_, 0); | 79 | STACK_CHECK(L_, 0); |
80 | break; | 80 | break; |
81 | } | 81 | } |
82 | switch (lua_type(L_, -1)) { // L_: o "r" {c} {fqn} ... {?} k v | 82 | switch (luaG_type(L_, -1)) { // L_: o "r" {c} {fqn} ... {?} k v |
83 | default: // nil, boolean, light userdata, number and string aren't identifiable | 83 | default: // nil, boolean, light userdata, number and string aren't identifiable |
84 | break; | 84 | break; |
85 | 85 | ||
86 | case LUA_TTABLE: // L_: o "r" {c} {fqn} ... {?} k {} | 86 | case LuaType::TABLE: // L_: o "r" {c} {fqn} ... {?} k {} |
87 | STACK_CHECK(L_, 2); | 87 | STACK_CHECK(L_, 2); |
88 | shortest_ = DiscoverObjectNameRecur(L_, shortest_, depth_); | 88 | shortest_ = DiscoverObjectNameRecur(L_, shortest_, depth_); |
89 | // search in the table's metatable too | 89 | // search in the table's metatable too |
@@ -102,11 +102,11 @@ THE SOFTWARE. | |||
102 | STACK_CHECK(L_, 2); | 102 | STACK_CHECK(L_, 2); |
103 | break; | 103 | break; |
104 | 104 | ||
105 | case LUA_TTHREAD: // L_: o "r" {c} {fqn} ... {?} k T | 105 | case LuaType::THREAD: // L_: o "r" {c} {fqn} ... {?} k T |
106 | // TODO: explore the thread's stack frame looking for our culprit? | 106 | // TODO: explore the thread's stack frame looking for our culprit? |
107 | break; | 107 | break; |
108 | 108 | ||
109 | case LUA_TUSERDATA: // L_: o "r" {c} {fqn} ... {?} k U | 109 | case LuaType::USERDATA: // L_: o "r" {c} {fqn} ... {?} k U |
110 | STACK_CHECK(L_, 2); | 110 | STACK_CHECK(L_, 2); |
111 | // search in the object's metatable (some modules are built that way) | 111 | // search in the object's metatable (some modules are built that way) |
112 | if (lua_getmetatable(L_, -1)) { // L_: o "r" {c} {fqn} ... {?} k U {mt} | 112 | if (lua_getmetatable(L_, -1)) { // L_: o "r" {c} {fqn} ... {?} k U {mt} |
@@ -172,7 +172,7 @@ LUAG_FUNC(nameof) | |||
172 | } | 172 | } |
173 | 173 | ||
174 | // nil, boolean, light userdata, number and string aren't identifiable | 174 | // nil, boolean, light userdata, number and string aren't identifiable |
175 | if (lua_type(L_, 1) < LUA_TTABLE) { | 175 | if (luaG_type(L_, 1) < LuaType::TABLE) { |
176 | lua_pushstring(L_, luaL_typename(L_, 1)); // L_: o "type" | 176 | lua_pushstring(L_, luaL_typename(L_, 1)); // L_: o "type" |
177 | lua_insert(L_, -2); // L_: "type" o | 177 | lua_insert(L_, -2); // L_: "type" o |
178 | return 2; | 178 | return 2; |
diff --git a/src/state.cpp b/src/state.cpp index 7585132..af071e8 100644 --- a/src/state.cpp +++ b/src/state.cpp | |||
@@ -184,9 +184,9 @@ namespace state { | |||
184 | STACK_CHECK(L_, 1); | 184 | STACK_CHECK(L_, 1); |
185 | // capture error and raise it in caller state | 185 | // capture error and raise it in caller state |
186 | std::string_view const _stateType{ mode_ == LookupMode::LaneBody ? "lane" : "keeper" }; | 186 | std::string_view const _stateType{ mode_ == LookupMode::LaneBody ? "lane" : "keeper" }; |
187 | std::ignore = lua_pushstringview(L_, _stateType); // L_: on_state_create() "<type>" | 187 | std::ignore = luaG_pushstringview(L_, _stateType); // L_: on_state_create() "<type>" |
188 | if (lua_pcall(L_, 1, 0, 0) != LUA_OK) { | 188 | if (lua_pcall(L_, 1, 0, 0) != LUA_OK) { |
189 | raise_luaL_error(from_, "%s failed: \"%s\"", kOnStateCreate, lua_isstring(L_, -1) ? lua_tostring(L_, -1) : lua_typename(L_, lua_type(L_, -1))); | 189 | raise_luaL_error(from_, "%s failed: \"%s\"", kOnStateCreate, lua_isstring(L_, -1) ? lua_tostring(L_, -1) : luaG_typename(L_, luaG_type(L_, -1))); |
190 | } | 190 | } |
191 | STACK_CHECK(L_, 0); | 191 | STACK_CHECK(L_, 0); |
192 | } | 192 | } |
@@ -365,19 +365,19 @@ namespace state { | |||
365 | kLookupRegKey.pushValue(_L); // L: {} | 365 | kLookupRegKey.pushValue(_L); // L: {} |
366 | lua_pushnil(_L); // L: {} nil | 366 | lua_pushnil(_L); // L: {} nil |
367 | while (lua_next(_L, -2)) { // L: {} k v | 367 | while (lua_next(_L, -2)) { // L: {} k v |
368 | std::ignore = lua_pushstringview(_L, "["); // L: {} k v "[" | 368 | std::ignore = luaG_pushstringview(_L, "["); // L: {} k v "[" |
369 | 369 | ||
370 | lua_getglobal(_L, "tostring"); // L: {} k v "[" tostring | 370 | lua_getglobal(_L, "tostring"); // L: {} k v "[" tostring |
371 | lua_pushvalue(_L, -4); // L: {} k v "[" tostring k | 371 | lua_pushvalue(_L, -4); // L: {} k v "[" tostring k |
372 | lua_call(_L, 1, 1); // L: {} k v "[" 'k' | 372 | lua_call(_L, 1, 1); // L: {} k v "[" 'k' |
373 | 373 | ||
374 | std::ignore = lua_pushstringview(_L, "] = "); // L: {} k v "[" 'k' "] = " | 374 | std::ignore = luaG_pushstringview(_L, "] = "); // L: {} k v "[" 'k' "] = " |
375 | 375 | ||
376 | lua_getglobal(_L, "tostring"); // L: {} k v "[" 'k' "] = " tostring | 376 | lua_getglobal(_L, "tostring"); // L: {} k v "[" 'k' "] = " tostring |
377 | lua_pushvalue(_L, -5); // L: {} k v "[" 'k' "] = " tostring v | 377 | lua_pushvalue(_L, -5); // L: {} k v "[" 'k' "] = " tostring v |
378 | lua_call(_L, 1, 1); // L: {} k v "[" 'k' "] = " 'v' | 378 | lua_call(_L, 1, 1); // L: {} k v "[" 'k' "] = " 'v' |
379 | lua_concat(_L, 4); // L: {} k v "[k] = v" | 379 | lua_concat(_L, 4); // L: {} k v "[k] = v" |
380 | DEBUGSPEW_CODE(DebugSpew(U_) << lua_tostringview(_L, -1) << std::endl); | 380 | DEBUGSPEW_CODE(DebugSpew(U_) << luaG_tostringview(_L, -1) << std::endl); |
381 | lua_pop(_L, 2); // L: {} k | 381 | lua_pop(_L, 2); // L: {} k |
382 | } // lua_next() // L: {} | 382 | } // lua_next() // L: {} |
383 | lua_pop(_L, 1); // L: | 383 | lua_pop(_L, 1); // L: |
diff --git a/src/tools.cpp b/src/tools.cpp index e7d1775..302a0df 100644 --- a/src/tools.cpp +++ b/src/tools.cpp | |||
@@ -78,7 +78,7 @@ static constexpr int kWriterReturnCode{ 666 }; | |||
78 | // the provided writer fails with code kWriterReturnCode | 78 | // the provided writer fails with code kWriterReturnCode |
79 | // therefore, anytime we get kWriterReturnCode, this means that lua_dump() attempted a dump | 79 | // therefore, anytime we get kWriterReturnCode, this means that lua_dump() attempted a dump |
80 | // all other cases mean this is either a C or LuaJIT-fast function | 80 | // all other cases mean this is either a C or LuaJIT-fast function |
81 | int const _dumpres{ lua504_dump(L_, dummy_writer, nullptr, 0) }; | 81 | int const _dumpres{ luaG_dump(L_, dummy_writer, nullptr, 0) }; |
82 | lua_pop(L_, _mustpush); | 82 | lua_pop(L_, _mustpush); |
83 | if (_dumpres == kWriterReturnCode) { | 83 | if (_dumpres == kWriterReturnCode) { |
84 | return FuncSubType::Bytecode; | 84 | return FuncSubType::Bytecode; |
@@ -111,7 +111,7 @@ namespace tools { | |||
111 | // &b is popped at that point (-> replaced by the result) | 111 | // &b is popped at that point (-> replaced by the result) |
112 | luaL_pushresult(&_b); // L_: ... {} ... "<result>" | 112 | luaL_pushresult(&_b); // L_: ... {} ... "<result>" |
113 | STACK_CHECK(L_, 1); | 113 | STACK_CHECK(L_, 1); |
114 | return lua_tostringview(L_, -1); | 114 | return luaG_tostringview(L_, -1); |
115 | } | 115 | } |
116 | 116 | ||
117 | } // namespace tools | 117 | } // namespace tools |
@@ -141,10 +141,10 @@ static void update_lookup_entry(lua_State* L_, int ctxBase_, int depth_) | |||
141 | // first, raise an error if the function is already known | 141 | // first, raise an error if the function is already known |
142 | lua_pushvalue(L_, -1); // L_: ... {bfc} k o o | 142 | lua_pushvalue(L_, -1); // L_: ... {bfc} k o o |
143 | lua_rawget(L_, _dest); // L_: ... {bfc} k o name? | 143 | lua_rawget(L_, _dest); // L_: ... {bfc} k o name? |
144 | std::string_view const _prevName{ lua_tostringview(L_, -1) }; // nullptr if we got nil (first encounter of this object) | 144 | std::string_view const _prevName{ luaG_tostringview(L_, -1) }; // nullptr if we got nil (first encounter of this object) |
145 | // push name in fqn stack (note that concatenation will crash if name is a not string or a number) | 145 | // push name in fqn stack (note that concatenation will crash if name is a not string or a number) |
146 | lua_pushvalue(L_, -3); // L_: ... {bfc} k o name? k | 146 | lua_pushvalue(L_, -3); // L_: ... {bfc} k o name? k |
147 | LUA_ASSERT(L_, lua_type(L_, -1) == LUA_TNUMBER || lua_type(L_, -1) == LUA_TSTRING); | 147 | LUA_ASSERT(L_, luaG_type(L_, -1) == LuaType::NUMBER || luaG_type(L_, -1) == LuaType::STRING); |
148 | ++depth_; | 148 | ++depth_; |
149 | lua_rawseti(L_, _fqn, depth_); // L_: ... {bfc} k o name? | 149 | lua_rawseti(L_, _fqn, depth_); // L_: ... {bfc} k o name? |
150 | // generate name | 150 | // generate name |
@@ -157,7 +157,7 @@ static void update_lookup_entry(lua_State* L_, int ctxBase_, int depth_) | |||
157 | // Therefore, when we encounter an object for which a name was previously registered, we need to select the a single name | 157 | // Therefore, when we encounter an object for which a name was previously registered, we need to select the a single name |
158 | // based on some sorting order so that we end up with the same name in all databases whatever order the table walk yielded | 158 | // based on some sorting order so that we end up with the same name in all databases whatever order the table walk yielded |
159 | if (!_prevName.empty() && ((_prevName.size() < _newName.size()) || (_prevName <= _newName))) { | 159 | if (!_prevName.empty() && ((_prevName.size() < _newName.size()) || (_prevName <= _newName))) { |
160 | DEBUGSPEW_CODE(DebugSpew(_U) << lua_typename(L_, lua_type(L_, -3)) << " '" << _newName << "' remains named '" << _prevName << "'" << std::endl); | 160 | DEBUGSPEW_CODE(DebugSpew(_U) << luaG_typename(L_, luaG_type(L_, -3)) << " '" << _newName << "' remains named '" << _prevName << "'" << std::endl); |
161 | // the previous name is 'smaller' than the one we just generated: keep it! | 161 | // the previous name is 'smaller' than the one we just generated: keep it! |
162 | lua_pop(L_, 3); // L_: ... {bfc} k | 162 | lua_pop(L_, 3); // L_: ... {bfc} k |
163 | } else { | 163 | } else { |
@@ -171,7 +171,7 @@ static void update_lookup_entry(lua_State* L_, int ctxBase_, int depth_) | |||
171 | } else { | 171 | } else { |
172 | lua_remove(L_, -2); // L_: ... {bfc} k o "f.q.n" | 172 | lua_remove(L_, -2); // L_: ... {bfc} k o "f.q.n" |
173 | } | 173 | } |
174 | DEBUGSPEW_CODE(DebugSpew(_U) << lua_typename(L_, lua_type(L_, -2)) << " '" << _newName << "'" << std::endl); | 174 | DEBUGSPEW_CODE(DebugSpew(_U) << luaG_typename(L_, luaG_type(L_, -2)) << " '" << _newName << "'" << std::endl); |
175 | // prepare the stack for database feed | 175 | // prepare the stack for database feed |
176 | lua_pushvalue(L_, -1); // L_: ... {bfc} k o "f.q.n" "f.q.n" | 176 | lua_pushvalue(L_, -1); // L_: ... {bfc} k o "f.q.n" "f.q.n" |
177 | lua_pushvalue(L_, -3); // L_: ... {bfc} k o "f.q.n" "f.q.n" o | 177 | lua_pushvalue(L_, -3); // L_: ... {bfc} k o "f.q.n" "f.q.n" o |
@@ -207,7 +207,7 @@ static void populate_func_lookup_table_recur(lua_State* L_, int dbIdx_, int i_, | |||
207 | STACK_CHECK_START_REL(L_, 0); // L_: ... {i_} | 207 | STACK_CHECK_START_REL(L_, 0); // L_: ... {i_} |
208 | 208 | ||
209 | // if object is a userdata, replace it by its metatable | 209 | // if object is a userdata, replace it by its metatable |
210 | if (lua_type(L_, i_) == LUA_TUSERDATA) { | 210 | if (luaG_type(L_, i_) == LuaType::USERDATA) { |
211 | lua_getmetatable(L_, i_); // L_: ... {i_} mt | 211 | lua_getmetatable(L_, i_); // L_: ... {i_} mt |
212 | lua_replace(L_, i_); // L_: ... {i_} | 212 | lua_replace(L_, i_); // L_: ... {i_} |
213 | } | 213 | } |
@@ -236,7 +236,7 @@ static void populate_func_lookup_table_recur(lua_State* L_, int dbIdx_, int i_, | |||
236 | lua_pushnil(L_); // L_: ... {i_} {bfc} nil | 236 | lua_pushnil(L_); // L_: ... {i_} {bfc} nil |
237 | while (lua_next(L_, i_) != 0) { // L_: ... {i_} {bfc} k v | 237 | while (lua_next(L_, i_) != 0) { // L_: ... {i_} {bfc} k v |
238 | // just for debug, not actually needed | 238 | // just for debug, not actually needed |
239 | // std::string_view const _key{ (lua_type(L_, -2) == LUA_TSTRING) ? lua_tostringview(L_, -2) : "not a string" }; | 239 | // std::string_view const _key{ (luaG_type(L_, -2) == LuaType::STRING) ? luaG_tostringview(L_, -2) : "not a string" }; |
240 | // subtable: process it recursively | 240 | // subtable: process it recursively |
241 | if (lua_istable(L_, -1)) { // L_: ... {i_} {bfc} k {} | 241 | if (lua_istable(L_, -1)) { // L_: ... {i_} {bfc} k {} |
242 | // increment visit count to make sure we will actually scan it at this recursive level | 242 | // increment visit count to make sure we will actually scan it at this recursive level |
@@ -266,13 +266,13 @@ static void populate_func_lookup_table_recur(lua_State* L_, int dbIdx_, int i_, | |||
266 | ++depth_; | 266 | ++depth_; |
267 | lua_pushnil(L_); // L_: ... {i_} {bfc} nil | 267 | lua_pushnil(L_); // L_: ... {i_} {bfc} nil |
268 | while (lua_next(L_, breadthFirstCache) != 0) { // L_: ... {i_} {bfc} k {} | 268 | while (lua_next(L_, breadthFirstCache) != 0) { // L_: ... {i_} {bfc} k {} |
269 | DEBUGSPEW_CODE(std::string_view const _key{ (lua_type(L_, -2) == LUA_TSTRING) ? lua_tostringview(L_, -2) : std::string_view{ "<not a string>" } }); | 269 | DEBUGSPEW_CODE(std::string_view const _key{ (luaG_type(L_, -2) == LuaType::STRING) ? luaG_tostringview(L_, -2) : std::string_view{ "<not a string>" } }); |
270 | DEBUGSPEW_CODE(DebugSpew(_U) << "table '"<< _key <<"'" << std::endl); | 270 | DEBUGSPEW_CODE(DebugSpew(_U) << "table '"<< _key <<"'" << std::endl); |
271 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope2{ _U }); | 271 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope2{ _U }); |
272 | // un-visit this table in case we do need to process it | 272 | // un-visit this table in case we do need to process it |
273 | lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} | 273 | lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} |
274 | lua_rawget(L_, _cache); // L_: ... {i_} {bfc} k {} n | 274 | lua_rawget(L_, _cache); // L_: ... {i_} {bfc} k {} n |
275 | LUA_ASSERT(L_, lua_type(L_, -1) == LUA_TNUMBER); | 275 | LUA_ASSERT(L_, luaG_type(L_, -1) == LuaType::NUMBER); |
276 | _visit_count = lua_tointeger(L_, -1) - 1; | 276 | _visit_count = lua_tointeger(L_, -1) - 1; |
277 | lua_pop(L_, 1); // L_: ... {i_} {bfc} k {} | 277 | lua_pop(L_, 1); // L_: ... {i_} {bfc} k {} |
278 | lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} | 278 | lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} |
@@ -317,23 +317,23 @@ namespace tools { | |||
317 | int const _dbIdx{ lua_gettop(L_) }; | 317 | int const _dbIdx{ lua_gettop(L_) }; |
318 | STACK_CHECK(L_, 1); | 318 | STACK_CHECK(L_, 1); |
319 | LUA_ASSERT(L_, lua_istable(L_, -1)); | 319 | LUA_ASSERT(L_, lua_istable(L_, -1)); |
320 | if (lua_type(L_, _in_base) == LUA_TFUNCTION) { // for example when a module is a simple function | 320 | if (luaG_type(L_, _in_base) == LuaType::FUNCTION) { // for example when a module is a simple function |
321 | if (_name.empty()) { | 321 | if (_name.empty()) { |
322 | _name = "nullptr"; | 322 | _name = "nullptr"; |
323 | } | 323 | } |
324 | lua_pushvalue(L_, _in_base); // L_: {} f | 324 | lua_pushvalue(L_, _in_base); // L_: {} f |
325 | std::ignore = lua_pushstringview(L_, _name); // L_: {} f name_ | 325 | std::ignore = luaG_pushstringview(L_, _name); // L_: {} f name_ |
326 | lua_rawset(L_, -3); // L_: {} | 326 | lua_rawset(L_, -3); // L_: {} |
327 | std::ignore = lua_pushstringview(L_, _name); // L_: {} name_ | 327 | std::ignore = luaG_pushstringview(L_, _name); // L_: {} name_ |
328 | lua_pushvalue(L_, _in_base); // L_: {} name_ f | 328 | lua_pushvalue(L_, _in_base); // L_: {} name_ f |
329 | lua_rawset(L_, -3); // L_: {} | 329 | lua_rawset(L_, -3); // L_: {} |
330 | lua_pop(L_, 1); // L_: | 330 | lua_pop(L_, 1); // L_: |
331 | } else if (lua_type(L_, _in_base) == LUA_TTABLE) { | 331 | } else if (luaG_type(L_, _in_base) == LuaType::TABLE) { |
332 | lua_newtable(L_); // L_: {} {fqn} | 332 | lua_newtable(L_); // L_: {} {fqn} |
333 | int _startDepth{ 0 }; | 333 | int _startDepth{ 0 }; |
334 | if (!_name.empty()) { | 334 | if (!_name.empty()) { |
335 | STACK_CHECK(L_, 2); | 335 | STACK_CHECK(L_, 2); |
336 | std::ignore = lua_pushstringview(L_, _name); // L_: {} {fqn} "name" | 336 | std::ignore = luaG_pushstringview(L_, _name); // L_: {} {fqn} "name" |
337 | // generate a name, and if we already had one name, keep whichever is the shorter | 337 | // generate a name, and if we already had one name, keep whichever is the shorter |
338 | lua_pushvalue(L_, _in_base); // L_: {} {fqn} "name" t | 338 | lua_pushvalue(L_, _in_base); // L_: {} {fqn} "name" t |
339 | update_lookup_entry(L_, _dbIdx, _startDepth); // L_: {} {fqn} "name" | 339 | update_lookup_entry(L_, _dbIdx, _startDepth); // L_: {} {fqn} "name" |
@@ -348,7 +348,7 @@ namespace tools { | |||
348 | lua_pop(L_, 3); // L_: | 348 | lua_pop(L_, 3); // L_: |
349 | } else { | 349 | } else { |
350 | lua_pop(L_, 1); // L_: | 350 | lua_pop(L_, 1); // L_: |
351 | raise_luaL_error(L_, "unsupported module type %s", lua_typename(L_, lua_type(L_, _in_base))); | 351 | raise_luaL_error(L_, "unsupported module type %s", luaG_typename(L_, luaG_type(L_, _in_base))); |
352 | } | 352 | } |
353 | STACK_CHECK(L_, 0); | 353 | STACK_CHECK(L_, 0); |
354 | } | 354 | } |
@@ -366,7 +366,7 @@ namespace tools { | |||
366 | +[](lua_State* L_) | 366 | +[](lua_State* L_) |
367 | { | 367 | { |
368 | int const _args{ lua_gettop(L_) }; // L_: args... | 368 | int const _args{ lua_gettop(L_) }; // L_: args... |
369 | //[[maybe_unused]] std::string_view const _modname{ luaL_checkstringview(L_, 1) }; | 369 | //[[maybe_unused]] std::string_view const _modname{ luaG_checkstringview(L_, 1) }; |
370 | 370 | ||
371 | STACK_GROW(L_, 1); | 371 | STACK_GROW(L_, 1); |
372 | 372 | ||
diff --git a/src/tracker.cpp b/src/tracker.cpp index d42eb35..618dc37 100644 --- a/src/tracker.cpp +++ b/src/tracker.cpp | |||
@@ -92,7 +92,7 @@ void LaneTracker::tracking_add(Lane* lane_) | |||
92 | while (_lane != TRACKING_END) { | 92 | while (_lane != TRACKING_END) { |
93 | // insert a { name='<name>', status='<status>' } tuple, so that several lanes with the same name can't clobber each other | 93 | // insert a { name='<name>', status='<status>' } tuple, so that several lanes with the same name can't clobber each other |
94 | lua_createtable(L_, 0, 2); // L_: {} {} | 94 | lua_createtable(L_, 0, 2); // L_: {} {} |
95 | std::ignore = lua_pushstringview(L_, _lane->debugName); // L_: {} {} "name" | 95 | std::ignore = luaG_pushstringview(L_, _lane->debugName); // L_: {} {} "name" |
96 | lua_setfield(L_, -2, "name"); // L_: {} {} | 96 | lua_setfield(L_, -2, "name"); // L_: {} {} |
97 | std::ignore = _lane->pushThreadStatus(L_); // L_: {} {} "status" | 97 | std::ignore = _lane->pushThreadStatus(L_); // L_: {} {} "status" |
98 | lua_setfield(L_, -2, "status"); // L_: {} {} | 98 | lua_setfield(L_, -2, "status"); // L_: {} {} |
diff --git a/src/universe.cpp b/src/universe.cpp index 5a52f7e..b4d54b2 100644 --- a/src/universe.cpp +++ b/src/universe.cpp | |||
@@ -136,7 +136,7 @@ Universe::Universe() | |||
136 | 136 | ||
137 | // Initialize 'timerLinda'; a common Linda object shared by all states | 137 | // Initialize 'timerLinda'; a common Linda object shared by all states |
138 | lua_pushcfunction(L_, LG_linda); // L_: settings lanes.linda | 138 | lua_pushcfunction(L_, LG_linda); // L_: settings lanes.linda |
139 | std::ignore = lua_pushstringview(L_, "lanes-timer"); // L_: settings lanes.linda "lanes-timer" | 139 | std::ignore = luaG_pushstringview(L_, "lanes-timer"); // L_: settings lanes.linda "lanes-timer" |
140 | lua_pushinteger(L_, 0); // L_: settings lanes.linda "lanes-timer" 0 | 140 | lua_pushinteger(L_, 0); // L_: settings lanes.linda "lanes-timer" 0 |
141 | lua_call(L_, 2, 1); // L_: settings linda | 141 | lua_call(L_, 2, 1); // L_: settings linda |
142 | STACK_CHECK(L_, 1); | 142 | STACK_CHECK(L_, 1); |
@@ -195,7 +195,7 @@ void Universe::initializeAllocatorFunction(lua_State* const L_) | |||
195 | // when we transfer the config table in newly created Lua states | 195 | // when we transfer the config table in newly created Lua states |
196 | lua_pushnil(L_); // L_: settings allocator nil | 196 | lua_pushnil(L_); // L_: settings allocator nil |
197 | lua_setfield(L_, -3, "allocator"); // L_: settings allocator | 197 | lua_setfield(L_, -3, "allocator"); // L_: settings allocator |
198 | } else if (lua_type(L_, -1) == LUA_TSTRING) { // should be "protected" | 198 | } else if (luaG_type(L_, -1) == LuaType::STRING) { // should be "protected" |
199 | LUA_ASSERT(L_, strcmp(lua_tostring(L_, -1), "protected") == 0); | 199 | LUA_ASSERT(L_, strcmp(lua_tostring(L_, -1), "protected") == 0); |
200 | // set the original allocator to call from inside protection by the mutex | 200 | // set the original allocator to call from inside protection by the mutex |
201 | protectedAllocator.initFrom(L_); | 201 | protectedAllocator.initFrom(L_); |
@@ -211,7 +211,7 @@ void Universe::initializeAllocatorFunction(lua_State* const L_) | |||
211 | STACK_CHECK(L_, 1); | 211 | STACK_CHECK(L_, 1); |
212 | 212 | ||
213 | std::ignore = luaG_getfield(L_, -1, "internal_allocator"); // L_: settings "libc"|"allocator" | 213 | std::ignore = luaG_getfield(L_, -1, "internal_allocator"); // L_: settings "libc"|"allocator" |
214 | std::string_view const _allocator{ lua_tostringview(L_, -1) }; | 214 | std::string_view const _allocator{ luaG_tostringview(L_, -1) }; |
215 | if (_allocator == "libc") { | 215 | if (_allocator == "libc") { |
216 | internalAllocator = AllocatorDefinition{ libc_lua_Alloc, nullptr }; | 216 | internalAllocator = AllocatorDefinition{ libc_lua_Alloc, nullptr }; |
217 | } else if (provideAllocator == luaG_provide_protected_allocator) { | 217 | } else if (provideAllocator == luaG_provide_protected_allocator) { |
@@ -236,7 +236,7 @@ int Universe::InitializeFinalizer(lua_State* const L_) | |||
236 | 236 | ||
237 | // make sure we are only called from the Master Lua State! | 237 | // make sure we are only called from the Master Lua State! |
238 | kUniverseFullRegKey.pushValue(L_); // L_: f U | 238 | kUniverseFullRegKey.pushValue(L_); // L_: f U |
239 | if (lua_type_as_enum(L_, -1) != LuaType::USERDATA) { | 239 | if (luaG_type(L_, -1) != LuaType::USERDATA) { |
240 | raise_luaL_error(L_, "lanes.%s called from inside a lane", kFinally); | 240 | raise_luaL_error(L_, "lanes.%s called from inside a lane", kFinally); |
241 | } | 241 | } |
242 | lua_pop(L_, 1); // L_: f | 242 | lua_pop(L_, 1); // L_: f |
@@ -318,7 +318,7 @@ void Universe::terminateFreeRunningLanes(lua_State* const L_, lua_Duration const | |||
318 | LUAG_FUNC(universe_gc) | 318 | LUAG_FUNC(universe_gc) |
319 | { | 319 | { |
320 | lua_Duration const _shutdown_timeout{ lua_tonumber(L_, lua_upvalueindex(1)) }; | 320 | lua_Duration const _shutdown_timeout{ lua_tonumber(L_, lua_upvalueindex(1)) }; |
321 | std::string_view const _op_string{ lua_tostringview(L_, lua_upvalueindex(2)) }; | 321 | std::string_view const _op_string{ luaG_tostringview(L_, lua_upvalueindex(2)) }; |
322 | STACK_CHECK_START_ABS(L_, 1); | 322 | STACK_CHECK_START_ABS(L_, 1); |
323 | Universe* const _U{ lua_tofulluserdata<Universe>(L_, 1) }; // L_: U | 323 | Universe* const _U{ lua_tofulluserdata<Universe>(L_, 1) }; // L_: U |
324 | _U->terminateFreeRunningLanes(L_, _shutdown_timeout, which_cancel_op(_op_string)); | 324 | _U->terminateFreeRunningLanes(L_, _shutdown_timeout, which_cancel_op(_op_string)); |