From 5add9b9e8ecb48d5e29556e5c655e6573c60c2b4 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Fri, 13 Dec 2019 10:44:08 +0100 Subject: Create manual_register.lua New test sample to demonstrate on_state_create and manual function registration. --- tests/manual_register.lua | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/manual_register.lua 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 @@ + +local register_func = true + +local RequireAModuleThatExportsGlobalFunctions = function() + -- grab some module that exports C functions, this is good enough for our purpose + local lfs = require "lfs" + -- make one of these a global + GlobalFunc = lfs.attributes + -- we need to register it so that it is transferable + if register_func then + local lanes = require "lanes" + lanes.register( "GlobalFunc", GlobalFunc) + end + print "RequireAModuleThatExportsGlobalFunctions done" +end + + +local lanes = require "lanes".configure{ with_timers = false, on_state_create = RequireAModuleThatExportsGlobalFunctions} + +-- load some module that adds C functions to the global space +RequireAModuleThatExportsGlobalFunctions() + +local GlobalFuncUpval = GlobalFunc + +-- a lane that makes use of the above global +local f = function() + GlobalFuncUpval("foo") + print "f done" +end + + +local g = lanes.gen( "*", f) + +-- generate a lane, this will transfer f, which pulls GlobalFunc. +local h = g() \ No newline at end of file -- cgit v1.2.3-55-g6feb