diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-03-26 17:46:00 +0100 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-03-26 17:46:00 +0100 |
commit | f214d35df5f09e7026dafd8553e83cc6ea21cbde (patch) | |
tree | 2bd19bfddf4949183fe0e84ca58940fd6a6aa918 /tests | |
parent | 2eeb245b98bd702379aa92d888f7b7d21d1193b8 (diff) | |
download | lanes-f214d35df5f09e7026dafd8553e83cc6ea21cbde.tar.gz lanes-f214d35df5f09e7026dafd8553e83cc6ea21cbde.tar.bz2 lanes-f214d35df5f09e7026dafd8553e83cc6ea21cbde.zip |
C++ migration: templated lua_touserdata
Diffstat (limited to 'tests')
-rw-r--r-- | tests/keeper.lua | 39 |
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 | ||
7 | local lanes = require "lanes".configure{ with_timers = false, nb_keepers = 200} | 7 | local lanes = require "lanes".configure{ with_timers = false, nb_keepers = 200} |
8 | 8 | ||
9 | local print_id = 0 | ||
10 | local PRINT = function(...) | ||
11 | print_id = print_id + 1 | ||
12 | print("main", print_id .. ".", ...) | ||
13 | end | ||
14 | |||
9 | local function keeper(linda) | 15 | local 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 ) | |||
25 | local lindaB= lanes.linda( "B", 2) | 31 | local lindaB= lanes.linda( "B", 2) |
26 | local B= keeper( lindaB ) | 32 | local B= keeper( lindaB ) |
27 | 33 | ||
34 | local lindaC= lanes.linda( "C", 3) | ||
35 | local C= keeper( lindaC ) | ||
36 | |||
28 | A.some= 1 | 37 | A.some= 1 |
29 | print( A.some ) | 38 | PRINT("A.some == " .. A.some ) |
30 | assert( A.some==1 ) | 39 | assert( A.some==1 ) |
31 | 40 | ||
32 | B.some= "hoo" | 41 | B.some= "hoo" |
42 | PRINT("B.some == " .. B.some ) | ||
33 | assert( B.some=="hoo" ) | 43 | assert( B.some=="hoo" ) |
34 | assert( A.some==1 ) | 44 | assert( A.some==1 ) |
45 | assert( C.some==nil ) | ||
35 | 46 | ||
36 | function lane() | 47 | function 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) | ||
41 | end | 67 | end |
42 | 68 | ||
69 | PRINT("lane started") | ||
43 | local h= lanes.gen( "io", lane )() | 70 | local h= lanes.gen( "io", lane )() |
44 | h:join() | 71 | PRINT("lane joined:", h:join()) |
45 | 72 | ||
46 | print( A.some ) -- 2 | 73 | PRINT("A.some = " .. A.some ) |
47 | assert( A.some==2 ) | 74 | assert( A.some==2 ) |
75 | PRINT("C.some = " .. C.some ) | ||
76 | assert( C.some==3 ) | ||
77 | lindaC:set("some") | ||
78 | assert( C.some==nil ) | ||