[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: why get a function`s environment without use it?
- From: "Li Hui" <xylophone21@...>
- Date: Sun, 21 Dec 2008 23:10:24 +0800
Hi all:
Sorry that I forget to modify the subject last mail.So I resend it.
------------------------------------------------------------------------------------
I read the source code of cgilua-5.1.2 this days.And I found this
function below:
function include (filename, env)
-- read the whole contents of the file
local fh = assert (open (filename))
local src = fh:read("*a")
fh:close()
-- translates the file into a function
local prog = compile (src, '@'..filename) -- return a function
local _env
if env then
_env = getfenv (prog) --why call use getfenv here?
setfenv (prog, env)
end
prog ()
end
compile will return a function .
My question is why here use "_env = getfenv (prog)" to get the prog
function`s environment,but never usr it?
3ks
--
lihui