[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Modules from the ground up
- From: Sean Conner <sean@...>
- Date: Wed, 26 Oct 2011 17:31:41 -0400
It was thus said that the Great Philipp Janda once stated:
> On 21.10.2011 06:10, Sean Conner wrote:
> >
> >[...]
> > Code wanting to be a module would do:
> >
> > ----[ sample.lua ]---------
> >
> > local string = _REQUIRE("string")
> > _MODULE()
> > function split(s,delim) ... end
> > function wrap(s,margin) ... end
> > function trim(s) ...end
>
> You forgot 'return _ENV'! Since _MODULE does not get the module name, it
> cannot pass the exported definitions via 'package.loaded[ name ]'. So
> you must pass the exported definitions via 'return'.
>
> If you add 'return _ENV', _MODULE() becomes '_ENV = {}'.
I was trying to come up with a way around that. I'm still thinking.
-spc