diff options
Diffstat (limited to 'src/lane.cpp')
-rw-r--r-- | src/lane.cpp | 32 |
1 files changed, 16 insertions, 16 deletions
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); |