lua-users home
lua-l archive

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

I would indeed expect it to inherit from the caller, to be more similar with a normal function declaration. But it is a detail since doing setglobals works very well ...

By the way, congratulation for bringing to us such a wonderful language !

Roberto Ierusalimschy wrote:

I have remarked an unexpected behaviour (to me) of the lua loadfile function. It returns a function, but it seems this function does not herit the global table from the caller of the loadfile function. Is it on purpose ? Which global table is assigned to it ?

Currently, loadfile (and loadstring) always returns a function with the
default global table (that is, the one used by the C functions). It
is very easy to change it before running the chunk, so that all functions
created by the chunck already get the new table:

 local f = loadfile"..."
 setglobals(f, t)

But we can change that.

-- Roberto