aboutsummaryrefslogtreecommitdiff
path: root/deep_test/deeptest.lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--deep_test/deeptest.lua19
1 files changed, 12 insertions, 7 deletions
diff --git a/deep_test/deeptest.lua b/deep_test/deeptest.lua
index 09b638c..89e6f0d 100644
--- a/deep_test/deeptest.lua
+++ b/deep_test/deeptest.lua
@@ -6,16 +6,21 @@ local dt = lanes.require "deep_test"
6 6
7local test_deep = true 7local test_deep = true
8local test_clonable = true 8local test_clonable = true
9local test_uvtype = "string" 9-- lua 5.1->5.2 support a single table uservalue
10-- lua 5.3->5.4 supports an arbitrary type uservalue
11local test_uvtype = (_VERSION == "Lua 5.4") and "function" or (_VERSION == "Lua 5.3") and "string" or "table"
12-- lua 5.4 supports multiple uservalues
10local nupvals = _VERSION == "Lua 5.4" and 3 or 1 13local nupvals = _VERSION == "Lua 5.4" and 3 or 1
11 14
12local makeUserValue = function( obj_) 15local makeUserValue = function( obj_)
13 if test_uvtype == "string" then 16 if test_uvtype == "table" then
17 return {"some uservalue"}
18 elseif test_uvtype == "string" then
14 return "some uservalue" 19 return "some uservalue"
15 elseif test_uvtype == "function" then 20 elseif test_uvtype == "function" then
16 -- a function that pull the userdata as upvalue 21 -- a function that pull the userdata as upvalue
17 local f = function() 22 local f = function()
18 return tostring( obj_) 23 return "-> '" .. tostring( obj_) .. "'"
19 end 24 end
20 return f 25 return f
21 end 26 end
@@ -25,7 +30,7 @@ local printDeep = function( prefix_, obj_, t_)
25 print( prefix_, obj_) 30 print( prefix_, obj_)
26 for uvi = 1, nupvals do 31 for uvi = 1, nupvals do
27 local uservalue = obj_:getuv(uvi) 32 local uservalue = obj_:getuv(uvi)
28 print ( "uv #" .. uvi, uservalue, type( uservalue) == "function" and uservalue() or "") 33 print ("uv #" .. uvi, type( uservalue), uservalue, type(uservalue) == "function" and uservalue() or "")
29 end 34 end
30 if t_ then 35 if t_ then
31 for k, v in pairs( t_) do 36 for k, v in pairs( t_) do
@@ -38,10 +43,7 @@ end
38local performTest = function( obj_) 43local performTest = function( obj_)
39 -- setup the userdata with some value and a uservalue 44 -- setup the userdata with some value and a uservalue
40 obj_:set( 666) 45 obj_:set( 666)
41 -- lua 5.1->5.2 support a single table uservalue
42 -- lua 5.3 supports an arbitrary type uservalue
43 obj_:setuv( 1, makeUserValue( obj_)) 46 obj_:setuv( 1, makeUserValue( obj_))
44 -- lua 5.4 supports multiple uservalues of arbitrary types
45 if nupvals > 1 then 47 if nupvals > 1 then
46 -- keep uv #2 as nil 48 -- keep uv #2 as nil
47 obj_:setuv( 3, "ENDUV") 49 obj_:setuv( 3, "ENDUV")
@@ -95,3 +97,6 @@ if test_clonable then
95 print "CLONABLE" 97 print "CLONABLE"
96 performTest( dt.new_clonable(nupvals)) 98 performTest( dt.new_clonable(nupvals))
97end 99end
100
101print "================================================================"
102print "TEST OK" \ No newline at end of file