diff options
Diffstat (limited to 'src/tools.cpp')
-rw-r--r-- | src/tools.cpp | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/src/tools.cpp b/src/tools.cpp index aa8f927..2497ba7 100644 --- a/src/tools.cpp +++ b/src/tools.cpp | |||
@@ -130,7 +130,7 @@ void initialize_allocator_function(Universe* U, lua_State* L) | |||
130 | char const* upname = lua_getupvalue(L, -1, 1); // settings allocator upval? | 130 | char const* upname = lua_getupvalue(L, -1, 1); // settings allocator upval? |
131 | if (upname != nullptr) // should be "" for C functions with upvalues if any | 131 | if (upname != nullptr) // should be "" for C functions with upvalues if any |
132 | { | 132 | { |
133 | (void) luaL_error(L, "config.allocator() shouldn't have upvalues"); | 133 | raise_luaL_error(L, "config.allocator() shouldn't have upvalues"); |
134 | } | 134 | } |
135 | // remove this C function from the config table so that it doesn't cause problems | 135 | // remove this C function from the config table so that it doesn't cause problems |
136 | // when we transfer the config table in newly created Lua states | 136 | // when we transfer the config table in newly created Lua states |
@@ -525,7 +525,7 @@ void populate_func_lookup_table(lua_State* L, int i_, char const* name_) | |||
525 | else | 525 | else |
526 | { | 526 | { |
527 | lua_pop(L, 1); // | 527 | lua_pop(L, 1); // |
528 | luaL_error(L, "unsupported module type %s", lua_typename(L, lua_type(L, in_base))); // doesn't return | 528 | raise_luaL_error(L, "unsupported module type %s", lua_typename(L, lua_type(L, in_base))); |
529 | } | 529 | } |
530 | STACK_CHECK(L, 0); | 530 | STACK_CHECK(L, 0); |
531 | } | 531 | } |
@@ -579,7 +579,7 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull }; | |||
579 | // function sentinel used to transfer native functions from/to keeper states | 579 | // function sentinel used to transfer native functions from/to keeper states |
580 | [[nodiscard]] static int func_lookup_sentinel(lua_State* L) | 580 | [[nodiscard]] static int func_lookup_sentinel(lua_State* L) |
581 | { | 581 | { |
582 | return luaL_error(L, "function lookup sentinel for %s, should never be called", lua_tostring(L, lua_upvalueindex(1))); | 582 | raise_luaL_error(L, "function lookup sentinel for %s, should never be called", lua_tostring(L, lua_upvalueindex(1))); |
583 | } | 583 | } |
584 | 584 | ||
585 | // ################################################################################################# | 585 | // ################################################################################################# |
@@ -587,7 +587,7 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull }; | |||
587 | // function sentinel used to transfer native table from/to keeper states | 587 | // function sentinel used to transfer native table from/to keeper states |
588 | [[nodiscard]] static int table_lookup_sentinel(lua_State* L) | 588 | [[nodiscard]] static int table_lookup_sentinel(lua_State* L) |
589 | { | 589 | { |
590 | return luaL_error(L, "table lookup sentinel for %s, should never be called", lua_tostring(L, lua_upvalueindex(1))); | 590 | raise_luaL_error(L, "table lookup sentinel for %s, should never be called", lua_tostring(L, lua_upvalueindex(1))); |
591 | } | 591 | } |
592 | 592 | ||
593 | // ################################################################################################# | 593 | // ################################################################################################# |
@@ -595,7 +595,7 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull }; | |||
595 | // function sentinel used to transfer cloned full userdata from/to keeper states | 595 | // function sentinel used to transfer cloned full userdata from/to keeper states |
596 | [[nodiscard]] static int userdata_clone_sentinel(lua_State* L) | 596 | [[nodiscard]] static int userdata_clone_sentinel(lua_State* L) |
597 | { | 597 | { |
598 | return luaL_error(L, "userdata clone sentinel for %s, should never be called", lua_tostring(L, lua_upvalueindex(1))); | 598 | raise_luaL_error(L, "userdata clone sentinel for %s, should never be called", lua_tostring(L, lua_upvalueindex(1))); |
599 | } | 599 | } |
600 | 600 | ||
601 | // ################################################################################################# | 601 | // ################################################################################################# |
@@ -663,7 +663,7 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull }; | |||
663 | gotchaB = ""; | 663 | gotchaB = ""; |
664 | what = (lua_type( L, -1) == LUA_TSTRING) ? lua_tostring( L, -1) : luaL_typename( L, -1); | 664 | what = (lua_type( L, -1) == LUA_TSTRING) ? lua_tostring( L, -1) : luaL_typename( L, -1); |
665 | } | 665 | } |
666 | (void) luaL_error( L, "%s%s '%s' not found in %s origin transfer database.%s", typewhat, gotchaA, what, from ? from : "main", gotchaB); | 666 | raise_luaL_error(L, "%s%s '%s' not found in %s origin transfer database.%s", typewhat, gotchaA, what, from ? from : "main", gotchaB); |
667 | *len_ = 0; | 667 | *len_ = 0; |
668 | return nullptr; | 668 | return nullptr; |
669 | } | 669 | } |
@@ -689,7 +689,7 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull }; | |||
689 | switch (mode) | 689 | switch (mode) |
690 | { | 690 | { |
691 | default: // shouldn't happen, in theory... | 691 | default: // shouldn't happen, in theory... |
692 | luaL_error(L1, "internal error: unknown lookup mode"); // doesn't return | 692 | raise_luaL_error(L1, "internal error: unknown lookup mode"); |
693 | break; | 693 | break; |
694 | 694 | ||
695 | case LookupMode::ToKeeper: | 695 | case LookupMode::ToKeeper: |
@@ -723,13 +723,13 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull }; | |||
723 | to = lua_tostring(L2, -1); | 723 | to = lua_tostring(L2, -1); |
724 | lua_pop(L2, 1); // {} t | 724 | lua_pop(L2, 1); // {} t |
725 | // when mode_ == LookupMode::FromKeeper, L is a keeper state and L2 is not, therefore L2 is the state where we want to raise the error | 725 | // when mode_ == LookupMode::FromKeeper, L is a keeper state and L2 is not, therefore L2 is the state where we want to raise the error |
726 | luaL_error( | 726 | raise_luaL_error( |
727 | (mode == LookupMode::FromKeeper) ? L2 : L1 | 727 | (mode == LookupMode::FromKeeper) ? L2 : L1 |
728 | , "INTERNAL ERROR IN %s: table '%s' not found in %s destination transfer database." | 728 | , "INTERNAL ERROR IN %s: table '%s' not found in %s destination transfer database." |
729 | , from ? from : "main" | 729 | , from ? from : "main" |
730 | , fqn | 730 | , fqn |
731 | , to ? to : "main" | 731 | , to ? to : "main" |
732 | ); // doesn't return | 732 | ); |
733 | return false; | 733 | return false; |
734 | } | 734 | } |
735 | lua_remove(L2, -2); // t | 735 | lua_remove(L2, -2); // t |
@@ -936,10 +936,10 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull }; | |||
936 | */ | 936 | */ |
937 | int luaG_nameof( lua_State* L) | 937 | int luaG_nameof( lua_State* L) |
938 | { | 938 | { |
939 | int what = lua_gettop( L); | 939 | int const what{ lua_gettop(L) }; |
940 | if (what > 1) | 940 | if (what > 1) |
941 | { | 941 | { |
942 | luaL_argerror( L, what, "too many arguments."); | 942 | raise_luaL_argerror( L, what, "too many arguments."); |
943 | } | 943 | } |
944 | 944 | ||
945 | // nil, boolean, light userdata, number and string aren't identifiable | 945 | // nil, boolean, light userdata, number and string aren't identifiable |
@@ -994,7 +994,7 @@ void InterCopyContext::lookup_native_func() const | |||
994 | switch (mode) | 994 | switch (mode) |
995 | { | 995 | { |
996 | default: // shouldn't happen, in theory... | 996 | default: // shouldn't happen, in theory... |
997 | luaL_error(L1, "internal error: unknown lookup mode"); // doesn't return | 997 | raise_luaL_error(L1, "internal error: unknown lookup mode"); |
998 | break; | 998 | break; |
999 | 999 | ||
1000 | case LookupMode::ToKeeper: | 1000 | case LookupMode::ToKeeper: |
@@ -1022,7 +1022,7 @@ void InterCopyContext::lookup_native_func() const | |||
1022 | to = lua_tostring(L2, -1); | 1022 | to = lua_tostring(L2, -1); |
1023 | lua_pop(L2, 1); // {} f | 1023 | lua_pop(L2, 1); // {} f |
1024 | // when mode_ == LookupMode::FromKeeper, L is a keeper state and L2 is not, therefore L2 is the state where we want to raise the error | 1024 | // when mode_ == LookupMode::FromKeeper, L is a keeper state and L2 is not, therefore L2 is the state where we want to raise the error |
1025 | (void) luaL_error( | 1025 | raise_luaL_error( |
1026 | (mode == LookupMode::FromKeeper) ? L2 : L1 | 1026 | (mode == LookupMode::FromKeeper) ? L2 : L1 |
1027 | , "%s%s: function '%s' not found in %s destination transfer database." | 1027 | , "%s%s: function '%s' not found in %s destination transfer database." |
1028 | , lua_isnil(L2, -1) ? "" : "INTERNAL ERROR IN " | 1028 | , lua_isnil(L2, -1) ? "" : "INTERNAL ERROR IN " |
@@ -1127,7 +1127,7 @@ void InterCopyContext::copy_func() const | |||
1127 | B.L = nullptr; | 1127 | B.L = nullptr; |
1128 | if (lua504_dump(L1, buf_writer, &B, 0) != 0) | 1128 | if (lua504_dump(L1, buf_writer, &B, 0) != 0) |
1129 | { | 1129 | { |
1130 | luaL_error(L1, "internal error: function dump failed."); // doesn't return | 1130 | raise_luaL_error(L1, "internal error: function dump failed."); |
1131 | } | 1131 | } |
1132 | 1132 | ||
1133 | // pushes dumped string on 'L1' | 1133 | // pushes dumped string on 'L1' |
@@ -1173,7 +1173,7 @@ void InterCopyContext::copy_func() const | |||
1173 | // "Otherwise, it pushes an error message" | 1173 | // "Otherwise, it pushes an error message" |
1174 | // | 1174 | // |
1175 | STACK_GROW(L1, 1); | 1175 | STACK_GROW(L1, 1); |
1176 | luaL_error(L1, "%s: %s", name, lua_tostring(L2, -1)); // doesn't return | 1176 | raise_luaL_error(L1, "%s: %s", name, lua_tostring(L2, -1)); |
1177 | } | 1177 | } |
1178 | // remove the dumped string | 1178 | // remove the dumped string |
1179 | lua_pop(L1, 1); // ... | 1179 | lua_pop(L1, 1); // ... |
@@ -1217,7 +1217,7 @@ void InterCopyContext::copy_func() const | |||
1217 | c.L1_i = SourceIndex{ lua_gettop(L1) }; | 1217 | c.L1_i = SourceIndex{ lua_gettop(L1) }; |
1218 | if (!c.inter_copy_one()) // ... {cache} ... function <upvalues> | 1218 | if (!c.inter_copy_one()) // ... {cache} ... function <upvalues> |
1219 | { | 1219 | { |
1220 | luaL_error(L1, "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); // doesn't return | 1220 | raise_luaL_error(L1, "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); |
1221 | } | 1221 | } |
1222 | } | 1222 | } |
1223 | lua_pop(L1, 1); // ... _G | 1223 | lua_pop(L1, 1); // ... _G |
@@ -1335,7 +1335,7 @@ void InterCopyContext::copy_cached_func() const | |||
1335 | InterCopyContext const c{ U, L2, L1, L2_cache_i, SourceIndex{ lua_gettop(L1) }, VT::METATABLE, mode, name }; | 1335 | InterCopyContext const c{ U, L2, L1, L2_cache_i, SourceIndex{ lua_gettop(L1) }, VT::METATABLE, mode, name }; |
1336 | if (!c.inter_copy_one()) // _R[kMtIdRegKey] mt? | 1336 | if (!c.inter_copy_one()) // _R[kMtIdRegKey] mt? |
1337 | { | 1337 | { |
1338 | luaL_error(L1, "Error copying a metatable"); // doesn't return | 1338 | raise_luaL_error(L1, "Error copying a metatable"); |
1339 | } | 1339 | } |
1340 | 1340 | ||
1341 | STACK_CHECK(L2, 2); // _R[kMtIdRegKey] mt | 1341 | STACK_CHECK(L2, 2); // _R[kMtIdRegKey] mt |
@@ -1371,7 +1371,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
1371 | { | 1371 | { |
1372 | return; | 1372 | return; |
1373 | // we could raise an error instead of ignoring the table entry, like so: | 1373 | // we could raise an error instead of ignoring the table entry, like so: |
1374 | //luaL_error(L1, "Unable to copy %s key '%s' because of value is of type '%s'", (vt == VT::NORMAL) ? "table" : "metatable", name, luaL_typename(L1, key_i)); // doesn't return | 1374 | //raise_luaL_error(L1, "Unable to copy %s key '%s' because of value is of type '%s'", (vt == VT::NORMAL) ? "table" : "metatable", name, luaL_typename(L1, key_i)); |
1375 | // maybe offer this possibility as a global configuration option, or a linda setting, or as a parameter of the call causing the transfer? | 1375 | // maybe offer this possibility as a global configuration option, or a linda setting, or as a parameter of the call causing the transfer? |
1376 | } | 1376 | } |
1377 | 1377 | ||
@@ -1426,7 +1426,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
1426 | } | 1426 | } |
1427 | else | 1427 | else |
1428 | { | 1428 | { |
1429 | luaL_error(L1, "Unable to copy %s entry '%s' because of value is of type '%s'", (vt == VT::NORMAL) ? "table" : "metatable", valPath, luaL_typename(L1, val_i)); | 1429 | raise_luaL_error(L1, "Unable to copy %s entry '%s' because of value is of type '%s'", (vt == VT::NORMAL) ? "table" : "metatable", valPath, luaL_typename(L1, val_i)); |
1430 | } | 1430 | } |
1431 | } | 1431 | } |
1432 | 1432 | ||
@@ -1504,7 +1504,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
1504 | } | 1504 | } |
1505 | else | 1505 | else |
1506 | { | 1506 | { |
1507 | luaL_error(L1, "Error copying a metatable"); // doesn't return | 1507 | raise_luaL_error(L1, "Error copying a metatable"); |
1508 | } | 1508 | } |
1509 | // first, add the entry in the cache (at this point it is either the actual userdata or the keeper sentinel | 1509 | // first, add the entry in the cache (at this point it is either the actual userdata or the keeper sentinel |
1510 | lua_pushlightuserdata( L2, source); // ... u source | 1510 | lua_pushlightuserdata( L2, source); // ... u source |
@@ -1521,7 +1521,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
1521 | c.L1_i = SourceIndex{ lua_absindex(L1, -1) }; | 1521 | c.L1_i = SourceIndex{ lua_absindex(L1, -1) }; |
1522 | if (!c.inter_copy_one()) // ... u uv | 1522 | if (!c.inter_copy_one()) // ... u uv |
1523 | { | 1523 | { |
1524 | luaL_error(L1, "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); // doesn't return | 1524 | raise_luaL_error(L1, "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); |
1525 | } | 1525 | } |
1526 | lua_pop(L1, 1); // ... mt __lanesclone [uv]* | 1526 | lua_pop(L1, 1); // ... mt __lanesclone [uv]* |
1527 | // this pops the value from the stack | 1527 | // this pops the value from the stack |
@@ -1591,7 +1591,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
1591 | } | 1591 | } |
1592 | else // raise an error | 1592 | else // raise an error |
1593 | { | 1593 | { |
1594 | luaL_error(L1, "can't copy non-deep full userdata across lanes"); // doesn't return | 1594 | raise_luaL_error(L1, "can't copy non-deep full userdata across lanes"); |
1595 | } | 1595 | } |
1596 | 1596 | ||
1597 | STACK_CHECK(L2, 1); | 1597 | STACK_CHECK(L2, 1); |
@@ -1667,7 +1667,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
1667 | c.L1_i = SourceIndex{ lua_absindex(L1, -1) }; | 1667 | c.L1_i = SourceIndex{ lua_absindex(L1, -1) }; |
1668 | if (!c.inter_copy_one()) // ... mt u uv | 1668 | if (!c.inter_copy_one()) // ... mt u uv |
1669 | { | 1669 | { |
1670 | luaL_error(L1, "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); // doesn't return | 1670 | raise_luaL_error(L1, "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); |
1671 | } | 1671 | } |
1672 | lua_pop(L1, 1); // ... u [uv]* | 1672 | lua_pop(L1, 1); // ... u [uv]* |
1673 | // this pops the value from the stack | 1673 | // this pops the value from the stack |
@@ -2010,7 +2010,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
2010 | // raise the error when copying from lane to lane, else just leave it on the stack to be raised later | 2010 | // raise the error when copying from lane to lane, else just leave it on the stack to be raised later |
2011 | if (mode == LookupMode::LaneBody) | 2011 | if (mode == LookupMode::LaneBody) |
2012 | { | 2012 | { |
2013 | lua_error(L1); // doesn't return | 2013 | raise_lua_error(L1); |
2014 | } | 2014 | } |
2015 | return InterCopyResult::Error; | 2015 | return InterCopyResult::Error; |
2016 | } | 2016 | } |
@@ -2057,7 +2057,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
2057 | // raise the error when copying from lane to lane, else just leave it on the stack to be raised later | 2057 | // raise the error when copying from lane to lane, else just leave it on the stack to be raised later |
2058 | if (mode == LookupMode::LaneBody) | 2058 | if (mode == LookupMode::LaneBody) |
2059 | { | 2059 | { |
2060 | lua_error(L1); // doesn't return | 2060 | raise_lua_error(L1); |
2061 | } | 2061 | } |
2062 | lua_pop(L1, 1); | 2062 | lua_pop(L1, 1); |
2063 | break; | 2063 | break; |