diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-06 14:21:46 +0200 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-06 14:21:46 +0200 |
| commit | 5fcbc757f62cdc9698a8f783864141f40fdff34e (patch) | |
| tree | ea465579253e3f6a1adba3b79842e773d563d16c | |
| parent | d7e4d17e65989d0974cd07c46bedfbf5dd1727ec (diff) | |
| download | lanes-5fcbc757f62cdc9698a8f783864141f40fdff34e.tar.gz lanes-5fcbc757f62cdc9698a8f783864141f40fdff34e.tar.bz2 lanes-5fcbc757f62cdc9698a8f783864141f40fdff34e.zip | |
Augment deep_test with deep:invoke()
| -rw-r--r-- | deep_test/deep_test.args.json | 2 | ||||
| -rw-r--r-- | deep_test/deep_test.cpp | 14 | ||||
| -rw-r--r-- | deep_test/deep_test.vcxproj.user | 4 | ||||
| -rw-r--r-- | deep_test/deeptest.lua | 34 |
4 files changed, 46 insertions, 8 deletions
diff --git a/deep_test/deep_test.args.json b/deep_test/deep_test.args.json index a540fc2..a94ccbb 100644 --- a/deep_test/deep_test.args.json +++ b/deep_test/deep_test.args.json | |||
| @@ -8,7 +8,7 @@ | |||
| 8 | "Items": [ | 8 | "Items": [ |
| 9 | { | 9 | { |
| 10 | "Id": "10e30bb2-dc23-4882-b918-b5939c14e588", | 10 | "Id": "10e30bb2-dc23-4882-b918-b5939c14e588", |
| 11 | "Command": "-i deeptest.lua" | 11 | "Command": "-e \"REPEAT=1000, SIZE=1000\" -i deeptest.lua" |
| 12 | } | 12 | } |
| 13 | ] | 13 | ] |
| 14 | } | 14 | } |
diff --git a/deep_test/deep_test.cpp b/deep_test/deep_test.cpp index da467f3..c330cbe 100644 --- a/deep_test/deep_test.cpp +++ b/deep_test/deep_test.cpp | |||
| @@ -47,6 +47,7 @@ void MyDeepFactory::deleteDeepObjectInternal(lua_State* const L_, DeepPrelude* c | |||
| 47 | [[nodiscard]] static int deep_gc(lua_State* L) | 47 | [[nodiscard]] static int deep_gc(lua_State* L) |
| 48 | { | 48 | { |
| 49 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, 1)) }; | 49 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, 1)) }; |
| 50 | luaL_argcheck(L, 1, !_self->inUse.load(), "being collected while in use!"); | ||
| 50 | return 0; | 51 | return 0; |
| 51 | } | 52 | } |
| 52 | 53 | ||
| @@ -76,6 +77,18 @@ void MyDeepFactory::deleteDeepObjectInternal(lua_State* const L_, DeepPrelude* c | |||
| 76 | 77 | ||
| 77 | // ################################################################################################# | 78 | // ################################################################################################# |
| 78 | 79 | ||
| 80 | [[nodiscard]] static int deep_invoke(lua_State* L) | ||
| 81 | { | ||
| 82 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L, 1)) }; | ||
| 83 | luaL_argcheck(L, 2, lua_gettop(L) >= 2, "need something to call"); | ||
| 84 | _self->inUse.fetch_add(1, std::memory_order_seq_cst); | ||
| 85 | lua_call(L, lua_gettop(L) - 2, LUA_MULTRET); | ||
| 86 | _self->inUse.fetch_sub(1, std::memory_order_seq_cst); | ||
| 87 | return 1; | ||
| 88 | } | ||
| 89 | |||
| 90 | // ################################################################################################# | ||
| 91 | |||
| 79 | [[nodiscard]] static int deep_set(lua_State* const L_) | 92 | [[nodiscard]] static int deep_set(lua_State* const L_) |
| 80 | { | 93 | { |
| 81 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L_, 1)) }; | 94 | MyDeepUserdata* const _self{ static_cast<MyDeepUserdata*>(MyDeepFactory::Instance.toDeep(L_, 1)) }; |
| @@ -105,6 +118,7 @@ static luaL_Reg const deep_mt[] = { | |||
| 105 | { "__gc", deep_gc }, | 118 | { "__gc", deep_gc }, |
| 106 | { "__tostring", deep_tostring }, | 119 | { "__tostring", deep_tostring }, |
| 107 | { "getuv", deep_getuv }, | 120 | { "getuv", deep_getuv }, |
| 121 | { "invoke", deep_invoke }, | ||
| 108 | { "set", deep_set }, | 122 | { "set", deep_set }, |
| 109 | { "setuv", deep_setuv }, | 123 | { "setuv", deep_setuv }, |
| 110 | { nullptr, nullptr } | 124 | { nullptr, nullptr } |
diff --git a/deep_test/deep_test.vcxproj.user b/deep_test/deep_test.vcxproj.user index 257d4e9..ed75184 100644 --- a/deep_test/deep_test.vcxproj.user +++ b/deep_test/deep_test.vcxproj.user | |||
| @@ -36,9 +36,9 @@ | |||
| 36 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug 5.4|x64'"> | 36 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug 5.4|x64'"> |
| 37 | <LocalDebuggerCommand>$(SolutionDir)..\framework\lua54.exe</LocalDebuggerCommand> | 37 | <LocalDebuggerCommand>$(SolutionDir)..\framework\lua54.exe</LocalDebuggerCommand> |
| 38 | <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> | 38 | <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> |
| 39 | <LocalDebuggerCommandArguments>deeptest.lua</LocalDebuggerCommandArguments> | 39 | <LocalDebuggerCommandArguments>-e "REPEAT=1000, SIZE=1000" -i deeptest.lua</LocalDebuggerCommandArguments> |
| 40 | <LocalDebuggerWorkingDirectory>$(SolutionDir)Lanes\lanes\deep_test\</LocalDebuggerWorkingDirectory> | 40 | <LocalDebuggerWorkingDirectory>$(SolutionDir)Lanes\lanes\deep_test\</LocalDebuggerWorkingDirectory> |
| 41 | <RemoteDebuggerCommandArguments>deeptest.lua</RemoteDebuggerCommandArguments> | 41 | <RemoteDebuggerCommandArguments>-e "REPEAT=1000, SIZE=1000" -i deeptest.lua</RemoteDebuggerCommandArguments> |
| 42 | </PropertyGroup> | 42 | </PropertyGroup> |
| 43 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MoonJIT|x64'"> | 43 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MoonJIT|x64'"> |
| 44 | <LocalDebuggerCommand>$(SolutionDir)..\MoonJIT\bin\$(Platform)\moonjit.exe</LocalDebuggerCommand> | 44 | <LocalDebuggerCommand>$(SolutionDir)..\MoonJIT\bin\$(Platform)\moonjit.exe</LocalDebuggerCommand> |
diff --git a/deep_test/deeptest.lua b/deep_test/deeptest.lua index 89e6f0d..99cf1e4 100644 --- a/deep_test/deeptest.lua +++ b/deep_test/deeptest.lua | |||
| @@ -4,8 +4,11 @@ local l = lanes.linda "my linda" | |||
| 4 | -- we will transfer userdata created by this module, so we need to make Lanes aware of it | 4 | -- we will transfer userdata created by this module, so we need to make Lanes aware of it |
| 5 | local dt = lanes.require "deep_test" | 5 | local dt = lanes.require "deep_test" |
| 6 | 6 | ||
| 7 | local test_deep = true | 7 | -- set DEEP to any non-false value to run the Deep Userdata tests. "gc" selects a special test for debug purposes |
| 8 | local test_clonable = true | 8 | DEEP = DEEP or true |
| 9 | -- set CLONABLE to any non-false value to run the Clonable Userdata tests | ||
| 10 | CLONABLE = CLONABLE or true | ||
| 11 | |||
| 9 | -- lua 5.1->5.2 support a single table uservalue | 12 | -- lua 5.1->5.2 support a single table uservalue |
| 10 | -- lua 5.3->5.4 supports an arbitrary type uservalue | 13 | -- lua 5.3->5.4 supports an arbitrary type uservalue |
| 11 | local test_uvtype = (_VERSION == "Lua 5.4") and "function" or (_VERSION == "Lua 5.3") and "string" or "table" | 14 | local test_uvtype = (_VERSION == "Lua 5.4") and "function" or (_VERSION == "Lua 5.3") and "string" or "table" |
| @@ -86,13 +89,34 @@ local performTest = function( obj_) | |||
| 86 | printDeep( "from lane:", h[1], h[2]) | 89 | printDeep( "from lane:", h[1], h[2]) |
| 87 | end | 90 | end |
| 88 | 91 | ||
| 89 | if test_deep then | 92 | if DEEP then |
| 90 | print "================================================================" | 93 | print "================================================================" |
| 91 | print "DEEP" | 94 | print "DEEP" |
| 92 | performTest( dt.new_deep(nupvals)) | 95 | local d = dt.new_deep(nupvals) |
| 96 | if DEEP == "gc" then | ||
| 97 | local thrasher = function(repeat_, size_) | ||
| 98 | print "in thrasher" | ||
| 99 | -- result is a table of repeat_ tables, each containing size_ entries | ||
| 100 | local result = {} | ||
| 101 | for i = 1, repeat_ do | ||
| 102 | local batch_values = {} | ||
| 103 | for j = 1, size_ do | ||
| 104 | table.insert(batch_values, j) | ||
| 105 | end | ||
| 106 | table.insert(result, batch_values) | ||
| 107 | end | ||
| 108 | print "thrasher done" | ||
| 109 | return result | ||
| 110 | end | ||
| 111 | -- have the object call the function from inside one of its functions, to detect if it gets collected from there (while in use!) | ||
| 112 | local r = d:invoke(thrasher, REPEAT or 10, SIZE or 10) | ||
| 113 | print("invoke -> ", tostring(r)) | ||
| 114 | else | ||
| 115 | performTest(d) | ||
| 116 | end | ||
| 93 | end | 117 | end |
| 94 | 118 | ||
| 95 | if test_clonable then | 119 | if CLONABLE then |
| 96 | print "================================================================" | 120 | print "================================================================" |
| 97 | print "CLONABLE" | 121 | print "CLONABLE" |
| 98 | performTest( dt.new_clonable(nupvals)) | 122 | performTest( dt.new_clonable(nupvals)) |
