diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2022-02-08 10:39:48 +0100 |
---|---|---|
committer | Benoit Germain <bnt.germain@gmail.com> | 2022-02-08 10:39:48 +0100 |
commit | 2c0000d5169cacf950d06637ada1a371cf382896 (patch) | |
tree | edfe62d964b98cc745d867f09feac2df2eab758f /deep_test | |
parent | 54152c35e76acd1f21b477caf0a4403128032039 (diff) | |
download | lanes-2c0000d5169cacf950d06637ada1a371cf382896.tar.gz lanes-2c0000d5169cacf950d06637ada1a371cf382896.tar.bz2 lanes-2c0000d5169cacf950d06637ada1a371cf382896.zip |
__lanesclone is now called only once with 3 parameters dest, source, size -> BREAKS CUSTOM DEEP USERDATA API
Diffstat (limited to 'deep_test')
-rw-r--r-- | deep_test/deep_test.c | 13 | ||||
-rw-r--r-- | deep_test/deep_test.vcxproj.user | 2 | ||||
-rw-r--r-- | deep_test/deeptest.lua | 24 |
3 files changed, 21 insertions, 18 deletions
diff --git a/deep_test/deep_test.c b/deep_test/deep_test.c index a725902..cb89741 100644 --- a/deep_test/deep_test.c +++ b/deep_test/deep_test.c | |||
@@ -1,5 +1,6 @@ | |||
1 | #include <malloc.h> | 1 | #include <malloc.h> |
2 | #include <memory.h> | 2 | #include <memory.h> |
3 | #include <assert.h> | ||
3 | 4 | ||
4 | #include "lua.h" | 5 | #include "lua.h" |
5 | #include "lualib.h" | 6 | #include "lualib.h" |
@@ -196,18 +197,12 @@ static int clonable_lanesclone( lua_State* L) | |||
196 | { | 197 | { |
197 | switch( lua_gettop( L)) | 198 | switch( lua_gettop( L)) |
198 | { | 199 | { |
199 | case 1: | 200 | case 3: |
200 | { | ||
201 | // in case we need it to compute the amount of memory we need | ||
202 | struct s_MyClonableUserdata* self = lua_touserdata( L, 1); | ||
203 | lua_pushinteger( L, sizeof( struct s_MyClonableUserdata)); | ||
204 | } | ||
205 | return 1; | ||
206 | |||
207 | case 2: | ||
208 | { | 201 | { |
209 | struct s_MyClonableUserdata* self = lua_touserdata( L, 1); | 202 | struct s_MyClonableUserdata* self = lua_touserdata( L, 1); |
210 | struct s_MyClonableUserdata* from = lua_touserdata( L, 2); | 203 | struct s_MyClonableUserdata* from = lua_touserdata( L, 2); |
204 | size_t len = lua_tointeger( L, 3); | ||
205 | assert( len == sizeof(struct s_MyClonableUserdata)); | ||
211 | *self = *from; | 206 | *self = *from; |
212 | } | 207 | } |
213 | return 0; | 208 | return 0; |
diff --git a/deep_test/deep_test.vcxproj.user b/deep_test/deep_test.vcxproj.user index c5d6237..6ffc0ba 100644 --- a/deep_test/deep_test.vcxproj.user +++ b/deep_test/deep_test.vcxproj.user | |||
@@ -13,7 +13,7 @@ | |||
13 | <LocalDebuggerWorkingDirectory>D:\Boulot\anubis\Lua\bindings\Lanes\lanes\deep_test\</LocalDebuggerWorkingDirectory> | 13 | <LocalDebuggerWorkingDirectory>D:\Boulot\anubis\Lua\bindings\Lanes\lanes\deep_test\</LocalDebuggerWorkingDirectory> |
14 | </PropertyGroup> | 14 | </PropertyGroup> |
15 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug 5.4|x64'"> | 15 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug 5.4|x64'"> |
16 | <LocalDebuggerCommand>D:\Boulot\anubis\Lua\framework\lua53.exe</LocalDebuggerCommand> | 16 | <LocalDebuggerCommand>D:\Boulot\anubis\Lua\framework\lua54.exe</LocalDebuggerCommand> |
17 | <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> | 17 | <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> |
18 | <LocalDebuggerCommandArguments>-i deeptest.lua</LocalDebuggerCommandArguments> | 18 | <LocalDebuggerCommandArguments>-i deeptest.lua</LocalDebuggerCommandArguments> |
19 | <LocalDebuggerWorkingDirectory>D:\Boulot\anubis\Lua\bindings\Lanes\lanes\deep_test\</LocalDebuggerWorkingDirectory> | 19 | <LocalDebuggerWorkingDirectory>D:\Boulot\anubis\Lua\bindings\Lanes\lanes\deep_test\</LocalDebuggerWorkingDirectory> |
diff --git a/deep_test/deeptest.lua b/deep_test/deeptest.lua index 3c89c3d..cbd08de 100644 --- a/deep_test/deeptest.lua +++ b/deep_test/deeptest.lua | |||
@@ -6,7 +6,8 @@ local dt = lanes.require "deep_test" | |||
6 | 6 | ||
7 | local test_deep = true | 7 | local test_deep = true |
8 | local test_clonable = true | 8 | local test_clonable = true |
9 | local test_uvtype = "function" | 9 | local test_uvtype = "string" |
10 | local nupvals = _VERSION == "Lua 5.4" and 2 or 1 | ||
10 | 11 | ||
11 | local makeUserValue = function( obj_) | 12 | local makeUserValue = function( obj_) |
12 | if test_uvtype == "string" then | 13 | if test_uvtype == "string" then |
@@ -21,14 +22,17 @@ local makeUserValue = function( obj_) | |||
21 | end | 22 | end |
22 | 23 | ||
23 | local printDeep = function( prefix_, obj_, t_) | 24 | local printDeep = function( prefix_, obj_, t_) |
24 | local uservalue = obj_:getuv( 1) | 25 | print( prefix_, obj_) |
25 | print( prefix_) | 26 | for uvi = 1, nupvals do |
26 | print ( obj_, uservalue, type( uservalue) == "function" and uservalue() or "") | 27 | local uservalue = obj_:getuv( 1) |
28 | print ( "uv #" .. uvi, uservalue, type( uservalue) == "function" and uservalue() or "") | ||
29 | end | ||
27 | if t_ then | 30 | if t_ then |
28 | for k, v in pairs( t_) do | 31 | for k, v in pairs( t_) do |
29 | print( k, v) | 32 | print( k, v) |
30 | end | 33 | end |
31 | end | 34 | end |
35 | print() | ||
32 | end | 36 | end |
33 | 37 | ||
34 | local performTest = function( obj_) | 38 | local performTest = function( obj_) |
@@ -38,12 +42,14 @@ local performTest = function( obj_) | |||
38 | -- lua 5.3 supports an arbitrary type uservalue | 42 | -- lua 5.3 supports an arbitrary type uservalue |
39 | obj_:setuv( 1, makeUserValue( obj_)) | 43 | obj_:setuv( 1, makeUserValue( obj_)) |
40 | -- lua 5.4 supports multiple uservalues of arbitrary types | 44 | -- lua 5.4 supports multiple uservalues of arbitrary types |
41 | -- obj_:setuv( 2, "ENDUV") | 45 | if nupvals > 1 then |
46 | obj_:setuv( 2, "ENDUV") | ||
47 | end | ||
42 | 48 | ||
43 | local t = | 49 | local t = |
44 | { | 50 | { |
45 | ["key"] = obj_, | 51 | ["key"] = obj_, |
46 | -- [obj_] = "val" | 52 | [obj_] = "val" -- this one won't transfer because we don't support full uservalue as keys |
47 | } | 53 | } |
48 | 54 | ||
49 | -- read back the contents of the object | 55 | -- read back the contents of the object |
@@ -76,11 +82,13 @@ local performTest = function( obj_) | |||
76 | end | 82 | end |
77 | 83 | ||
78 | if test_deep then | 84 | if test_deep then |
85 | print "================================================================" | ||
79 | print "DEEP" | 86 | print "DEEP" |
80 | performTest( dt.new_deep()) | 87 | performTest( dt.new_deep(nupvals)) |
81 | end | 88 | end |
82 | 89 | ||
83 | if test_clonable then | 90 | if test_clonable then |
91 | print "================================================================" | ||
84 | print "CLONABLE" | 92 | print "CLONABLE" |
85 | performTest( dt.new_clonable()) | 93 | performTest( dt.new_clonable(nupvals)) |
86 | end | 94 | end |