diff options
Diffstat (limited to 'tests/irayo_closure.lua')
-rw-r--r-- | tests/irayo_closure.lua | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/irayo_closure.lua b/tests/irayo_closure.lua new file mode 100644 index 0000000..faf08fd --- /dev/null +++ b/tests/irayo_closure.lua | |||
@@ -0,0 +1,35 @@ | |||
1 | -- | ||
2 | -- Bugs filed by irayo Jul-2008 | ||
3 | -- | ||
4 | --[[ | ||
5 | "Another issue I've noticed is trying to pass a table with a function | ||
6 | that uses closures in it as a global variable into a new lane. This | ||
7 | causes a segmentation fault and it appears to be related to the | ||
8 | luaG_inter_move function near line 835-836 or so in lanes.c, but I | ||
9 | haven't investigated further. | ||
10 | e.g. { globals = { data = 1, func = function() useclosurehere() end } }" | ||
11 | ]] | ||
12 | |||
13 | require "lanes" | ||
14 | |||
15 | local function testrun() | ||
16 | assert( print ) | ||
17 | assert( data==1 ) | ||
18 | assert( type(func)=="function" ) | ||
19 | func() -- "using the closure" | ||
20 | return true | ||
21 | end | ||
22 | |||
23 | -- Should also work without these lines, but currently doesn't (bug in Lanes, | ||
24 | -- a function thrown over isn't connected to receiving lane's globals) | ||
25 | -- | ||
26 | --local print=print | ||
27 | --local assert=assert | ||
28 | |||
29 | local function useclosurehere() | ||
30 | assert( print ) | ||
31 | print "using the closure" | ||
32 | end | ||
33 | |||
34 | local lane= lanes.gen( "", { globals = { data=1, func=useclosurehere } }, testrun )() | ||
35 | print(lane[1]) | ||