lua-users home
lua-l archive

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

Is the _env  a global veriable?

On Sun, Dec 21, 2008 at 23:10, Li Hui <> wrote:
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: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)
      prog ()

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?


Linker Lin