diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2020-04-22 11:26:31 +0200 |
---|---|---|
committer | Benoit Germain <bnt.germain@gmail.com> | 2020-04-22 11:26:31 +0200 |
commit | 203790a68020186bf668b2787968aa0d901fc518 (patch) | |
tree | d81307bc7a89030620dd49c71eac9814d72dc383 | |
parent | a24e54d7d506d4ac38516143b25593922a9959cf (diff) | |
parent | 5add9b9e8ecb48d5e29556e5c655e6573c60c2b4 (diff) | |
download | lanes-203790a68020186bf668b2787968aa0d901fc518.tar.gz lanes-203790a68020186bf668b2787968aa0d901fc518.tar.bz2 lanes-203790a68020186bf668b2787968aa0d901fc518.zip |
Merge branch 'master' of https://github.com/LuaLanes/lanes
-rw-r--r-- | tests/manual_register.lua | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/manual_register.lua b/tests/manual_register.lua new file mode 100644 index 0000000..b868bb9 --- /dev/null +++ b/tests/manual_register.lua | |||
@@ -0,0 +1,35 @@ | |||
1 | |||
2 | local register_func = true | ||
3 | |||
4 | local RequireAModuleThatExportsGlobalFunctions = function() | ||
5 | -- grab some module that exports C functions, this is good enough for our purpose | ||
6 | local lfs = require "lfs" | ||
7 | -- make one of these a global | ||
8 | GlobalFunc = lfs.attributes | ||
9 | -- we need to register it so that it is transferable | ||
10 | if register_func then | ||
11 | local lanes = require "lanes" | ||
12 | lanes.register( "GlobalFunc", GlobalFunc) | ||
13 | end | ||
14 | print "RequireAModuleThatExportsGlobalFunctions done" | ||
15 | end | ||
16 | |||
17 | |||
18 | local lanes = require "lanes".configure{ with_timers = false, on_state_create = RequireAModuleThatExportsGlobalFunctions} | ||
19 | |||
20 | -- load some module that adds C functions to the global space | ||
21 | RequireAModuleThatExportsGlobalFunctions() | ||
22 | |||
23 | local GlobalFuncUpval = GlobalFunc | ||
24 | |||
25 | -- a lane that makes use of the above global | ||
26 | local f = function() | ||
27 | GlobalFuncUpval("foo") | ||
28 | print "f done" | ||
29 | end | ||
30 | |||
31 | |||
32 | local g = lanes.gen( "*", f) | ||
33 | |||
34 | -- generate a lane, this will transfer f, which pulls GlobalFunc. | ||
35 | local h = g() \ No newline at end of file | ||