[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Basic, no fuss, no magic, foolproof module pattern. [Was: require, module, globals and "magic"]
- From: Quae Quack <quae@...>
- Date: Fri, 20 Aug 2010 10:35:38 +1000
On 19 August 2010 04:51, Lorenzo Donati <lorenzodonatibz@interfree.it> wrote:
> On a related note, may I assume from what you said that now the standard
> contract for a module can be (incompletely) summarized as in the following
> lines?
>
> 1. when loaded and called, a module's chunk should return a table containing
> its "exported" symbols
> 2. a module should not create any global
> 3. ? any more items in the contract?
These would be reasonable starting points for "best practices".
I would rephrase 2. to: "a module should be fully self contained, not
creating or using globals other than the base libraries"
Others conditions might be:
Don't use a debug hook for longer than a function's duration; and
bubble any other hooks up;
Don't change common metatables (eg, string/lightuserdata)
> (BTW should this contract be the same for both Lua and C modules?)
Yes; using luaL_register with a NULL argument leaves the table on the
stack, so you can "return 1".
Daurn.
- References:
- Basic, no fuss, no magic, foolproof module pattern. [Was: require, module, globals and "magic"], Lorenzo Donati
- Re: Basic, no fuss, no magic, foolproof module pattern. [Was: require, module, globals and "magic"], Sean Conner
- Re: Basic, no fuss, no magic, foolproof module pattern. [Was: require, module, globals and "magic"], Lorenzo Donati
- Re: Basic, no fuss, no magic, foolproof module pattern. [Was: require, module, globals and "magic"], Roberto Ierusalimschy
- Re: Basic, no fuss, no magic, foolproof module pattern. [Was: require, module, globals and "magic"], Lorenzo Donati
- Prev by Date:
Re: cross-compile alien
- Next by Date:
Re: Basic, no fuss, no magic, foolproof module pattern. [Was: require, module, globals and "magic"]
- Previous by thread:
Re: Basic, no fuss, no magic, foolproof module pattern. [Was: require, module, globals and "magic"]
- Next by thread:
Re: Basic, no fuss, no magic, foolproof module pattern. [Was: require, module, globals and "magic"]
- Index(es):