diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2021-06-23 14:44:43 +0200 |
---|---|---|
committer | Benoit Germain <bnt.germain@gmail.com> | 2021-06-23 14:44:43 +0200 |
commit | 54e788bc121218f8f1a978ee136e4d0faa67370d (patch) | |
tree | abbb96bbe5d683aabc85ddfd803734550221db73 /deep_test/deeptest.lua | |
parent | d1ef9b97e356805c622e4832ec76289bae391a6e (diff) | |
download | lanes-54e788bc121218f8f1a978ee136e4d0faa67370d.tar.gz lanes-54e788bc121218f8f1a978ee136e4d0faa67370d.tar.bz2 lanes-54e788bc121218f8f1a978ee136e4d0faa67370d.zip |
updated deep userdata unit test to expose issue #189
Diffstat (limited to '')
-rw-r--r-- | deep_test/deeptest.lua | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/deep_test/deeptest.lua b/deep_test/deeptest.lua index 16059d9..bc183a0 100644 --- a/deep_test/deeptest.lua +++ b/deep_test/deeptest.lua | |||
@@ -5,25 +5,32 @@ local l = lanes.linda "my linda" | |||
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 = false |
8 | local test_clonable = true | 8 | local test_clonable = false |
9 | local test_clonable_as_upvalue = true | ||
9 | 10 | ||
10 | local performTest = function( obj_) | 11 | local performTest = function( obj_, uservalue_) |
12 | -- setup the userdata with some value and a uservalue | ||
11 | obj_:set( 666) | 13 | obj_:set( 666) |
12 | obj_:setuv( 1, "my uservalue") | 14 | obj_:setuv( 1, uservalue_) |
13 | print( "immediate:", obj_) | ||
14 | 15 | ||
16 | -- read back the contents of the object | ||
17 | print( "immediate:", obj_, obj_:getuv( 1)) | ||
18 | |||
19 | -- send the object in a linda, get it back out, read the contents | ||
15 | l:set( "key", obj_) | 20 | l:set( "key", obj_) |
16 | local out = l:get( "key") | 21 | local out = l:get( "key") |
17 | print( "out of linda:", out, out:getuv( 1)) | 22 | print( "out of linda:", out, out:getuv( 1)) |
18 | 23 | ||
24 | -- send the object in a lane through parameter passing, the lane body returns it as return value, read the contents | ||
19 | local g = lanes.gen( | 25 | local g = lanes.gen( |
20 | "package" | 26 | "package" |
21 | , { | 27 | , { |
22 | required = { "deep_test"} -- we will transfer userdata created by this module, so we need to make this lane aware of it | 28 | required = { "deep_test"} -- we will transfer userdata created by this module, so we need to make this lane aware of it |
23 | } | 29 | } |
24 | , function( obj_) | 30 | , function( param_) |
25 | print( "in lane:", obj_, obj_:getuv( 1)) | 31 | -- read contents inside lane |
26 | return obj_ | 32 | print( "in lane:", param_, param_:getuv( 1)) |
33 | return param_ | ||
27 | end | 34 | end |
28 | ) | 35 | ) |
29 | h = g( obj_) | 36 | h = g( obj_) |
@@ -32,9 +39,19 @@ local performTest = function( obj_) | |||
32 | end | 39 | end |
33 | 40 | ||
34 | if test_deep then | 41 | if test_deep then |
35 | performTest( dt.new_deep()) | 42 | performTest( dt.new_deep(), "some uservalue") |
36 | end | 43 | end |
37 | 44 | ||
38 | if test_clonable then | 45 | if test_clonable then |
39 | performTest( dt.new_clonable()) | 46 | performTest( dt.new_clonable(), "my uservalue") |
40 | end | 47 | 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 | ||