lua-users home
lua-l archive

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


2013/4/10 steve donovan <steve.j.donovan@gmail.com>:
> On Wed, Apr 10, 2013 at 9:03 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>>
>> > However, using it for namespacing ties one to 5.2 prematurely.
>> How about giving us a little example?
>
>
> -- new style Lua 5.2 module
> local _ENV = {}
> function answer() return 42 end
> return _ENV
>
...
> But why not just
>
> local M = {}
> function M.answer() return 42 end
> return M

In fact, much rather.

I was bitten for about two weeks by the possibility of doing as
in your example, but quickly discovered that having the standard
library functions undefined except those cached as upvalues
was intensely annoying.