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 --- unit_tests/shared.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'unit_tests/shared.cpp') diff --git a/unit_tests/shared.cpp b/unit_tests/shared.cpp index 9f3b08e..825cd48 100644 --- a/unit_tests/shared.cpp +++ b/unit_tests/shared.cpp @@ -46,8 +46,14 @@ namespace return 1; }; + // a function that creates a full userdata, using first argument as its metatable lua_CFunction sNewUserData = +[](lua_State* const L_) { - std::ignore = luaW_newuserdatauv(L_, UserValueCount{ 0 }); + lua_settop(L_, 1); // L_: {}|nil + STACK_CHECK_START_ABS(L_, 1); + std::ignore = luaW_newuserdatauv(L_, UserValueCount{ 0 }); // L_: {}|nil u + lua_insert(L_, 1); // L_: u {}|nil + lua_setmetatable(L_, 1); // L_: u + STACK_CHECK(L_, 1); return 1; }; -- cgit v1.2.3-55-g6feb