diff options
Diffstat (limited to 'src/lane.cpp')
-rw-r--r-- | src/lane.cpp | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/src/lane.cpp b/src/lane.cpp index e838b7d..d68da76 100644 --- a/src/lane.cpp +++ b/src/lane.cpp | |||
@@ -216,7 +216,7 @@ static int thread_index_number(lua_State* L_) | |||
216 | // this is an internal error, we probably never get here | 216 | // this is an internal error, we probably never get here |
217 | lua_settop(L_, 0); // L_: | 217 | lua_settop(L_, 0); // L_: |
218 | lua_pushliteral(L_, "Unexpected status: "); // L_: "Unexpected status: " | 218 | lua_pushliteral(L_, "Unexpected status: "); // L_: "Unexpected status: " |
219 | _lane->pushThreadStatus(L_); // L_: "Unexpected status: " "<status>" | 219 | std::ignore = _lane->pushThreadStatus(L_); // L_: "Unexpected status: " "<status>" |
220 | lua_concat(L_, 2); // L_: "Unexpected status: <status>" | 220 | lua_concat(L_, 2); // L_: "Unexpected status: <status>" |
221 | raise_lua_error(L_); | 221 | raise_lua_error(L_); |
222 | 222 | ||
@@ -300,14 +300,14 @@ 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 | char const* const _keystr{ lua_tostring(L_, kKey) }; | 303 | std::string_view const _keystr{ lua_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 (strcmp(_keystr, "status") == 0) { | 305 | if (_keystr == "status") { |
306 | _lane->pushThreadStatus(L_); // L_: lane "key" "<status>" | 306 | std::ignore = _lane->pushThreadStatus(L_); // L_: lane "key" "<status>" |
307 | return 1; | 307 | return 1; |
308 | } | 308 | } |
309 | if (strcmp(_keystr, "error_trace_level") == 0) { | 309 | if (_keystr == "error_trace_level") { |
310 | _lane->pushErrorTraceLevel(L_); // L_: lane "key" "<level>" | 310 | std::ignore = _lane->pushErrorTraceLevel(L_); // L_: lane "key" "<level>" |
311 | return 1; | 311 | return 1; |
312 | } | 312 | } |
313 | // return self.metatable[key] | 313 | // return self.metatable[key] |
@@ -316,7 +316,7 @@ static int thread_index_string(lua_State* L_) | |||
316 | lua_rawget(L_, -2); // L_: mt value | 316 | lua_rawget(L_, -2); // L_: mt value |
317 | // only "cancel" and "join" are registered as functions, any other string will raise an error | 317 | // only "cancel" and "join" are registered as functions, any other string will raise an error |
318 | if (!lua_iscfunction(L_, -1)) { | 318 | if (!lua_iscfunction(L_, -1)) { |
319 | raise_luaL_error(L_, "can't index a lane with '%s'", _keystr); | 319 | raise_luaL_error(L_, "can't index a lane with '%s'", _keystr.data()); |
320 | } | 320 | } |
321 | return 1; | 321 | return 1; |
322 | } | 322 | } |
@@ -833,9 +833,9 @@ void Lane::changeDebugName(int nameIdx_) | |||
833 | // / "error" finished at an error, error value is there | 833 | // / "error" finished at an error, error value is there |
834 | // / "cancelled" execution cancelled by M (state gone) | 834 | // / "cancelled" execution cancelled by M (state gone) |
835 | // | 835 | // |
836 | [[nodiscard]] char const* Lane::errorTraceLevelString() const | 836 | [[nodiscard]] std::string_view Lane::errorTraceLevelString() const |
837 | { | 837 | { |
838 | char const* const _str{ | 838 | std::string_view const _str{ |
839 | (errorTraceLevel == ErrorTraceLevel::Minimal) ? "minimal" : | 839 | (errorTraceLevel == ErrorTraceLevel::Minimal) ? "minimal" : |
840 | (errorTraceLevel == ErrorTraceLevel::Basic) ? "basic" : | 840 | (errorTraceLevel == ErrorTraceLevel::Basic) ? "basic" : |
841 | (errorTraceLevel == ErrorTraceLevel::Extended) ? "extended" : | 841 | (errorTraceLevel == ErrorTraceLevel::Extended) ? "extended" : |
@@ -890,22 +890,22 @@ void Lane::PushMetatable(lua_State* L_) | |||
890 | 890 | ||
891 | // ################################################################################################# | 891 | // ################################################################################################# |
892 | 892 | ||
893 | void Lane::pushThreadStatus(lua_State* L_) const | 893 | [[nodiscard]] std::string_view Lane::pushThreadStatus(lua_State* L_) const |
894 | { | 894 | { |
895 | char const* const _str{ threadStatusString() }; | 895 | std::string_view const _str{ threadStatusString() }; |
896 | LUA_ASSERT(L_, _str); | 896 | LUA_ASSERT(L_, !_str.empty()); |
897 | 897 | ||
898 | lua_pushstring(L_, _str); | 898 | return lua_pushstringview(L_, _str); |
899 | } | 899 | } |
900 | 900 | ||
901 | // ################################################################################################# | 901 | // ################################################################################################# |
902 | 902 | ||
903 | void Lane::pushErrorTraceLevel(lua_State* L_) const | 903 | [[nodiscard]] std::string_view Lane::pushErrorTraceLevel(lua_State* L_) const |
904 | { | 904 | { |
905 | char const* const _str{ errorTraceLevelString() }; | 905 | std::string_view const _str{ errorTraceLevelString() }; |
906 | LUA_ASSERT(L_, _str); | 906 | LUA_ASSERT(L_, !_str.empty()); |
907 | 907 | ||
908 | lua_pushstring(L_, _str); | 908 | return lua_pushstringview(L_, _str); |
909 | } | 909 | } |
910 | 910 | ||
911 | // ################################################################################################# | 911 | // ################################################################################################# |
@@ -948,9 +948,9 @@ void Lane::startThread(int priority_) | |||
948 | // / "error" finished at an error, error value is there | 948 | // / "error" finished at an error, error value is there |
949 | // / "cancelled" execution cancelled by M (state gone) | 949 | // / "cancelled" execution cancelled by M (state gone) |
950 | // | 950 | // |
951 | [[nodiscard]] char const* Lane::threadStatusString() const | 951 | [[nodiscard]] std::string_view Lane::threadStatusString() const |
952 | { | 952 | { |
953 | char const* const _str{ | 953 | std::string_view const _str{ |
954 | (status == Lane::Pending) ? "pending" : | 954 | (status == Lane::Pending) ? "pending" : |
955 | (status == Lane::Running) ? "running" : // like in 'co.status()' | 955 | (status == Lane::Running) ? "running" : // like in 'co.status()' |
956 | (status == Lane::Waiting) ? "waiting" : | 956 | (status == Lane::Waiting) ? "waiting" : |