aboutsummaryrefslogtreecommitdiff
path: root/src/universe.cpp
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2025-09-20 14:30:57 +0200
committerBenoit Germain <bnt.germain@gmail.com>2025-09-20 14:30:57 +0200
commitc52571736d852d2636bd285d19c613be5c706cff (patch)
tree50a1fc9b867197faa695c728008c8d0c7498b756 /src/universe.cpp
parentdc3de6ef8d4bb1a8ce7b2932515a0f6287ab1e76 (diff)
downloadlanes-c52571736d852d2636bd285d19c613be5c706cff.tar.gz
lanes-c52571736d852d2636bd285d19c613be5c706cff.tar.bz2
lanes-c52571736d852d2636bd285d19c613be5c706cff.zip
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
Diffstat (limited to 'src/universe.cpp')
-rw-r--r--src/universe.cpp16
1 files changed, 16 insertions, 0 deletions
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_)
163 lua_setmetatable(L_, -2); // L_: settings universe 163 lua_setmetatable(L_, -2); // L_: settings universe
164 lua_pop(L_, 1); // L_: settings 164 lua_pop(L_, 1); // L_: settings
165 165
166 std::ignore = luaW_getfield(L_, kIdxSettings, "convert_fallback"); // L_: settings convert_fallback
167 if (kNilSentinel.equals(L_, kIdxTop)) {
168 _U->convertMode = ConvertMode::ConvertToNil;
169 } else if (luaW_type(L_, kIdxTop) == LuaType::STRING) {
170 LUA_ASSERT(L_, luaW_tostring(L_, kIdxTop) == "decay");
171 _U->convertMode = ConvertMode::Decay;
172 } else {
173 LUA_ASSERT(L_, lua_isnil(L_, kIdxTop));
174 }
175 lua_pop(L_, 1); // L_: settings
176
177 std::ignore = luaW_getfield(L_, kIdxSettings, "convert_max_attempts"); // L_: settings convert_max_attempts
178 _U->convertMaxAttempts = static_cast<decltype(_U->convertMaxAttempts)>(lua_tointeger(L_, kIdxTop));
179 lua_pop(L_, 1); // L_: settings
180 STACK_CHECK(L_, 0);
181
166 std::ignore = luaW_getfield(L_, kIdxSettings, "linda_wake_period"); // L_: settings linda_wake_period 182 std::ignore = luaW_getfield(L_, kIdxSettings, "linda_wake_period"); // L_: settings linda_wake_period
167 if (luaW_type(L_, kIdxTop) == LuaType::NUMBER) { 183 if (luaW_type(L_, kIdxTop) == LuaType::NUMBER) {
168 _U->lindaWakePeriod = lua_Duration{ lua_tonumber(L_, kIdxTop) }; 184 _U->lindaWakePeriod = lua_Duration{ lua_tonumber(L_, kIdxTop) };