diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-07 11:46:25 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-07 11:46:25 +0200 |
commit | ee32d4281a5e59ce81d7f38f86a49fa8ff64d2c3 (patch) | |
tree | 68c0d74ac40c6ee098abf606e3d660a862acf04f /src/tools.cpp | |
parent | 35d7a6bb691d7e0564cda324b3d724caf4901545 (diff) | |
download | lanes-ee32d4281a5e59ce81d7f38f86a49fa8ff64d2c3.tar.gz lanes-ee32d4281a5e59ce81d7f38f86a49fa8ff64d2c3.tar.bz2 lanes-ee32d4281a5e59ce81d7f38f86a49fa8ff64d2c3.zip |
Boyscouting some luaG_ functions
Diffstat (limited to 'src/tools.cpp')
-rw-r--r-- | src/tools.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/tools.cpp b/src/tools.cpp index 1afc2b8..efded98 100644 --- a/src/tools.cpp +++ b/src/tools.cpp | |||
@@ -112,7 +112,7 @@ namespace tools { | |||
112 | // &b is popped at that point (-> replaced by the result) | 112 | // &b is popped at that point (-> replaced by the result) |
113 | luaL_pushresult(&_b); // L_: ... {} ... "<result>" | 113 | luaL_pushresult(&_b); // L_: ... {} ... "<result>" |
114 | STACK_CHECK(L_, 1); | 114 | STACK_CHECK(L_, 1); |
115 | return luaG_tostringview(L_, -1); | 115 | return luaG_tostring(L_, -1); |
116 | } | 116 | } |
117 | 117 | ||
118 | } // namespace tools | 118 | } // namespace tools |
@@ -142,7 +142,7 @@ static void update_lookup_entry(lua_State* L_, int ctxBase_, int depth_) | |||
142 | // first, raise an error if the function is already known | 142 | // first, raise an error if the function is already known |
143 | lua_pushvalue(L_, -1); // L_: ... {bfc} k o o | 143 | lua_pushvalue(L_, -1); // L_: ... {bfc} k o o |
144 | lua_rawget(L_, _dest); // L_: ... {bfc} k o name? | 144 | lua_rawget(L_, _dest); // L_: ... {bfc} k o name? |
145 | std::string_view const _prevName{ luaG_tostringview(L_, -1) }; // nullptr if we got nil (first encounter of this object) | 145 | std::string_view const _prevName{ luaG_tostring(L_, -1) }; // nullptr if we got nil (first encounter of this object) |
146 | // push name in fqn stack (note that concatenation will crash if name is a not string or a number) | 146 | // push name in fqn stack (note that concatenation will crash if name is a not string or a number) |
147 | lua_pushvalue(L_, -3); // L_: ... {bfc} k o name? k | 147 | lua_pushvalue(L_, -3); // L_: ... {bfc} k o name? k |
148 | LUA_ASSERT(L_, luaG_type(L_, -1) == LuaType::NUMBER || luaG_type(L_, -1) == LuaType::STRING); | 148 | LUA_ASSERT(L_, luaG_type(L_, -1) == LuaType::NUMBER || luaG_type(L_, -1) == LuaType::STRING); |
@@ -237,7 +237,7 @@ static void populate_func_lookup_table_recur(lua_State* L_, int dbIdx_, int i_, | |||
237 | lua_pushnil(L_); // L_: ... {i_} {bfc} nil | 237 | lua_pushnil(L_); // L_: ... {i_} {bfc} nil |
238 | while (lua_next(L_, i_) != 0) { // L_: ... {i_} {bfc} k v | 238 | while (lua_next(L_, i_) != 0) { // L_: ... {i_} {bfc} k v |
239 | // just for debug, not actually needed | 239 | // just for debug, not actually needed |
240 | // std::string_view const _key{ (luaG_type(L_, -2) == LuaType::STRING) ? luaG_tostringview(L_, -2) : "not a string" }; | 240 | // std::string_view const _key{ (luaG_type(L_, -2) == LuaType::STRING) ? luaG_tostring(L_, -2) : "not a string" }; |
241 | // subtable: process it recursively | 241 | // subtable: process it recursively |
242 | if (lua_istable(L_, -1)) { // L_: ... {i_} {bfc} k {} | 242 | if (lua_istable(L_, -1)) { // L_: ... {i_} {bfc} k {} |
243 | // increment visit count to make sure we will actually scan it at this recursive level | 243 | // increment visit count to make sure we will actually scan it at this recursive level |
@@ -267,7 +267,7 @@ static void populate_func_lookup_table_recur(lua_State* L_, int dbIdx_, int i_, | |||
267 | ++depth_; | 267 | ++depth_; |
268 | lua_pushnil(L_); // L_: ... {i_} {bfc} nil | 268 | lua_pushnil(L_); // L_: ... {i_} {bfc} nil |
269 | while (lua_next(L_, breadthFirstCache) != 0) { // L_: ... {i_} {bfc} k {} | 269 | while (lua_next(L_, breadthFirstCache) != 0) { // L_: ... {i_} {bfc} k {} |
270 | 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(std::string_view const _key{ (luaG_type(L_, -2) == LuaType::STRING) ? luaG_tostring(L_, -2) : std::string_view{ "<not a string>" } }); |
271 | DEBUGSPEW_CODE(DebugSpew(_U) << "table '"<< _key <<"'" << std::endl); | 271 | DEBUGSPEW_CODE(DebugSpew(_U) << "table '"<< _key <<"'" << std::endl); |
272 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope2{ _U }); | 272 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope2{ _U }); |
273 | // un-visit this table in case we do need to process it | 273 | // un-visit this table in case we do need to process it |
@@ -323,9 +323,9 @@ namespace tools { | |||
323 | _name = "nullptr"; | 323 | _name = "nullptr"; |
324 | } | 324 | } |
325 | lua_pushvalue(L_, _in_base); // L_: {} f | 325 | lua_pushvalue(L_, _in_base); // L_: {} f |
326 | std::ignore = luaG_pushstringview(L_, _name); // L_: {} f name_ | 326 | std::ignore = luaG_pushstring(L_, _name); // L_: {} f name_ |
327 | lua_rawset(L_, -3); // L_: {} | 327 | lua_rawset(L_, -3); // L_: {} |
328 | std::ignore = luaG_pushstringview(L_, _name); // L_: {} name_ | 328 | std::ignore = luaG_pushstring(L_, _name); // L_: {} name_ |
329 | lua_pushvalue(L_, _in_base); // L_: {} name_ f | 329 | lua_pushvalue(L_, _in_base); // L_: {} name_ f |
330 | lua_rawset(L_, -3); // L_: {} | 330 | lua_rawset(L_, -3); // L_: {} |
331 | lua_pop(L_, 1); // L_: | 331 | lua_pop(L_, 1); // L_: |
@@ -334,7 +334,7 @@ namespace tools { | |||
334 | int _startDepth{ 0 }; | 334 | int _startDepth{ 0 }; |
335 | if (!_name.empty()) { | 335 | if (!_name.empty()) { |
336 | STACK_CHECK(L_, 2); | 336 | STACK_CHECK(L_, 2); |
337 | std::ignore = luaG_pushstringview(L_, _name); // L_: {} {fqn} "name" | 337 | std::ignore = luaG_pushstring(L_, _name); // L_: {} {fqn} "name" |
338 | // generate a name, and if we already had one name, keep whichever is the shorter | 338 | // generate a name, and if we already had one name, keep whichever is the shorter |
339 | lua_pushvalue(L_, _in_base); // L_: {} {fqn} "name" t | 339 | lua_pushvalue(L_, _in_base); // L_: {} {fqn} "name" t |
340 | update_lookup_entry(L_, _dbIdx, _startDepth); // L_: {} {fqn} "name" | 340 | update_lookup_entry(L_, _dbIdx, _startDepth); // L_: {} {fqn} "name" |
@@ -367,7 +367,7 @@ namespace tools { | |||
367 | +[](lua_State* L_) | 367 | +[](lua_State* L_) |
368 | { | 368 | { |
369 | int const _args{ lua_gettop(L_) }; // L_: args... | 369 | int const _args{ lua_gettop(L_) }; // L_: args... |
370 | //[[maybe_unused]] std::string_view const _modname{ luaG_checkstringview(L_, 1) }; | 370 | //[[maybe_unused]] std::string_view const _modname{ luaG_checkstring(L_, 1) }; |
371 | 371 | ||
372 | STACK_GROW(L_, 1); | 372 | STACK_GROW(L_, 1); |
373 | 373 | ||