lua-users home
lua-l archive

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

> I guess loadstring() would use the _ENV in the lexical scope of its
> call site?

Just follow the rules (1 & 2). loadstring is a specific form of load. It
will enclose the string with a new "local _ENV=<some value>", where
<some value> is the global table.

Lexical scope means that _ENV is only visible by code that is lexically
in its scope.

Of course, you can write "loadin(_ENV, string)" and then make the
string share the lexical scope of its call site. But you must pass _ENV
explicitly; nobody can access it outside its lexical scope (except using
the debug API).

-- Roberto