lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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