From c52571736d852d2636bd285d19c613be5c706cff Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Sat, 20 Sep 2025 14:30:57 +0200 Subject: Improve table and userdata conversions * add convert_fallback and convert_max_attempts to global settings * if no __lanesconvert is available, use convert_fallback (can be useful for externally provided full userdata with fixed metatables) * only try conversion on non-deep and non-clonable userdata * conversion can be applied recursively, up to convert_max_attempts times * plus all the relevant unit tests of course --- src/universe.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/universe.cpp') diff --git a/src/universe.cpp b/src/universe.cpp index 4db036b..934db2c 100644 --- a/src/universe.cpp +++ b/src/universe.cpp @@ -163,6 +163,22 @@ Universe* Universe::Create(lua_State* const L_) lua_setmetatable(L_, -2); // L_: settings universe lua_pop(L_, 1); // L_: settings + std::ignore = luaW_getfield(L_, kIdxSettings, "convert_fallback"); // L_: settings convert_fallback + if (kNilSentinel.equals(L_, kIdxTop)) { + _U->convertMode = ConvertMode::ConvertToNil; + } else if (luaW_type(L_, kIdxTop) == LuaType::STRING) { + LUA_ASSERT(L_, luaW_tostring(L_, kIdxTop) == "decay"); + _U->convertMode = ConvertMode::Decay; + } else { + LUA_ASSERT(L_, lua_isnil(L_, kIdxTop)); + } + lua_pop(L_, 1); // L_: settings + + std::ignore = luaW_getfield(L_, kIdxSettings, "convert_max_attempts"); // L_: settings convert_max_attempts + _U->convertMaxAttempts = static_castconvertMaxAttempts)>(lua_tointeger(L_, kIdxTop)); + lua_pop(L_, 1); // L_: settings + STACK_CHECK(L_, 0); + std::ignore = luaW_getfield(L_, kIdxSettings, "linda_wake_period"); // L_: settings linda_wake_period if (luaW_type(L_, kIdxTop) == LuaType::NUMBER) { _U->lindaWakePeriod = lua_Duration{ lua_tonumber(L_, kIdxTop) }; -- cgit v1.2.3-55-g6feb