|
The existing functionality (debug.upvaluejoin) is all you need to do
what you want:
- Declare locals to be exported:
local x = 1
export("x", function() return x end) -- **
local y = 2
export("y", function() return y end)
- hook the load function which creates locals with the names of the
exported locals and then joins them to the loaded chunk, something
like:
local new_chunk = "local x,y; return function(...)"..chunk.." end"
local f = original_load(new_chunk)()
-- join exported upvalues on f