lua-users home
lua-l archive

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


On Mon, 11 Feb 2002, Lucas Ackerman wrote:

> Ok, so that is already doable, but it's not what I'm asking for.  In 4.0,
> you can get away with just hiding globals, and in your case you
> don't need to do this from within Lua.  But if someone does want to
> do this within Lua (I can think of any number of reasons -
> demarshalling object references, more flexible sandbox setup, etc),
> with a more recent build that uses lexical scoping, then they need to
> be able to hide the enclosing scope, which was the real point of this
> suggestion.

Lexical scoping only works for things literally defined inside the
scope. If a function is not literally written inside the scope of a
local variable, it does not have access to that variable.

As an important particular case, strings run through `dostring' do not
have access to the scope where `dostring' is running:

  local a;
  dostring("a=a+1")      -- this `a' is global!

So, unless the code you want to protect is literally inside your program,
nothing changes from 4.0 to 4.1.

-- Roberto