aboutsummaryrefslogtreecommitdiff
path: root/tests/keeper.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tests/keeper.lua')
-rw-r--r--tests/keeper.lua47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/keeper.lua b/tests/keeper.lua
new file mode 100644
index 0000000..5c8c23a
--- /dev/null
+++ b/tests/keeper.lua
@@ -0,0 +1,47 @@
1--
2-- KEEPER.LUA
3--
4-- Test program for Lua Lanes
5--
6
7require "lanes"
8
9local function keeper(linda)
10 local mt= {
11 __index= function( _, key )
12 return linda:get( key )
13 end,
14 __newindex= function( _, key, val )
15 linda:set( key, val )
16 end
17 }
18 return setmetatable( {}, mt )
19end
20
21--
22local lindaA= lanes.linda()
23local A= keeper( lindaA )
24
25local lindaB= lanes.linda()
26local B= keeper( lindaB )
27
28A.some= 1
29print( A.some )
30assert( A.some==1 )
31
32B.some= "hoo"
33assert( B.some=="hoo" )
34assert( A.some==1 )
35
36function lane()
37 local a= keeper(lindaA)
38 print( a.some )
39 assert( a.some==1 )
40 a.some= 2
41end
42
43local h= lanes.gen( "io", lane )()
44h:join()
45
46print( A.some ) -- 2
47assert( A.some==2 )