From 4e8242de0c5d8c853201ec49dacf5aa9a5b0f7d3 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Thu, 24 Jun 2021 11:19:38 +0200 Subject: expand deeptest.lua --- deep_test/deep_test.c | 4 ++-- 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) static int deep_tostring( lua_State* L) { struct s_MyDeepUserdata* self = luaG_todeep( L, deep_test_id, 1); - lua_pushfstring( L, "deep(%d)", self->val); + lua_pushfstring( L, "%p:deep(%d)", lua_topointer( L, 1), self->val); return 1; } @@ -173,7 +173,7 @@ static int clonable_getuv( lua_State* L) static int clonable_tostring(lua_State* L) { struct s_MyClonableUserdata* self = (struct s_MyClonableUserdata*) lua_touserdata( L, 1); - lua_pushfstring( L, "clonable(%d)", self->val); + lua_pushfstring( L, "%p:clonable(%d)", lua_topointer( L, 1), self->val); return 1; } 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" -- we will transfer userdata created by this module, so we need to make Lanes aware of it local dt = lanes.require "deep_test" -local test_deep = false +local test_deep = true local test_clonable = false -local test_clonable_as_upvalue = true +local test_uvtype = "string" + +local makeUserValue = function( obj_) + if test_uvtype == "string" then + return "some uservalue" + elseif test_uvtype == "function" then + -- a function that pull the userdata as upvalue + local f = function() + print( obj_) + end + return f + end +end -local performTest = function( obj_, uservalue_) +local performTest = function( obj_) -- setup the userdata with some value and a uservalue obj_:set( 666) - obj_:setuv( 1, uservalue_) + obj_:setuv( 1, makeUserValue( obj_)) -- read back the contents of the object print( "immediate:", obj_, obj_:getuv( 1)) @@ -39,19 +51,9 @@ local performTest = function( obj_, uservalue_) end if test_deep then - performTest( dt.new_deep(), "some uservalue") + performTest( dt.new_deep()) end if test_clonable then - performTest( dt.new_clonable(), "my uservalue") + performTest( dt.new_clonable()) end - -if test_clonable_as_upvalue then - local clonable = dt.new_clonable() - -- pull clonable as upvalue in a function - local f = function() - print( clonable) - end - -- set function as uservalue of clonable (thus, clonable is referenced as upvalue in its function uservalue) - performTest( clonable, f) -end \ No newline at end of file -- cgit v1.2.3-55-g6feb