suppose i have a file name "test.lua" containing lines below:
--[[ test.lua --]] local f = function() print"local function f in test.lua" end f_generate = function() local fun = loadstring(" f()") -- local env = getfenv(1) -- set(fun,env) return fun end f_generate()() --[[ end of test.lua--]]
because loadstring doing its stuff under the global environment, so when i call
i will get an error "attempt to call global 'f' (a nil value)"
the code commented out shows that function environment can't deal with this problem.
cause table is the only data structure in lua, (and function environment and other lots of thing are implement by table), i think is reasonable to assume that the closure are also implement by table, but how can i get it?