From b657f38535c3c27a848353ef853d6667d6acc917 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Wed, 30 Jan 2013 20:28:47 +0100 Subject: version 3.5.0 * new: API lanes.require(), use it instead of regular require() for modules that export C functions you need to send over. * new: lanes no longer require 'lanes.core' by default in every created state. Use {required={"lanes.core"}} if you need to transfer lanes functions. * internal: because of the above, reworked the timer implementation to remove upvalue-dependency on lanes.core * new: API lanes.timer_lane, to be able to operate on timer lane if need be * improved: if a module is a full userdata, scan its metatable for function database population * improved: on_state_create can be a Lua function * changed: on_state_create is called after the base libraries are loaded * package[loaders|searchers] is no longer transfered as function naming depends on slot order * internal: changed separator from '.' to '/' in lookup databases to be able to distinguish search levels and dot coming from module names * added some mode debug spew * updated tests to reflect the above changes --- tests/fibonacci.lua | 9 ++++++--- tests/package.lua | 20 ++++++++++++++++++++ tests/pingpong.lua | 31 +++++++++++++++++++++++++++++++ tests/timer.lua | 5 +++-- 4 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 tests/package.lua create mode 100644 tests/pingpong.lua (limited to 'tests') diff --git a/tests/fibonacci.lua b/tests/fibonacci.lua index 48cd8d7..a5e0b2a 100644 --- a/tests/fibonacci.lua +++ b/tests/fibonacci.lua @@ -28,6 +28,7 @@ local KNOWN= { [0]=0, 1,1,2,3,5,8,13,21,34,55,89,144 } -- uint= fib( n_uint ) -- local function fib( n ) + --local lanes = require"lanes".configure() -- local sum local floor= assert(math.floor) @@ -39,9 +40,11 @@ local function fib( n ) else -- Splits into two; this task remains waiting for the results -- - -- note that lanes is pulled in as upvalue, so we need package library to require internals properly - -- (because lua51-lanes is always required internally if possible, which is necessary in that case) - local gen_f= lanes.gen( "*", fib ) + -- note that lanes is pulled in by upvalue, so we need lanes.core to be available + -- the other solution is to require "lanes" from inside the lane body, as in: + -- local lanes = require"lanes".configure() + -- local gen_f= lanes.gen( "*", fib) + local gen_f= lanes.gen( "*", {required={"lanes.core"}}, fib) local n1=floor(n/2) +1 local n2=floor(n/2) -1 + n%2 diff --git a/tests/package.lua b/tests/package.lua new file mode 100644 index 0000000..7c72d35 --- /dev/null +++ b/tests/package.lua @@ -0,0 +1,20 @@ +assert(nil == package.loaders[5]) + +local configure_loaders = function() + table.insert(package.loaders, 4, function() end) + assert(package.loaders[1]) + assert(package.loaders[2]) + assert(package.loaders[3]) + assert(package.loaders[4]) + assert(package.loaders[5]) + print "loaders configured!" +end + +configure_loaders() + +for k,v in pairs(package.loaders) do + print( k, type(v)) +end + +lanes = require "lanes" +lanes.configure{with_timers=false, on_state_create = configure_loaders} \ No newline at end of file diff --git a/tests/pingpong.lua b/tests/pingpong.lua new file mode 100644 index 0000000..30cd360 --- /dev/null +++ b/tests/pingpong.lua @@ -0,0 +1,31 @@ +local lanes = require 'lanes'.configure() +local q = lanes.linda() + +local pingpong = function(name, qr, qs, start) + print("start " .. name, qr, qs, start) + local count = 0 + if start then + print(name .. ": sending " .. qs .. " 0") + q:send(qs, 0) + end + while count < 10 do + print(name .. ": receiving " .. qr) + local key, val = q:receive(qr) + if val == nil then + print(name .. ": timeout") + break + end + print(name .. ":" .. val) + val = val + 1 + print(name .. ": sending " .. qs .. " " .. tostring(val + 1)) + q:send(qs, val) + count = count + 1 + end +end + +-- pingpong("L1", '0', '1', true) +local t1, err1 = lanes.gen("*", pingpong)("L1", 'a', 'b', true) +local t2, err2 = lanes.gen("*", pingpong)("L2", 'b', 'a', false) + +t1:join() +t2:join() \ No newline at end of file diff --git a/tests/timer.lua b/tests/timer.lua index 953e4ed..805d85c 100644 --- a/tests/timer.lua +++ b/tests/timer.lua @@ -8,8 +8,7 @@ io.stderr:setvbuf "no" -local lanes = require "lanes" -lanes.configure() +local lanes = require "lanes".configure() local linda= lanes.linda() @@ -101,3 +100,5 @@ PRINT "...making sure no ticks are coming..." local k,v= linda:receive( 10, T1,T2 ) -- should not get any assert(v==nil) +lanes.timer_lane:cancel() +print (lanes.timer_lane[1], lanes.timer_lane[2]) \ No newline at end of file -- cgit v1.2.3-55-g6feb