From 408f8a5bf7934e7a5aa113fd3a55899db70dd73a Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Wed, 10 Apr 2024 09:48:59 +0200 Subject: C++ migration: luaG_inter_copy_* now return an enum class instead of an anonymous int --- src/cancel.cpp | 2 +- src/deep.cpp | 2 +- src/keeper.cpp | 12 ++++++------ src/lanes.cpp | 36 ++++++++++++++++++------------------ src/linda.cpp | 2 +- src/macros_and_utils.h | 8 ++++---- src/state.cpp | 34 ++++++++++++++++++++++++---------- src/tools.cpp | 38 ++++++++++++++++++++++++-------------- src/tools.h | 23 ++++++++++++++--------- 9 files changed, 93 insertions(+), 64 deletions(-) (limited to 'src') diff --git a/src/cancel.cpp b/src/cancel.cpp index 3a01ac2..b3e52b6 100644 --- a/src/cancel.cpp +++ b/src/cancel.cpp @@ -213,7 +213,7 @@ CancelOp which_cancel_op(char const* op_string_) lua_remove(L, idx_); // argument is processed, remove it if (op == CancelOp::Invalid) { - std::ignore = luaL_error(L, "invalid hook option %s", str); // doesn't return + luaL_error(L, "invalid hook option %s", str); // doesn't return } return op; } diff --git a/src/deep.cpp b/src/deep.cpp index 418724e..d0b8123 100644 --- a/src/deep.cpp +++ b/src/deep.cpp @@ -488,7 +488,7 @@ bool copydeep(Universe* U, Dest L2, int L2_cache_i, Source L, int i, LookupMode { // raise the error in the proper state (not the keeper) lua_State* const errL{ (mode_ == LookupMode::FromKeeper) ? L2 : L }; - std::ignore = luaL_error(errL, errmsg); // doesn't return + luaL_error(errL, errmsg); // doesn't return } return true; } \ No newline at end of file diff --git a/src/keeper.cpp b/src/keeper.cpp index 37fcba5..f56c50c 100644 --- a/src/keeper.cpp +++ b/src/keeper.cpp @@ -656,7 +656,7 @@ void init_keepers(Universe* U, lua_State* L) lua_pop(L, 1); // if (nb_keepers < 1) { - std::ignore = luaL_error(L, "Bad number of keepers (%d)", nb_keepers); // doesn't return + luaL_error(L, "Bad number of keepers (%d)", nb_keepers); // doesn't return } STACK_CHECK(L, 0); @@ -671,7 +671,7 @@ void init_keepers(Universe* U, lua_State* L) U->keepers = static_cast(U->internal_allocator.alloc(bytes)); if (U->keepers == nullptr) { - std::ignore = luaL_error(L, "init_keepers() failed while creating keeper array; out of memory"); // doesn't return + luaL_error(L, "init_keepers() failed while creating keeper array; out of memory"); // doesn't return } U->keepers->Keepers::Keepers(); U->keepers->gc_threshold = keepers_gc_threshold; @@ -688,7 +688,7 @@ void init_keepers(Universe* U, lua_State* L) lua_State* const K{ create_state(U, L) }; if (K == nullptr) { - std::ignore = luaL_error(L, "init_keepers() failed while creating keeper states; out of memory"); // doesn't return + luaL_error(L, "init_keepers() failed while creating keeper states; out of memory"); // doesn't return } U->keepers->keeper_array[i].L = K; @@ -717,7 +717,7 @@ void init_keepers(Universe* U, lua_State* L) if (!lua_isnil(L, -1)) { // when copying with mode LookupMode::ToKeeper, error message is pushed at the top of the stack, not raised immediately - if (luaG_inter_copy_package(U, Source{ L }, Dest{ K }, -1, LookupMode::ToKeeper)) + if (luaG_inter_copy_package(U, Source{ L }, Dest{ K }, -1, LookupMode::ToKeeper) != InterCopyResult::Success) { // if something went wrong, the error message is at the top of the stack lua_remove(L, -2); // error_msg @@ -840,7 +840,7 @@ int keeper_call(Universe* U, lua_State* K, keeper_api_t func_, lua_State* L, voi lua_pushlightuserdata(K, linda); - if ((args == 0) || luaG_inter_copy(U, Source{ L }, Dest{ K }, args, LookupMode::ToKeeper) == 0) // L->K + if ((args == 0) || luaG_inter_copy(U, Source{ L }, Dest{ K }, args, LookupMode::ToKeeper) == InterCopyResult::Success) // L->K { lua_call(K, 1 + args, LUA_MULTRET); retvals = lua_gettop(K) - Ktos; @@ -848,7 +848,7 @@ int keeper_call(Universe* U, lua_State* K, keeper_api_t func_, lua_State* L, voi // this may interrupt a lane, causing the destruction of the underlying OS thread // after this, another lane making use of this keeper can get an error code from the mutex-locking function // when attempting to grab the mutex again (WINVER <= 0x400 does this, but locks just fine, I don't know about pthread) - if ((retvals > 0) && luaG_inter_move(U, Source{ K }, Dest{ L }, retvals, LookupMode::FromKeeper) != 0) // K->L + if ((retvals > 0) && luaG_inter_move(U, Source{ K }, Dest{ L }, retvals, LookupMode::FromKeeper) != InterCopyResult::Success) // K->L { retvals = -1; } diff --git a/src/lanes.cpp b/src/lanes.cpp index f549359..462de0f 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp @@ -540,7 +540,7 @@ static void selfdestruct_add(Lane* lane_) if (lane != SELFDESTRUCT_END) { // this causes a leak because we don't call U's destructor (which could be bad if the still running lanes are accessing it) - std::ignore = luaL_error(L, "Zombie thread %s refuses to die!", lane->debug_name); // doesn't return + luaL_error(L, "Zombie thread %s refuses to die!", lane->debug_name); // doesn't return } } @@ -1134,7 +1134,8 @@ LUAG_FUNC(lane_new) { DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lane_new: update 'package'\n" INDENT_END)); // when copying with mode LookupMode::LaneBody, should raise an error in case of problem, not leave it one the stack - std::ignore = luaG_inter_copy_package(U, Source{ L }, Dest{ L2 }, package_idx, LookupMode::LaneBody); + [[maybe_unused]] InterCopyResult const ret{ luaG_inter_copy_package(U, Source{ L }, Dest{ L2 }, package_idx, LookupMode::LaneBody) }; + ASSERT_L(ret == InterCopyResult::Success); // either all went well, or we should not even get here } // modules to require in the target lane *before* the function is transfered! @@ -1146,7 +1147,7 @@ LUAG_FUNC(lane_new) // should not happen, was checked in lanes.lua before calling lane_new() if (lua_type(L, required_idx) != LUA_TTABLE) { - return luaL_error(L, "expected required module list as a table, got %s", luaL_typename(L, required_idx)); + luaL_error(L, "expected required module list as a table, got %s", luaL_typename(L, required_idx)); // doesn't return } lua_pushnil(L); // func libs priority globals package required gc_cb [... args ...] nil @@ -1154,7 +1155,7 @@ LUAG_FUNC(lane_new) { if (lua_type(L, -1) != LUA_TSTRING || lua_type(L, -2) != LUA_TNUMBER || lua_tonumber(L, -2) != nbRequired) { - return luaL_error(L, "required module list should be a list of strings"); + luaL_error(L, "required module list should be a list of strings"); // doesn't return } else { @@ -1168,7 +1169,7 @@ LUAG_FUNC(lane_new) if (lua_isnil( L2, -1)) { lua_pop( L2, 1); // - return luaL_error(L, "cannot pre-require modules without loading 'package' library first"); + luaL_error(L, "cannot pre-require modules without loading 'package' library first"); // doesn't return } else { @@ -1203,7 +1204,7 @@ LUAG_FUNC(lane_new) DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lane_new: transfer globals\n" INDENT_END)); if (!lua_istable(L, globals_idx)) { - return luaL_error(L, "Expected table, got %s", luaL_typename(L, globals_idx)); + luaL_error(L, "Expected table, got %s", luaL_typename(L, globals_idx)); // doesn't return } DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_add(1, std::memory_order_relaxed)); @@ -1230,11 +1231,11 @@ LUAG_FUNC(lane_new) DEBUGSPEW_CODE(fprintf( stderr, INDENT_BEGIN "lane_new: transfer lane body\n" INDENT_END)); DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_add(1, std::memory_order_relaxed)); lua_pushvalue(L, 1); // func libs priority globals package required gc_cb [... args ...] func - int const res{ luaG_inter_move(U, Source{ L }, Dest{ L2 }, 1, LookupMode::LaneBody) }; // func libs priority globals package required gc_cb [... args ...] // func + InterCopyResult const res{ luaG_inter_move(U, Source{ L }, Dest{ L2 }, 1, LookupMode::LaneBody) }; // func libs priority globals package required gc_cb [... args ...] // func DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_sub(1, std::memory_order_relaxed)); - if (res != 0) + if (res != InterCopyResult::Success) { - return luaL_error(L, "tried to copy unsupported types"); + luaL_error(L, "tried to copy unsupported types"); // doesn't return } } else if (lua_type(L, 1) == LUA_TSTRING) @@ -1243,7 +1244,7 @@ LUAG_FUNC(lane_new) // compile the string if (luaL_loadstring(L2, lua_tostring(L, 1)) != 0) // func { - return luaL_error(L, "error when parsing lane function code"); + luaL_error(L, "error when parsing lane function code"); // doesn't return } } STACK_CHECK(L, 0); @@ -1253,14 +1254,13 @@ LUAG_FUNC(lane_new) // revive arguments if (nargs > 0) { - int res; DEBUGSPEW_CODE(fprintf( stderr, INDENT_BEGIN "lane_new: transfer lane arguments\n" INDENT_END)); DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_add(1, std::memory_order_relaxed)); - res = luaG_inter_move(U, Source{ L }, Dest{ L2 }, nargs, LookupMode::LaneBody); // func libs priority globals package required gc_cb // func [... args ...] + InterCopyResult const res{ luaG_inter_move(U, Source{ L }, Dest{ L2 }, nargs, LookupMode::LaneBody) }; // func libs priority globals package required gc_cb // func [... args ...] DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_sub(1, std::memory_order_relaxed)); - if (res != 0) + if (res != InterCopyResult::Success) { - return luaL_error(L, "tried to copy unsupported types"); + luaL_error(L, "tried to copy unsupported types"); // doesn't return } } STACK_CHECK(L, -nargs); @@ -1420,9 +1420,9 @@ LUAG_FUNC(thread_join) case Lane::Done: { int const n{ lua_gettop(L2) }; // whole L2 stack - if ((n > 0) && (luaG_inter_move(U, Source{ L2 }, Dest{ L }, n, LookupMode::LaneBody) != 0)) + if ((n > 0) && (luaG_inter_move(U, Source{ L2 }, Dest{ L }, n, LookupMode::LaneBody) != InterCopyResult::Success)) { - return luaL_error(L, "tried to copy unsupported types"); + luaL_error(L, "tried to copy unsupported types"); // doesn't return } ret = n; } @@ -1434,9 +1434,9 @@ LUAG_FUNC(thread_join) STACK_GROW(L, 3); lua_pushnil(L); // even when ERROR_FULL_STACK, if the error is not LUA_ERRRUN, the handler wasn't called, and we only have 1 error message on the stack ... - if (luaG_inter_move(U, Source{ L2 }, Dest{ L }, n, LookupMode::LaneBody) != 0) // nil "err" [trace] + if (luaG_inter_move(U, Source{ L2 }, Dest{ L }, n, LookupMode::LaneBody) != InterCopyResult::Success) // nil "err" [trace] { - return luaL_error(L, "tried to copy unsupported types: %s", lua_tostring(L, -n)); + luaL_error(L, "tried to copy unsupported types: %s", lua_tostring(L, -n)); // doesn't return } ret = 1 + n; } diff --git a/src/linda.cpp b/src/linda.cpp index 50964ad..e749f52 100644 --- a/src/linda.cpp +++ b/src/linda.cpp @@ -162,7 +162,7 @@ static void check_key_types(lua_State* L, int start_, int end_) { continue; } - std::ignore = luaL_error(L, "argument #%d: invalid key type (not a boolean, string, number or light userdata)", i); + luaL_error(L, "argument #%d: invalid key type (not a boolean, string, number or light userdata)", i); // doesn't return } } diff --git a/src/macros_and_utils.h b/src/macros_and_utils.h index 31ae8bd..99e49f9 100644 --- a/src/macros_and_utils.h +++ b/src/macros_and_utils.h @@ -77,7 +77,7 @@ class StackChecker if ((offset_ < 0) || (m_oldtop < 0)) { assert(false); - std::ignore = luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%d", lua_gettop(m_L), offset_, file_, line_); + luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%d", lua_gettop(m_L), offset_, file_, line_); // doesn't return } } @@ -88,7 +88,7 @@ class StackChecker if (lua_gettop(m_L) != pos_) { assert(false); - std::ignore = luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%d", lua_gettop(m_L), pos_, file_, line_); + luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%d", lua_gettop(m_L), pos_, file_, line_); // doesn't return } } @@ -108,7 +108,7 @@ class StackChecker if (actual != expected_) { assert(false); - std::ignore = luaL_error(m_L, "STACK ASSERT failed (%d not %d): %s:%d", actual, expected_, file_, line_); + luaL_error(m_L, "STACK ASSERT failed (%d not %d): %s:%d", actual, expected_, file_, line_); // doesn't return } } } @@ -128,7 +128,7 @@ inline void STACK_GROW(lua_State* L, int n_) { if (!lua_checkstack(L, n_)) { - std::ignore = luaL_error(L, "Cannot grow stack!"); + luaL_error(L, "Cannot grow stack!"); // doesn't return } } diff --git a/src/state.cpp b/src/state.cpp index 496e21e..4a5f995 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -8,7 +8,7 @@ =============================================================================== Copyright (C) 2002-10 Asko Kauppi -2011-21 benoit Germain +2011-24 benoit Germain Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -79,6 +79,8 @@ THE SOFTWARE. return lua_gettop(L); // result(s) } +// ################################################################################################# + /* * Serialize calls to 'require', if it exists */ @@ -117,6 +119,7 @@ void serialize_require(DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* L) return 1; } +// ################################################################################################# static luaL_Reg const libs[] = { @@ -154,7 +157,9 @@ static luaL_Reg const libs[] = { nullptr, nullptr } }; -static void open1lib( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* L, char const* name_, size_t len_) +// ################################################################################################# + +static void open1lib(DEBUGSPEW_PARAM_COMMA(Universe* U) lua_State* L, char const* name_, size_t len_) { int i; for( i = 0; libs[i].name; ++ i) @@ -183,6 +188,7 @@ static void open1lib( DEBUGSPEW_PARAM_COMMA( Universe* U) lua_State* L, char con } } +// ################################################################################################# // just like lua_xmove, args are (from, to) static void copy_one_time_settings(Universe* U, Source L, Dest L2) @@ -194,19 +200,21 @@ static void copy_one_time_settings(Universe* U, Source L, Dest L2) DEBUGSPEW_CODE(fprintf( stderr, INDENT_BEGIN "copy_one_time_settings()\n" INDENT_END)); DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_add(1, std::memory_order_relaxed)); - CONFIG_REGKEY.pushValue(L); // config + CONFIG_REGKEY.pushValue(L); // config // copy settings from from source to destination registry - if( luaG_inter_move( U, L, L2, 1, LookupMode::LaneBody) < 0) // // config + if (luaG_inter_move(U, L, L2, 1, LookupMode::LaneBody) != InterCopyResult::Success) // // config { - (void) luaL_error( L, "failed to copy settings when loading lanes.core"); + luaL_error( L, "failed to copy settings when loading lanes.core"); // doesn't return } // set L2:_R[CONFIG_REGKEY] = settings - CONFIG_REGKEY.setValue(L2, [](lua_State* L) { lua_insert(L, -2); }); // config - STACK_CHECK( L2, 0); - STACK_CHECK( L, 0); + CONFIG_REGKEY.setValue(L2, [](lua_State* L) { lua_insert(L, -2); }); // config + STACK_CHECK(L2, 0); + STACK_CHECK(L, 0); DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_sub(1, std::memory_order_relaxed)); } +// ################################################################################################# + void initialize_on_state_create( Universe* U, lua_State* L) { STACK_CHECK_START_REL(L, 1); // settings @@ -238,7 +246,9 @@ void initialize_on_state_create( Universe* U, lua_State* L) STACK_CHECK(L, 1); } -lua_State* create_state( Universe* U, lua_State* from_) +// ################################################################################################# + +lua_State* create_state(Universe* U, lua_State* from_) { lua_State* L; #if LUAJIT_FLAVOR() == 64 @@ -264,11 +274,13 @@ lua_State* create_state( Universe* U, lua_State* from_) if (L == nullptr) { - std::ignore = luaL_error( from_, "luaG_newstate() failed while creating state; out of memory"); + luaL_error(from_, "luaG_newstate() failed while creating state; out of memory"); // doesn't return } return L; } +// ################################################################################################# + void call_on_state_create(Universe* U, lua_State* L, lua_State* from_, LookupMode mode_) { if (U->on_state_create_func != nullptr) @@ -304,6 +316,8 @@ void call_on_state_create(Universe* U, lua_State* L, lua_State* from_, LookupMod } } +// ################################################################################################# + /* * Like 'luaL_openlibs()' but allows the set of libraries be selected * diff --git a/src/tools.cpp b/src/tools.cpp index 9207df6..aa95f04 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -1415,7 +1415,7 @@ static void copy_cached_func(Universe* U, Dest L2, int L2_cache_i, Source L, int lua_pop(L2, 1); // _R[REG_MTID] if (!inter_copy_one(U, L2, L2_cache_i, L, lua_gettop(L), VT::METATABLE, mode_, upName_)) // _R[REG_MTID] mt? { - std::ignore = luaL_error(L, "Error copying a metatable"); // doesn't return + luaL_error(L, "Error copying a metatable"); // doesn't return } STACK_CHECK(L2, 2); // _R[REG_MTID] mt @@ -1600,7 +1600,7 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull }; { if (!inter_copy_one(U, L2, L2_cache_i, L, lua_absindex(L, -1), VT::NORMAL, mode_, upName_)) // ... u uv { - std::ignore = luaL_error(L, "Cannot copy upvalue type '%s'", luaL_typename(L, -1)); // doesn't return + luaL_error(L, "Cannot copy upvalue type '%s'", luaL_typename(L, -1)); // doesn't return } lua_pop( L, 1); // ... mt __lanesclone [uv]* // this pops the value from the stack @@ -1670,7 +1670,7 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull }; } else // raise an error { - std::ignore = luaL_error(L, "can't copy non-deep full userdata across lanes"); // doesn't return + luaL_error(L, "can't copy non-deep full userdata across lanes"); // doesn't return } STACK_CHECK(L2, 1); @@ -1739,7 +1739,7 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull }; { if (!inter_copy_one(U, L2, L2_cache_i, L, lua_absindex(L, -1), vt_, mode_, upName_)) // ... mt u uv { - std::ignore = luaL_error(L, "Cannot copy upvalue type '%s'", luaL_typename(L, -1)); // doesn't return + luaL_error(L, "Cannot copy upvalue type '%s'", luaL_typename(L, -1)); // doesn't return } lua_pop(L, 1); // ... u [uv]* // this pops the value from the stack @@ -1973,7 +1973,7 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull }; * * Note: Parameters are in this order ('L' = from first) to be same as 'lua_xmove'. */ -[[nodiscard]] int luaG_inter_copy(Universe* U, Source L, Dest L2, int n, LookupMode mode_) +[[nodiscard]] InterCopyResult luaG_inter_copy(Universe* U, Source L, Dest L2, int n, LookupMode mode_) { int const top_L{ lua_gettop(L) }; // ... {}n int const top_L2{ lua_gettop(L2) }; // ... @@ -1988,7 +1988,7 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull }; // requesting to copy more than is available? DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "nothing to copy()\n" INDENT_END)); DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_sub(1, std::memory_order_relaxed)); - return -1; + return InterCopyResult::NotEnoughValues; } STACK_CHECK_START_REL(L2, 0); @@ -2025,25 +2025,31 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull }; // Remove the cache table. Persistent caching would cause i.e. multiple // messages passed in the same table to use the same table also in receiving end. lua_remove(L2, top_L2 + 1); - return 0; + return InterCopyResult::Success; } // error -> pop everything from the target state stack lua_settop(L2, top_L2); STACK_CHECK(L2, 0); - return -2; + return InterCopyResult::Error; } // ################################################################################################# -[[nodiscard]] int luaG_inter_move(Universe* U, Source L, Dest L2, int n, LookupMode mode_) +[[nodiscard]] InterCopyResult luaG_inter_move(Universe* U, Source L, Dest L2, int n_, LookupMode mode_) { - int const ret{ luaG_inter_copy(U, L, L2, n, mode_) }; - lua_pop( L, n); + InterCopyResult const ret{ luaG_inter_copy(U, L, L2, n_, mode_) }; + lua_pop( L, n_); return ret; } -[[nodiscard]] int luaG_inter_copy_package(Universe* U, Source L, Dest L2, int package_idx_, LookupMode mode_) +// ################################################################################################# + +// transfers stuff from L->_G["package"] to L2->_G["package"] +// returns InterCopyResult::Success if everything is fine +// returns InterCopyResult::Error if pushed an error message in L +// else raise an error in L +[[nodiscard]] InterCopyResult luaG_inter_copy_package(Universe* U, Source L, Dest L2, int package_idx_, LookupMode mode_) { DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "luaG_inter_copy_package()\n" INDENT_END)); DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_add(1, std::memory_order_relaxed)); @@ -2056,7 +2062,11 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull }; lua_pushfstring(L, "expected package as table, got %s", luaL_typename(L, package_idx_)); STACK_CHECK(L, 1); // raise the error when copying from lane to lane, else just leave it on the stack to be raised later - return (mode_ == LookupMode::LaneBody) ? lua_error(L) : 1; + if (mode_ == LookupMode::LaneBody) + { + lua_error(L); // doesn't return + } + return InterCopyResult::Error; } lua_getglobal(L2, "package"); if (!lua_isnil(L2, -1)) // package library not loaded: do nothing @@ -2095,5 +2105,5 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull }; STACK_CHECK(L2, 0); STACK_CHECK(L, 0); DEBUGSPEW_CODE(U->debugspew_indent_depth.fetch_sub(1, std::memory_order_relaxed)); - return 0; + return InterCopyResult::Success; } diff --git a/src/tools.h b/src/tools.h index f0de7ec..dce7378 100644 --- a/src/tools.h +++ b/src/tools.h @@ -1,8 +1,6 @@ #pragma once -#include "threading.h" #include "deep.h" - #include "macros_and_utils.h" // forwards @@ -11,13 +9,13 @@ class Universe; // ################################################################################################ #ifdef _DEBUG -void luaG_dump( lua_State* L); +void luaG_dump(lua_State* L); #endif // _DEBUG // ################################################################################################ -void push_registry_subtable_mode( lua_State* L, UniqueKey key_, const char* mode_); -void push_registry_subtable( lua_State* L, UniqueKey key_); +void push_registry_subtable_mode(lua_State* L, UniqueKey key_, const char* mode_); +void push_registry_subtable(lua_State* L, UniqueKey key_); enum class VT { @@ -25,14 +23,21 @@ enum class VT KEY, METATABLE }; + +enum class InterCopyResult +{ + Success, + NotEnoughValues, + Error +}; + [[nodiscard]] bool inter_copy_one(Universe* U, Dest L2, int L2_cache_i, Source L, int i, VT vt_, LookupMode mode_, char const* upName_); // ################################################################################################ -[[nodiscard]] int luaG_inter_copy_package(Universe* U, Source L, Dest L2, int package_idx_, LookupMode mode_); - -[[nodiscard]] int luaG_inter_copy(Universe* U, Source L, Dest L2, int n, LookupMode mode_); -[[nodiscard]] int luaG_inter_move(Universe* U, Source L, Dest L2, int n, LookupMode mode_); +[[nodiscard]] InterCopyResult luaG_inter_copy_package(Universe* U, Source L, Dest L2, int package_idx_, LookupMode mode_); +[[nodiscard]] InterCopyResult luaG_inter_copy(Universe* U, Source L, Dest L2, int n, LookupMode mode_); +[[nodiscard]] InterCopyResult luaG_inter_move(Universe* U, Source L, Dest L2, int n, LookupMode mode_); [[nodiscard]] int luaG_nameof(lua_State* L); -- cgit v1.2.3-55-g6feb