[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Module metatable
- From: Luis Carvalho <carvalho@...>
- Date: Tue, 22 Feb 2005 10:54:59 -0500
On Tue, Feb 22, 2005 at 11:07:03AM -0300, Roberto Ierusalimschy wrote:
> There is a hidden rule in Lua that only the creator of a table should
> set (or change) its metatable. Other code may change a metatable's
> fields, but should not change the metatable itself.
Very reasonable. But the point is: who created the table first (and registered
as global), ll_module or the module's luaL_openlib?
> So, in the case of modules created with the "module" function, only the
> package system should set the module's metatable. Whenever it does that
> it also sets the _NAME field; therefore, to test for a MT is redundant
> with the test for _NAME.
Ah, so the rule is "only the package system should set the module's MT". Fine
with me. But note that this does not invalidate the argument in my previous
post: if the package system sets the module table, then it should be ok for the
former to set the latter's MT; but if the module sets its own table (through
luaL_openlib), the package system should care only for the module's MT __index
> After "module" sets a module's metatable, it is OK for another code
> to add a __call metamethod on it.
Ok, I've already done so in order to preserve my lua dist vanilla. But things
could be a little easier, nevertheless.
A mathematician is a device for turning coffee into theorems.
-- P. Erdos
Applied Math PhD Student - Brown University
PGP Key: E820854A <firstname.lastname@example.org>