lua-users home
lua-l archive

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


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.