From 79e46938c5d8daf164ab2d934f668fa27b32e4cf Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Tue, 4 Jan 2011 21:31:17 +0100 Subject: Take all code from Asko Kauppi's SVN server, and push it here so that the github repository becomes the official Lanes source codebase. Note that Asko's SVN server holds version 2.0.9, whereas this is version 2.0.10, but I don't see any real need to update SVN if it is to become deprecated. Next steps: - upgrade the rockspec to the latest version - make the html help available online somewhere Signed-off-by: Benoit Germain --- tests/appendud.lua | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/basic.lua | 52 +++++++++++++++++++++---------------------- tests/func_is_string.lua | 12 ++++++++++ 3 files changed, 96 insertions(+), 26 deletions(-) create mode 100644 tests/appendud.lua create mode 100644 tests/func_is_string.lua (limited to 'tests') diff --git a/tests/appendud.lua b/tests/appendud.lua new file mode 100644 index 0000000..afea0e9 --- /dev/null +++ b/tests/appendud.lua @@ -0,0 +1,58 @@ +-- +-- APPENDUD.LUA +-- +-- Lanes version for John Belmonte's challenge on Lua list (about finalizers): +-- +-- +-- Needs Lanes >= 2.0.3 +-- +require "lanes" + +local _tab = { + beginupdate = function (this) print('tab.beginupdate') end; + endupdate = function (this) print('tab.endupdate') end; +} +local _ud = { + lock = function (this) print('ud.lock') end; + unlock = function (this) print('ud.unlock') end; + 1,2,3,4,5; +} + +-- +-- This sample is with the 'finalize/guard' patch applied (new keywords): +-- +--function appendud(tab, ud) +-- tab:beginupdate() finalize tab:endupdate() end +-- ud:lock() finalize ud:unlock() end +-- for i = 1,#ud do +-- tab[#tab+1] = ud[i] +-- end +--end + + +function appendud(tab, ud) +io.stderr:write "Starting" + tab:beginupdate() set_finalizer( function() tab:endupdate() end ) + ud:lock() set_finalizer( function() ud:unlock() end ) + for i = 1,#ud do + tab[#tab+1] = ud[i] + end +io.stderr:write "Ending" + return tab -- need to return 'tab' since we're running in a separate thread + -- ('tab' is passed over lanes by value, not by reference) +end + +local t,err= lanes.gen( appendud )( _tab, _ud ) -- create & launch a thread +assert(t) +assert(not err) + +-- test + +t:join() -- Need to explicitly wait for the thread, since 'ipairs()' does not + -- value the '__index' metamethod (wouldn't it be cool if it did..?) + +io.stderr:write(t[1]) + +for k,v in ipairs(t) do + print(k,v) +end diff --git a/tests/basic.lua b/tests/basic.lua index ee31ed1..b1e8fd3 100644 --- a/tests/basic.lua +++ b/tests/basic.lua @@ -2,7 +2,7 @@ -- BASIC.LUA Copyright (c) 2007-08, Asko Kauppi -- -- Selftests for Lua Lanes --- +-- -- To do: -- - ... -- @@ -20,7 +20,7 @@ local function PRINT(...) for i=1,select('#',...) do str= str..tostring(select(i,...)).."\t" end - if io then + if io then io.stderr:write(str.."\n") end end @@ -55,7 +55,7 @@ tables_match= function( a, b ) end ----=== Tasking (basic) ===--- +PRINT( "---=== Tasking (basic) ===---") local function task( a, b, c ) --error "111" -- testing error messages @@ -98,7 +98,7 @@ assert( lane1.status == "done" ) assert( lane1.status == "done" ) ----=== Tasking (cancelling) ===--- +PRINT( "---=== Tasking (cancelling) ===---") local task_launch2= lanes_gen( "", { cancelstep=100, globals={hey=true} }, task ) @@ -136,7 +136,7 @@ PRINT(" "..st) assert( st == "cancelled" ) ----=== Communications ===--- +PRINT( "---=== Communications ===---") local function WR(...) io.stderr:write(...) end @@ -157,7 +157,7 @@ local chunk= function( linda ) send { 'a', 'b', 'c', d=10 }; WR( "{'a','b','c',d=10} sent\n" ) v=receive(); WR( v.." received\n" ); assert( v==4 ) - + WR( "Lane ends!\n" ) end @@ -195,7 +195,7 @@ assert( PEEK() == nil ) SEND(4) ----=== Stdlib naming ===--- +PRINT( "---=== Stdlib naming ===---") local function io_os_f() assert(io) @@ -215,7 +215,7 @@ assert( f2()[1] ) assert( f3()[1] ) ----=== Comms criss cross ===--- +PRINT( "---=== Comms criss cross ===---") -- We make two identical lanes, which are using the same Linda channel. -- @@ -241,7 +241,7 @@ local a,b= tc(linda, "A","B"), tc(linda, "B","A") -- launching two lanes, twis local _= a[1],b[1] -- waits until they are both ready ----=== Receive & send of code ===--- +PRINT( "---=== Receive & send of code ===---") local upvalue="123" @@ -251,21 +251,21 @@ local function chunk2( linda ) -- function name & line number should be there even as separate thread -- local info= debug.getinfo(1) -- 1 = us - -- - for k,v in pairs(info) do PRINT(k,v) end - - assert( info.nups == 2 ) -- one upvalue + PRINT - assert( info.what == "Lua" ) - - --assert( info.name == "chunk2" ) -- name does not seem to come through - assert( string.match( info.source, "^@tests[/\\]basic.lua$" ) ) - assert( string.match( info.short_src, "^tests[/\\]basic.lua$" ) ) - - -- These vary so let's not be picky (they're there..) - -- - assert( info.linedefined > 200 ) -- start of 'chunk2' - assert( info.currentline > info.linedefined ) -- line of 'debug.getinfo' - assert( info.lastlinedefined > info.currentline ) -- end of 'chunk2' + -- + for k,v in pairs(info) do PRINT(k,v) end + + assert( info.nups == 2 ) -- one upvalue + PRINT + assert( info.what == "Lua" ) + + --assert( info.name == "chunk2" ) -- name does not seem to come through + assert( string.match( info.source, "^@basic.lua$" ) ) + assert( string.match( info.short_src, "^basic.lua$" ) ) + + -- These vary so let's not be picky (they're there..) + -- + assert( info.linedefined > 200 ) -- start of 'chunk2' + assert( info.currentline > info.linedefined ) -- line of 'debug.getinfo' + assert( info.lastlinedefined > info.currentline ) -- end of 'chunk2' local func,k= linda:receive( "down" ) assert( type(func)=="function" ) @@ -275,7 +275,7 @@ local function chunk2( linda ) local str= linda:receive( "down" ) assert( str=="ok" ) - + linda:send( "up", function() return ":)" end, "ok2" ) end @@ -304,7 +304,7 @@ local ok2= linda:receive( "up" ) assert( ok2 == "ok2" ) ----=== :join test ===--- +PRINT( "---=== :join test ===---") -- NOTE: 'unpack()' cannot be used on the lane handle; it will always return nil -- (unless [1..n] has been read earlier, in which case it would seemingly diff --git a/tests/func_is_string.lua b/tests/func_is_string.lua new file mode 100644 index 0000000..98ea62b --- /dev/null +++ b/tests/func_is_string.lua @@ -0,0 +1,12 @@ +require "lanes" + +local options = {globals = { b = 666 }} + +-- local gen1 = lanes.gen("*", "dofile('fibonacci.lua')") +local gen2 = lanes.gen(options, "return b") + +-- fibLane = gen1() +retLane1, retLane2 = gen2(), gen2() +-- fibLane:join() + +print( retLane1[1], retLane2[1]) -- cgit v1.2.3-55-g6feb