diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2019-12-13 10:44:08 +0100 |
---|---|---|
committer | Benoit Germain <bnt.germain@gmail.com> | 2019-12-13 10:44:08 +0100 |
commit | 5add9b9e8ecb48d5e29556e5c655e6573c60c2b4 (patch) | |
tree | d5f368671b206034fad3215532b9db1fd3209d03 | |
parent | 4109442fc48cfb30f83c4f0de8a62d51a9781249 (diff) | |
download | lanes-5add9b9e8ecb48d5e29556e5c655e6573c60c2b4.tar.gz lanes-5add9b9e8ecb48d5e29556e5c655e6573c60c2b4.tar.bz2 lanes-5add9b9e8ecb48d5e29556e5c655e6573c60c2b4.zip |
Create manual_register.lua
New test sample to demonstrate on_state_create and manual function registration.
-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 | ||