lua-users home
lua-l archive

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




On Thu, Aug 12, 2010 at 10:01 PM, David Manura <dm.lua@math2.org> wrote:
On Tue, Aug 10, 2010 at 1:42 PM, Shawn Fox <shawnkfox@gmail.com> wrote:
> So based on this I think what I'm really asking for is that something like:
>
> foo = namespace
>     local x = 99
>    function bar(y) print(x+y) end
> end

which isn't too different from what I would recommend below, where f
could be various functions including `namespace` and `class` suitably
defined:

 foo = f(function(M)
   local x = 99
   function M.bar(y) print(x+y) end
 end)

I recognize there are ways to do this already, they are just all ugly.  The _ENV feature in 5.2 is very close, I just think it should be usable with a cleaner syntax instead of having to assign to a magic variable.  loadin is a great solution for this when your code exists in a separate file, but there ought to be a way to do this using a control block as well, perhaps a "doin" statement:

foo={}
doin foo
    x=99
    bar(y) print(x+y) end
end