aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2019-12-13 10:44:08 +0100
committerBenoit Germain <bnt.germain@gmail.com>2019-12-13 10:44:08 +0100
commit5add9b9e8ecb48d5e29556e5c655e6573c60c2b4 (patch)
treed5f368671b206034fad3215532b9db1fd3209d03
parent4109442fc48cfb30f83c4f0de8a62d51a9781249 (diff)
downloadlanes-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.lua35
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
2local register_func = true
3
4local 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"
15end
16
17
18local lanes = require "lanes".configure{ with_timers = false, on_state_create = RequireAModuleThatExportsGlobalFunctions}
19
20-- load some module that adds C functions to the global space
21RequireAModuleThatExportsGlobalFunctions()
22
23local GlobalFuncUpval = GlobalFunc
24
25-- a lane that makes use of the above global
26local f = function()
27 GlobalFuncUpval("foo")
28 print "f done"
29end
30
31
32local g = lanes.gen( "*", f)
33
34-- generate a lane, this will transfer f, which pulls GlobalFunc.
35local h = g() \ No newline at end of file