diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2021-06-24 11:19:38 +0200 |
---|---|---|
committer | Benoit Germain <bnt.germain@gmail.com> | 2021-06-24 11:19:38 +0200 |
commit | 4e8242de0c5d8c853201ec49dacf5aa9a5b0f7d3 (patch) | |
tree | a1c8efb7cd0e875dd0dde7d8c38ed332d616b411 | |
parent | 54e788bc121218f8f1a978ee136e4d0faa67370d (diff) | |
download | lanes-4e8242de0c5d8c853201ec49dacf5aa9a5b0f7d3.tar.gz lanes-4e8242de0c5d8c853201ec49dacf5aa9a5b0f7d3.tar.bz2 lanes-4e8242de0c5d8c853201ec49dacf5aa9a5b0f7d3.zip |
expand deeptest.lua
-rw-r--r-- | deep_test/deep_test.c | 4 | ||||
-rw-r--r-- | deep_test/deeptest.lua | 34 |
2 files changed, 20 insertions, 18 deletions
diff --git a/deep_test/deep_test.c b/deep_test/deep_test.c index 4bee7fe..c400cac 100644 --- a/deep_test/deep_test.c +++ b/deep_test/deep_test.c | |||
@@ -61,7 +61,7 @@ static int deep_getuv( lua_State* L) | |||
61 | static int deep_tostring( lua_State* L) | 61 | static int deep_tostring( lua_State* L) |
62 | { | 62 | { |
63 | struct s_MyDeepUserdata* self = luaG_todeep( L, deep_test_id, 1); | 63 | struct s_MyDeepUserdata* self = luaG_todeep( L, deep_test_id, 1); |
64 | lua_pushfstring( L, "deep(%d)", self->val); | 64 | lua_pushfstring( L, "%p:deep(%d)", lua_topointer( L, 1), self->val); |
65 | return 1; | 65 | return 1; |
66 | } | 66 | } |
67 | 67 | ||
@@ -173,7 +173,7 @@ static int clonable_getuv( lua_State* L) | |||
173 | static int clonable_tostring(lua_State* L) | 173 | static int clonable_tostring(lua_State* L) |
174 | { | 174 | { |
175 | struct s_MyClonableUserdata* self = (struct s_MyClonableUserdata*) lua_touserdata( L, 1); | 175 | struct s_MyClonableUserdata* self = (struct s_MyClonableUserdata*) lua_touserdata( L, 1); |
176 | lua_pushfstring( L, "clonable(%d)", self->val); | 176 | lua_pushfstring( L, "%p:clonable(%d)", lua_topointer( L, 1), self->val); |
177 | return 1; | 177 | return 1; |
178 | } | 178 | } |
179 | 179 | ||
diff --git a/deep_test/deeptest.lua b/deep_test/deeptest.lua index bc183a0..b3e523f 100644 --- a/deep_test/deeptest.lua +++ b/deep_test/deeptest.lua | |||
@@ -4,14 +4,26 @@ 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 = false | 7 | local test_deep = true |
8 | local test_clonable = false | 8 | local test_clonable = false |
9 | local test_clonable_as_upvalue = true | 9 | local test_uvtype = "string" |
10 | |||
11 | local makeUserValue = function( obj_) | ||
12 | if test_uvtype == "string" then | ||
13 | return "some uservalue" | ||
14 | elseif test_uvtype == "function" then | ||
15 | -- a function that pull the userdata as upvalue | ||
16 | local f = function() | ||
17 | print( obj_) | ||
18 | end | ||
19 | return f | ||
20 | end | ||
21 | end | ||
10 | 22 | ||
11 | local performTest = function( obj_, uservalue_) | 23 | local performTest = function( obj_) |
12 | -- setup the userdata with some value and a uservalue | 24 | -- setup the userdata with some value and a uservalue |
13 | obj_:set( 666) | 25 | obj_:set( 666) |
14 | obj_:setuv( 1, uservalue_) | 26 | obj_:setuv( 1, makeUserValue( obj_)) |
15 | 27 | ||
16 | -- read back the contents of the object | 28 | -- read back the contents of the object |
17 | print( "immediate:", obj_, obj_:getuv( 1)) | 29 | print( "immediate:", obj_, obj_:getuv( 1)) |
@@ -39,19 +51,9 @@ local performTest = function( obj_, uservalue_) | |||
39 | end | 51 | end |
40 | 52 | ||
41 | if test_deep then | 53 | if test_deep then |
42 | performTest( dt.new_deep(), "some uservalue") | 54 | performTest( dt.new_deep()) |
43 | end | 55 | end |
44 | 56 | ||
45 | if test_clonable then | 57 | if test_clonable then |
46 | performTest( dt.new_clonable(), "my uservalue") | 58 | performTest( dt.new_clonable()) |
47 | end | 59 | end |
48 | |||
49 | if test_clonable_as_upvalue then | ||
50 | local clonable = dt.new_clonable() | ||
51 | -- pull clonable as upvalue in a function | ||
52 | local f = function() | ||
53 | print( clonable) | ||
54 | end | ||
55 | -- set function as uservalue of clonable (thus, clonable is referenced as upvalue in its function uservalue) | ||
56 | performTest( clonable, f) | ||
57 | end \ No newline at end of file | ||