diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2013-01-30 20:28:47 +0100 |
---|---|---|
committer | Benoit Germain <bnt.germain@gmail.com> | 2013-01-30 20:28:47 +0100 |
commit | b657f38535c3c27a848353ef853d6667d6acc917 (patch) | |
tree | 8679a62c0b6343eae4781cff10a0ea60460d9cb4 /tests | |
parent | 3377b95704e611a288791fee6a7bc59c5ecebf2d (diff) | |
download | lanes-b657f38535c3c27a848353ef853d6667d6acc917.tar.gz lanes-b657f38535c3c27a848353ef853d6667d6acc917.tar.bz2 lanes-b657f38535c3c27a848353ef853d6667d6acc917.zip |
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
Diffstat (limited to 'tests')
-rw-r--r-- | tests/fibonacci.lua | 9 | ||||
-rw-r--r-- | tests/package.lua | 20 | ||||
-rw-r--r-- | tests/pingpong.lua | 31 | ||||
-rw-r--r-- | tests/timer.lua | 5 |
4 files changed, 60 insertions, 5 deletions
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 } | |||
28 | -- uint= fib( n_uint ) | 28 | -- uint= fib( n_uint ) |
29 | -- | 29 | -- |
30 | local function fib( n ) | 30 | local function fib( n ) |
31 | --local lanes = require"lanes".configure() | ||
31 | -- | 32 | -- |
32 | local sum | 33 | local sum |
33 | local floor= assert(math.floor) | 34 | local floor= assert(math.floor) |
@@ -39,9 +40,11 @@ local function fib( n ) | |||
39 | else | 40 | else |
40 | -- Splits into two; this task remains waiting for the results | 41 | -- Splits into two; this task remains waiting for the results |
41 | -- | 42 | -- |
42 | -- note that lanes is pulled in as upvalue, so we need package library to require internals properly | 43 | -- note that lanes is pulled in by upvalue, so we need lanes.core to be available |
43 | -- (because lua51-lanes is always required internally if possible, which is necessary in that case) | 44 | -- the other solution is to require "lanes" from inside the lane body, as in: |
44 | local gen_f= lanes.gen( "*", fib ) | 45 | -- local lanes = require"lanes".configure() |
46 | -- local gen_f= lanes.gen( "*", fib) | ||
47 | local gen_f= lanes.gen( "*", {required={"lanes.core"}}, fib) | ||
45 | 48 | ||
46 | local n1=floor(n/2) +1 | 49 | local n1=floor(n/2) +1 |
47 | local n2=floor(n/2) -1 + n%2 | 50 | 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 @@ | |||
1 | assert(nil == package.loaders[5]) | ||
2 | |||
3 | local configure_loaders = function() | ||
4 | table.insert(package.loaders, 4, function() end) | ||
5 | assert(package.loaders[1]) | ||
6 | assert(package.loaders[2]) | ||
7 | assert(package.loaders[3]) | ||
8 | assert(package.loaders[4]) | ||
9 | assert(package.loaders[5]) | ||
10 | print "loaders configured!" | ||
11 | end | ||
12 | |||
13 | configure_loaders() | ||
14 | |||
15 | for k,v in pairs(package.loaders) do | ||
16 | print( k, type(v)) | ||
17 | end | ||
18 | |||
19 | lanes = require "lanes" | ||
20 | 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 @@ | |||
1 | local lanes = require 'lanes'.configure() | ||
2 | local q = lanes.linda() | ||
3 | |||
4 | local pingpong = function(name, qr, qs, start) | ||
5 | print("start " .. name, qr, qs, start) | ||
6 | local count = 0 | ||
7 | if start then | ||
8 | print(name .. ": sending " .. qs .. " 0") | ||
9 | q:send(qs, 0) | ||
10 | end | ||
11 | while count < 10 do | ||
12 | print(name .. ": receiving " .. qr) | ||
13 | local key, val = q:receive(qr) | ||
14 | if val == nil then | ||
15 | print(name .. ": timeout") | ||
16 | break | ||
17 | end | ||
18 | print(name .. ":" .. val) | ||
19 | val = val + 1 | ||
20 | print(name .. ": sending " .. qs .. " " .. tostring(val + 1)) | ||
21 | q:send(qs, val) | ||
22 | count = count + 1 | ||
23 | end | ||
24 | end | ||
25 | |||
26 | -- pingpong("L1", '0', '1', true) | ||
27 | local t1, err1 = lanes.gen("*", pingpong)("L1", 'a', 'b', true) | ||
28 | local t2, err2 = lanes.gen("*", pingpong)("L2", 'b', 'a', false) | ||
29 | |||
30 | t1:join() | ||
31 | 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 @@ | |||
8 | io.stderr:setvbuf "no" | 8 | io.stderr:setvbuf "no" |
9 | 9 | ||
10 | 10 | ||
11 | local lanes = require "lanes" | 11 | local lanes = require "lanes".configure() |
12 | lanes.configure() | ||
13 | 12 | ||
14 | local linda= lanes.linda() | 13 | local linda= lanes.linda() |
15 | 14 | ||
@@ -101,3 +100,5 @@ PRINT "...making sure no ticks are coming..." | |||
101 | local k,v= linda:receive( 10, T1,T2 ) -- should not get any | 100 | local k,v= linda:receive( 10, T1,T2 ) -- should not get any |
102 | assert(v==nil) | 101 | assert(v==nil) |
103 | 102 | ||
103 | lanes.timer_lane:cancel() | ||
104 | print (lanes.timer_lane[1], lanes.timer_lane[2]) \ No newline at end of file | ||