[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Load Compiled Script?
- From: "Wim Couwenberg" <w.couwenberg@...>
- Date: Wed, 30 Apr 2003 12:01:09 +0200
And of course, now all loaded functions got the proxy as their
environment... Sigh. Actually testing the code led to the following
version that seems to work... Yay!
function dofile_protected(fname)
local globals = getfenv(2) -- globals of caller...
local proxy = {}
setmetatable(proxy, {
__index = function() return nil end,
__newindex = function(_, index, value)
if type(value) == "function" then
setfenv(value, globals)
globals[index] = value
else
-- non-function assignment
end
end,
})
-- load and execute script file in proxy context
local f = loadfile(fname)
setfenv(f, proxy)
f()
end
Bye,
Wim