lua-users home
lua-l archive

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


On Thu, Sep 8, 2011 at 1:49 PM, Axel Kittenberger <axkibe@gmail.com> wrote:
> In Lua you can do setfenv/_ENV to simulate with - if you absolutely have to.

In the early drafts of Lua 5.2 there was a similar feature to 'with',
and the problem was that people expected it to work like 'with'.

The trouble comes from any locals that happen to be hanging around ...

do
  _ENV = t
  x = 1
  y = 2
  z = 3
end

Cool, but it will break as soon as there's a local 'y' in some
enclosing scope. Not nice!

VB needed an explicit '.' dot in its with statement, which is one of
the few cool things about VB

Personally, I like solving the problem with a macro which provides
something similar to VB:

https://github.com/stevedonovan/LuaMacro/blob/master/tests/test-with.lua

steve d.