diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-10 14:51:17 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-10 14:51:17 +0200 |
commit | 3763be94cdd1a5cf26fec0f09784b18188fd3054 (patch) | |
tree | 3a0e6c1f915e06d51b578d113a759f7e57de875e | |
parent | 770e3c0c533a94631885a4d04d8c36a76d5c185e (diff) | |
download | lanes-3763be94cdd1a5cf26fec0f09784b18188fd3054.tar.gz lanes-3763be94cdd1a5cf26fec0f09784b18188fd3054.tar.bz2 lanes-3763be94cdd1a5cf26fec0f09784b18188fd3054.zip |
luaG_typename returns a std::string_view
-rw-r--r-- | src/compat.h | 13 | ||||
-rw-r--r-- | src/intercopycontext.cpp | 2 | ||||
-rw-r--r-- | src/lane.cpp | 4 | ||||
-rw-r--r-- | src/lanes.cpp | 10 | ||||
-rw-r--r-- | src/state.cpp | 2 | ||||
-rw-r--r-- | src/tools.cpp | 6 |
6 files changed, 22 insertions, 15 deletions
diff --git a/src/compat.h b/src/compat.h index bc8b165..e0a2e6f 100644 --- a/src/compat.h +++ b/src/compat.h | |||
@@ -357,7 +357,7 @@ inline void luaG_setmetatable(lua_State* const L_, std::string_view const& tname | |||
357 | 357 | ||
358 | // a small helper to extract a full userdata pointer from the stack in a safe way | 358 | // a small helper to extract a full userdata pointer from the stack in a safe way |
359 | template <typename T> | 359 | template <typename T> |
360 | [[nodiscard]] T* luaG_tofulluserdata(lua_State* L_, int index_) | 360 | [[nodiscard]] T* luaG_tofulluserdata(lua_State* const L_, int const index_) |
361 | { | 361 | { |
362 | LUA_ASSERT(L_, lua_isnil(L_, index_) || lua_type(L_, index_) == LUA_TUSERDATA); | 362 | LUA_ASSERT(L_, lua_isnil(L_, index_) || lua_type(L_, index_) == LUA_TUSERDATA); |
363 | return static_cast<T*>(lua_touserdata(L_, index_)); | 363 | return static_cast<T*>(lua_touserdata(L_, index_)); |
@@ -366,7 +366,7 @@ template <typename T> | |||
366 | // ------------------------------------------------------------------------------------------------- | 366 | // ------------------------------------------------------------------------------------------------- |
367 | 367 | ||
368 | template <typename T> | 368 | template <typename T> |
369 | [[nodiscard]] auto luaG_tolightuserdata(lua_State* L_, int index_) | 369 | [[nodiscard]] auto luaG_tolightuserdata(lua_State* const L_, int const index_) |
370 | { | 370 | { |
371 | LUA_ASSERT(L_, lua_isnil(L_, index_) || lua_islightuserdata(L_, index_)); | 371 | LUA_ASSERT(L_, lua_isnil(L_, index_) || lua_islightuserdata(L_, index_)); |
372 | if constexpr (std::is_pointer_v<T>) { | 372 | if constexpr (std::is_pointer_v<T>) { |
@@ -378,11 +378,18 @@ template <typename T> | |||
378 | 378 | ||
379 | // ------------------------------------------------------------------------------------------------- | 379 | // ------------------------------------------------------------------------------------------------- |
380 | 380 | ||
381 | inline char const* luaG_typename(lua_State* L_, LuaType t_) | 381 | [[nodiscard]] inline std::string_view luaG_typename(lua_State* const L_, LuaType const t_) |
382 | { | 382 | { |
383 | return lua_typename(L_, static_cast<int>(t_)); | 383 | return lua_typename(L_, static_cast<int>(t_)); |
384 | } | 384 | } |
385 | 385 | ||
386 | // ------------------------------------------------------------------------------------------------- | ||
387 | |||
388 | [[nodiscard]] inline std::string_view luaG_typename(lua_State* const L_, int const idx_) | ||
389 | { | ||
390 | return luaG_typename(L_, luaG_type(L_, idx_)); | ||
391 | } | ||
392 | |||
386 | // ################################################################################################# | 393 | // ################################################################################################# |
387 | 394 | ||
388 | // must keep as a macro as long as we do constant string concatenations | 395 | // must keep as a macro as long as we do constant string concatenations |
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index fcec38a..c7fcf14 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp | |||
@@ -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 | luaG_typename(L2, luaG_type(L2, -1)), | 465 | luaG_typename(L2, -1).data(), |
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 |
diff --git a/src/lane.cpp b/src/lane.cpp index de513c2..3bb98b9 100644 --- a/src/lane.cpp +++ b/src/lane.cpp | |||
@@ -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(), luaG_typename(L_, luaG_type(L_, kKey))); | 348 | raise_luaL_error(L_, "%s[%s]: should not get here!", _lane->debugName.data(), luaG_typename(L_, kKey).data()); |
349 | } | 349 | } |
350 | } | 350 | } |
351 | 351 | ||
@@ -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" : luaG_typename(_L, luaG_type(_L, 1))) << ")" << std::endl); | 686 | DEBUGSPEW_CODE(DebugSpew(_U) << "Lane " << _L << " body: " << GetErrcodeName(_rc) << " (" << (kCancelError.equals(_L, 1) ? "cancelled" : luaG_typename(_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) }; |
diff --git a/src/lanes.cpp b/src/lanes.cpp index b7cd148..9b3b28c 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp | |||
@@ -479,7 +479,7 @@ LUAG_FUNC(lane_new) | |||
479 | STACK_CHECK(_L2, 0); | 479 | STACK_CHECK(_L2, 0); |
480 | 480 | ||
481 | // Lane main function | 481 | // Lane main function |
482 | [[maybe_unused]] int const errorHandlerCount{ _lane->pushErrorHandler() }; // L_: [fixed] args... L2: eh? | 482 | [[maybe_unused]] int const _errorHandlerCount{ _lane->pushErrorHandler() }; // L_: [fixed] args... L2: eh? |
483 | LuaType const _func_type{ luaG_type(L_, kFuncIdx) }; | 483 | LuaType const _func_type{ luaG_type(L_, kFuncIdx) }; |
484 | if (_func_type == LuaType::FUNCTION) { | 484 | if (_func_type == LuaType::FUNCTION) { |
485 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: transfer lane body" << std::endl); | 485 | DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: transfer lane body" << std::endl); |
@@ -497,11 +497,11 @@ LUAG_FUNC(lane_new) | |||
497 | raise_luaL_error(L_, "error when parsing lane function code"); | 497 | raise_luaL_error(L_, "error when parsing lane function code"); |
498 | } | 498 | } |
499 | } else { | 499 | } else { |
500 | raise_luaL_error(L_, "Expected function, got %s", luaG_typename(L_, _func_type)); | 500 | raise_luaL_error(L_, "Expected function, got %s", luaG_typename(L_, _func_type).data()); |
501 | } | 501 | } |
502 | STACK_CHECK(L_, 0); | 502 | STACK_CHECK(L_, 0); |
503 | STACK_CHECK(_L2, errorHandlerCount + 1); | 503 | STACK_CHECK(_L2, _errorHandlerCount + 1); |
504 | LUA_ASSERT(L_, lua_isfunction(_L2, errorHandlerCount + 1)); | 504 | LUA_ASSERT(L_, lua_isfunction(_L2, _errorHandlerCount + 1)); |
505 | 505 | ||
506 | // revive arguments | 506 | // revive arguments |
507 | if (_nargs > 0) { | 507 | if (_nargs > 0) { |
@@ -520,7 +520,7 @@ LUAG_FUNC(lane_new) | |||
520 | kLanePointerRegKey.setValue( | 520 | kLanePointerRegKey.setValue( |
521 | _L2, [lane = _lane](lua_State* L_) { lua_pushlightuserdata(L_, lane); } // L_: [fixed] L2: eh? func args... | 521 | _L2, [lane = _lane](lua_State* L_) { lua_pushlightuserdata(L_, lane); } // L_: [fixed] L2: eh? func args... |
522 | ); | 522 | ); |
523 | STACK_CHECK(_L2, errorHandlerCount + 1 + _nargs); | 523 | STACK_CHECK(_L2, _errorHandlerCount + 1 + _nargs); |
524 | 524 | ||
525 | STACK_CHECK_RESET_REL(L_, 0); | 525 | STACK_CHECK_RESET_REL(L_, 0); |
526 | // all went well, the lane's thread can start working | 526 | // all went well, the lane's thread can start working |
diff --git a/src/state.cpp b/src/state.cpp index 77e1fd9..50981a6 100644 --- a/src/state.cpp +++ b/src/state.cpp | |||
@@ -185,7 +185,7 @@ namespace state { | |||
185 | std::string_view const _stateType{ mode_ == LookupMode::LaneBody ? "lane" : "keeper" }; | 185 | std::string_view const _stateType{ mode_ == LookupMode::LaneBody ? "lane" : "keeper" }; |
186 | std::ignore = luaG_pushstring(L_, _stateType); // L_: on_state_create() "<type>" | 186 | std::ignore = luaG_pushstring(L_, _stateType); // L_: on_state_create() "<type>" |
187 | if (lua_pcall(L_, 1, 0, 0) != LUA_OK) { | 187 | if (lua_pcall(L_, 1, 0, 0) != LUA_OK) { |
188 | raise_luaL_error(from_, "%s failed: \"%s\"", kOnStateCreate, lua_isstring(L_, -1) ? lua_tostring(L_, -1) : luaG_typename(L_, luaG_type(L_, -1))); | 188 | raise_luaL_error(from_, "%s failed: \"%s\"", kOnStateCreate, lua_isstring(L_, -1) ? lua_tostring(L_, -1) : luaG_typename(L_, -1).data()); |
189 | } | 189 | } |
190 | STACK_CHECK(L_, 0); | 190 | STACK_CHECK(L_, 0); |
191 | } | 191 | } |
diff --git a/src/tools.cpp b/src/tools.cpp index efded98..49872f7 100644 --- a/src/tools.cpp +++ b/src/tools.cpp | |||
@@ -158,7 +158,7 @@ static void update_lookup_entry(lua_State* L_, int ctxBase_, int depth_) | |||
158 | // Therefore, when we encounter an object for which a name was previously registered, we need to select the a single name | 158 | // Therefore, when we encounter an object for which a name was previously registered, we need to select the a single name |
159 | // based on some sorting order so that we end up with the same name in all databases whatever order the table walk yielded | 159 | // based on some sorting order so that we end up with the same name in all databases whatever order the table walk yielded |
160 | if (!_prevName.empty() && ((_prevName.size() < _newName.size()) || (_prevName <= _newName))) { | 160 | if (!_prevName.empty() && ((_prevName.size() < _newName.size()) || (_prevName <= _newName))) { |
161 | DEBUGSPEW_CODE(DebugSpew(_U) << luaG_typename(L_, luaG_type(L_, -3)) << " '" << _newName << "' remains named '" << _prevName << "'" << std::endl); | 161 | DEBUGSPEW_CODE(DebugSpew(_U) << luaG_typename(L_, -3) << " '" << _newName << "' remains named '" << _prevName << "'" << std::endl); |
162 | // the previous name is 'smaller' than the one we just generated: keep it! | 162 | // the previous name is 'smaller' than the one we just generated: keep it! |
163 | lua_pop(L_, 3); // L_: ... {bfc} k | 163 | lua_pop(L_, 3); // L_: ... {bfc} k |
164 | } else { | 164 | } else { |
@@ -172,7 +172,7 @@ static void update_lookup_entry(lua_State* L_, int ctxBase_, int depth_) | |||
172 | } else { | 172 | } else { |
173 | lua_remove(L_, -2); // L_: ... {bfc} k o "f.q.n" | 173 | lua_remove(L_, -2); // L_: ... {bfc} k o "f.q.n" |
174 | } | 174 | } |
175 | DEBUGSPEW_CODE(DebugSpew(_U) << luaG_typename(L_, luaG_type(L_, -2)) << " '" << _newName << "'" << std::endl); | 175 | DEBUGSPEW_CODE(DebugSpew(_U) << luaG_typename(L_, -2) << " '" << _newName << "'" << std::endl); |
176 | // prepare the stack for database feed | 176 | // prepare the stack for database feed |
177 | lua_pushvalue(L_, -1); // L_: ... {bfc} k o "f.q.n" "f.q.n" | 177 | lua_pushvalue(L_, -1); // L_: ... {bfc} k o "f.q.n" "f.q.n" |
178 | lua_pushvalue(L_, -3); // L_: ... {bfc} k o "f.q.n" "f.q.n" o | 178 | lua_pushvalue(L_, -3); // L_: ... {bfc} k o "f.q.n" "f.q.n" o |
@@ -349,7 +349,7 @@ namespace tools { | |||
349 | lua_pop(L_, 3); // L_: | 349 | lua_pop(L_, 3); // L_: |
350 | } else { | 350 | } else { |
351 | lua_pop(L_, 1); // L_: | 351 | lua_pop(L_, 1); // L_: |
352 | raise_luaL_error(L_, "unsupported module type %s", luaG_typename(L_, luaG_type(L_, _in_base))); | 352 | raise_luaL_error(L_, "unsupported module type %s", luaG_typename(L_, _in_base).data()); |
353 | } | 353 | } |
354 | STACK_CHECK(L_, 0); | 354 | STACK_CHECK(L_, 0); |
355 | } | 355 | } |