aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-03-26 17:46:00 +0100
committerBenoit Germain <benoit.germain@ubisoft.com>2024-03-26 17:46:00 +0100
commitf214d35df5f09e7026dafd8553e83cc6ea21cbde (patch)
tree2bd19bfddf4949183fe0e84ca58940fd6a6aa918 /tests
parent2eeb245b98bd702379aa92d888f7b7d21d1193b8 (diff)
downloadlanes-f214d35df5f09e7026dafd8553e83cc6ea21cbde.tar.gz
lanes-f214d35df5f09e7026dafd8553e83cc6ea21cbde.tar.bz2
lanes-f214d35df5f09e7026dafd8553e83cc6ea21cbde.zip
C++ migration: templated lua_touserdata
Diffstat (limited to 'tests')
-rw-r--r--tests/keeper.lua39
1 files changed, 35 insertions, 4 deletions
diff --git a/tests/keeper.lua b/tests/keeper.lua
index f8c915d..11bbe17 100644
--- a/tests/keeper.lua
+++ b/tests/keeper.lua
@@ -6,6 +6,12 @@
6 6
7local lanes = require "lanes".configure{ with_timers = false, nb_keepers = 200} 7local lanes = require "lanes".configure{ with_timers = false, nb_keepers = 200}
8 8
9local print_id = 0
10local PRINT = function(...)
11 print_id = print_id + 1
12 print("main", print_id .. ".", ...)
13end
14
9local function keeper(linda) 15local function keeper(linda)
10 local mt= { 16 local mt= {
11 __index= function( _, key ) 17 __index= function( _, key )
@@ -25,23 +31,48 @@ local A= keeper( lindaA )
25local lindaB= lanes.linda( "B", 2) 31local lindaB= lanes.linda( "B", 2)
26local B= keeper( lindaB ) 32local B= keeper( lindaB )
27 33
34local lindaC= lanes.linda( "C", 3)
35local C= keeper( lindaC )
36
28A.some= 1 37A.some= 1
29print( A.some ) 38PRINT("A.some == " .. A.some )
30assert( A.some==1 ) 39assert( A.some==1 )
31 40
32B.some= "hoo" 41B.some= "hoo"
42PRINT("B.some == " .. B.some )
33assert( B.some=="hoo" ) 43assert( B.some=="hoo" )
34assert( A.some==1 ) 44assert( A.some==1 )
45assert( C.some==nil )
35 46
36function lane() 47function lane()
48 local print_id = 0
49 local PRINT = function(...)
50 print_id = print_id + 1
51 print("lane", print_id .. ".", ...)
52 end
53
37 local a= keeper(lindaA) 54 local a= keeper(lindaA)
38 print( a.some ) 55 PRINT("a.some == " .. a.some )
39 assert( a.some==1 ) 56 assert( a.some==1 )
40 a.some= 2 57 a.some= 2
58 assert( a.some==2 )
59 PRINT("a.some == " .. a.some )
60
61 local c = keeper(lindaC)
62 assert( c.some==nil )
63 PRINT("c.some == " .. tostring(c.some))
64 c.some= 3
65 assert( c.some==3 )
66 PRINT("c.some == " .. c.some)
41end 67end
42 68
69PRINT("lane started")
43local h= lanes.gen( "io", lane )() 70local h= lanes.gen( "io", lane )()
44h:join() 71PRINT("lane joined:", h:join())
45 72
46print( A.some ) -- 2 73PRINT("A.some = " .. A.some )
47assert( A.some==2 ) 74assert( A.some==2 )
75PRINT("C.some = " .. C.some )
76assert( C.some==3 )
77lindaC:set("some")
78assert( C.some==nil )