aboutsummaryrefslogtreecommitdiff
path: root/tests/manual_register.lua
blob: b868bb97ee5091c52b6db28b086c3e6c0a03bf73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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()