[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: as so often before require()
- From: "Peter Hill" <corwin@...>
- Date: Tue, 18 Feb 2003 12:20:58 +0800
> Wim has written a Lua Technical Note about this that only today I found
> time to add to the site. So there it is:
>
> LTN 11 - Require revisited: Import, by Wim Couwenberg
> http://www.lua.org/notes/ltn011.html
Thanks, that was interesting!
It makes reference to LTN7 (modularising by returning a table) which is
something I just naturally do myself when using "dofile".
But, in the case of "packages", I wonder if that is appropriate? Presumably
packages are not meant to attack the global name space (Wim mentions that no
protection is offered to force packages to be 'nice') so perhaps, in their
case, it might simply be more appropriate to wrap their import with a global
table and let them alter that? The "import" call would then return that
table.
In order to keep the cyclic access protection one would keep the 'stub'
table mentioned by Wim but, instead of a returned definition function, one
would also create a temporary global table to wrap the package execution in.
After the package is fully executed the contents of the temporary global
table would be copied into the stub, and the stub would be unlocked (against
cyclic accesses).
Whether using this method, or that of LTN11, the (currently undocumented)
metamethods that prevent "get/setmetatable" should be used on the stub
table. Rather than returning an error, "import" should probably store the
metatable and enable it upon unlocking the stub.
*cheers*
Peter Hill.
Ki: Contractors... high-paid leeches stealing our work.
Fooker: If you think of them as disposable employees, you'll feel much
better...