diff options
Diffstat (limited to 'tests/keeper.lua')
-rw-r--r-- | tests/keeper.lua | 47 |
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 | |||
7 | require "lanes" | ||
8 | |||
9 | local 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 ) | ||
19 | end | ||
20 | |||
21 | -- | ||
22 | local lindaA= lanes.linda() | ||
23 | local A= keeper( lindaA ) | ||
24 | |||
25 | local lindaB= lanes.linda() | ||
26 | local B= keeper( lindaB ) | ||
27 | |||
28 | A.some= 1 | ||
29 | print( A.some ) | ||
30 | assert( A.some==1 ) | ||
31 | |||
32 | B.some= "hoo" | ||
33 | assert( B.some=="hoo" ) | ||
34 | assert( A.some==1 ) | ||
35 | |||
36 | function lane() | ||
37 | local a= keeper(lindaA) | ||
38 | print( a.some ) | ||
39 | assert( a.some==1 ) | ||
40 | a.some= 2 | ||
41 | end | ||
42 | |||
43 | local h= lanes.gen( "io", lane )() | ||
44 | h:join() | ||
45 | |||
46 | print( A.some ) -- 2 | ||
47 | assert( A.some==2 ) | ||