From 68d8db431ec2b739dc53233d6b4d8aeee9324e48 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Thu, 24 Jan 2013 22:46:21 +0100 Subject: version 3.4.3 * raise an error if lane generator libs specification contains a lib more than once * bit32 is a valid lib name in the libs specification (silently ignored by the Lua 5.1 build) * improved lanes.nameof to search inside table- and userdata- metatables for an object's name * fixed an unwarranted error when trying to discover a function name upon a failed transfer * contents of package.[path,cpath,preload,loaders|searchers] are pulled *only once* inside keeper states at initialisation * Lua function upvalues equal to the global environment aren't copied by value, but bound to the destination's global environment especially useful for Lua 5.2 _ENV * fixed loading of base libraries that didn't create the global tables when built for Lua 5.2 --- tests/basic.lua | 38 ++++++++++++++++++++++++++------------ tests/keeper.lua | 3 +-- tests/linda_perf.lua | 5 ++++- 3 files changed, 31 insertions(+), 15 deletions(-) (limited to 'tests') diff --git a/tests/basic.lua b/tests/basic.lua index e913906..c35f16a 100644 --- a/tests/basic.lua +++ b/tests/basic.lua @@ -7,8 +7,7 @@ -- - ... -- -local lanes = require "lanes" -lanes.configure() +local lanes = require "lanes".configure{ with_timers = false} require "assert" -- assert.fails() local lanes_gen= assert( lanes.gen ) @@ -49,7 +48,7 @@ local function subtable( a, b ) return true -- is a subtable end --- true when contents of 'a' and 'b' are identific +-- true when contents of 'a' and 'b' are identical -- tables_match= function( a, b ) return subtable( a, b ) and subtable( b, a ) @@ -215,7 +214,7 @@ assert( type(linda) == "userdata" ) local function PEEK() return linda:get("<-") end local function SEND(...) linda:send( "->", ... ) end -local function RECEIVE() local k,v = linda:receive( "<-" ) return v end +local function RECEIVE() local k,v = linda:receive( 1, "<-" ) return v end local t= lanes_gen("io",chunk)(linda) -- prepare & launch @@ -228,7 +227,14 @@ end SEND(3); WR( "3 sent\n" ) local a,b,c= RECEIVE(), RECEIVE(), RECEIVE() - WR( a..", "..b..", "..c.." received\n" ) + +print( "lane status: " .. t.status) +if t.status == "error" then + print( t:join()) +else + WR( a..", "..b..", "..c.." received\n" ) +end + assert( a==1 and b==2 and c==3 ) local a= RECEIVE(); WR( a.." received\n" ) @@ -299,7 +305,7 @@ local function chunk2( linda ) -- for k,v in pairs(info) do PRINT(k,v) end - assert( info.nups == 2 ) -- one upvalue + PRINT + assert( info.nups == (_VERSION == "Lua 5.1" and 2 or 3) ) -- one upvalue + PRINT + _ENV (Lua 5.2 only) assert( info.what == "Lua" ) --assert( info.name == "chunk2" ) -- name does not seem to come through assert( string.match( info.source, "^@.*basic.lua$" ) ) @@ -327,7 +333,10 @@ linda:send( "down", function(linda) linda:send( "up", "ready!" ) end, "ok" ) -- wait to see if the tiny function gets executed -- -local k,s= linda:receive( "up" ) +local k,s= linda:receive( 1, "up" ) +if t2.status == "error" then + print( "t2 error: " , t2:join()) +end PRINT(s) assert( s=="ready!" ) @@ -355,16 +364,21 @@ local S= lanes_gen( "table", for i, v in ipairs(arg) do table.insert (aux, 1, v) end - return unpack(aux) + -- unpack was renamed table.unpack in Lua 5.2: cater for both! + return (unpack or table.unpack)(aux) end ) h= S { 12, 13, 14 } -- execution starts, h[1..3] will get the return values local a,b,c,d= h:join() -assert(a==14) -assert(b==13) -assert(c==12) -assert(d==nil) +if h.status == "error" then + print( "h error: " , a, b, c, d) +else + assert(a==14) + assert(b==13) + assert(c==12) + assert(d==nil) +end -- io.stderr:write "Done! :)\n" diff --git a/tests/keeper.lua b/tests/keeper.lua index 40c9e11..73ed3cf 100644 --- a/tests/keeper.lua +++ b/tests/keeper.lua @@ -4,8 +4,7 @@ -- Test program for Lua Lanes -- -local lanes = require "lanes" -lanes.configure() +local lanes = require "lanes".configure{ with_timers = false} local function keeper(linda) local mt= { diff --git a/tests/linda_perf.lua b/tests/linda_perf.lua index 87e0da7..be582ce 100644 --- a/tests/linda_perf.lua +++ b/tests/linda_perf.lua @@ -1,6 +1,9 @@ local lanes = require "lanes" lanes.configure() +-- Lua 5.1/5.2 compatibility +local table_unpack = unpack or table.unpack + -- this lane eats items in the linda one by one local eater = function( l, loop) local key, val = l:receive( "go") @@ -131,7 +134,7 @@ local function ziva2( preloop, loop, batch) end -- create a function that can send several values in one shot batch_send = function() - l:send( "key", unpack( batch_values)) + l:send( "key", table_unpack( batch_values)) end batch_read = function() l:receive( l.batched, "key", batch) -- cgit v1.2.3-55-g6feb