aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2021-06-24 11:19:38 +0200
committerBenoit Germain <bnt.germain@gmail.com>2021-06-24 11:19:38 +0200
commit4e8242de0c5d8c853201ec49dacf5aa9a5b0f7d3 (patch)
treea1c8efb7cd0e875dd0dde7d8c38ed332d616b411
parent54e788bc121218f8f1a978ee136e4d0faa67370d (diff)
downloadlanes-4e8242de0c5d8c853201ec49dacf5aa9a5b0f7d3.tar.gz
lanes-4e8242de0c5d8c853201ec49dacf5aa9a5b0f7d3.tar.bz2
lanes-4e8242de0c5d8c853201ec49dacf5aa9a5b0f7d3.zip
expand deeptest.lua
-rw-r--r--deep_test/deep_test.c4
-rw-r--r--deep_test/deeptest.lua34
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)
61static int deep_tostring( lua_State* L) 61static 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)
173static int clonable_tostring(lua_State* L) 173static 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
5local dt = lanes.require "deep_test" 5local dt = lanes.require "deep_test"
6 6
7local test_deep = false 7local test_deep = true
8local test_clonable = false 8local test_clonable = false
9local test_clonable_as_upvalue = true 9local test_uvtype = "string"
10
11local 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
21end
10 22
11local performTest = function( obj_, uservalue_) 23local 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_)
39end 51end
40 52
41if test_deep then 53if test_deep then
42 performTest( dt.new_deep(), "some uservalue") 54 performTest( dt.new_deep())
43end 55end
44 56
45if test_clonable then 57if test_clonable then
46 performTest( dt.new_clonable(), "my uservalue") 58 performTest( dt.new_clonable())
47end 59end
48
49if 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)
57end \ No newline at end of file