From f214d35df5f09e7026dafd8553e83cc6ea21cbde Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Tue, 26 Mar 2024 17:46:00 +0100 Subject: C++ migration: templated lua_touserdata --- tests/keeper.lua | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'tests') 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 @@ local lanes = require "lanes".configure{ with_timers = false, nb_keepers = 200} +local print_id = 0 +local PRINT = function(...) + print_id = print_id + 1 + print("main", print_id .. ".", ...) +end + local function keeper(linda) local mt= { __index= function( _, key ) @@ -25,23 +31,48 @@ local A= keeper( lindaA ) local lindaB= lanes.linda( "B", 2) local B= keeper( lindaB ) +local lindaC= lanes.linda( "C", 3) +local C= keeper( lindaC ) + A.some= 1 -print( A.some ) +PRINT("A.some == " .. A.some ) assert( A.some==1 ) B.some= "hoo" +PRINT("B.some == " .. B.some ) assert( B.some=="hoo" ) assert( A.some==1 ) +assert( C.some==nil ) function lane() + local print_id = 0 + local PRINT = function(...) + print_id = print_id + 1 + print("lane", print_id .. ".", ...) + end + local a= keeper(lindaA) - print( a.some ) + PRINT("a.some == " .. a.some ) assert( a.some==1 ) a.some= 2 + assert( a.some==2 ) + PRINT("a.some == " .. a.some ) + + local c = keeper(lindaC) + assert( c.some==nil ) + PRINT("c.some == " .. tostring(c.some)) + c.some= 3 + assert( c.some==3 ) + PRINT("c.some == " .. c.some) end +PRINT("lane started") local h= lanes.gen( "io", lane )() -h:join() +PRINT("lane joined:", h:join()) -print( A.some ) -- 2 +PRINT("A.some = " .. A.some ) assert( A.some==2 ) +PRINT("C.some = " .. C.some ) +assert( C.some==3 ) +lindaC:set("some") +assert( C.some==nil ) -- cgit v1.2.3-55-g6feb