[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: local "module" pattern without module [was Re: [ANN] SLAXML - pure Lua, robust-ish, SAX-like streaming XML processor]
- From: steve donovan <steve.j.donovan@...>
- Date: Tue, 19 Feb 2013 08:02:47 +0200
On Tue, Feb 19, 2013 at 4:38 AM, Gavin Kistner <phrogz@me.com> wrote:
> If, on the other hand, you are just making a joke, that is also fine. :)
PA likes making jokes, but they usually have a point ;)
One consequence of setfenv magic is that everything becomes slower,
because you now have indirect lookup for everything (that's another
criticisim of module(...,package.seeall) apart from allowing all your
laundry to be exposed).
The pattern that Tomas gives puts everything explicitly into the
master table. Generally the idea is to keep as much in locals as
possible - which is BTW the reason I'm not so keen on the _ENV 5.2
construction.
I've found myself doing things like this to split a module over
several files (useful if there's extra functionality you might want to
load)
--foo.lua
local foo = {}
function foo.answer() ... end
....
return foo
--foo.extra.lua
local foo = require 'foo'
function foo.more() ... end
end
return foo
I keep to the 'no magic' style because it discriminates equally
against 5.1 and 5.2 ;)
steve d.