[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: "module" tutorial
- From: Mildred <ml.mildred593@...>
- Date: Thu, 13 Apr 2006 23:11:48 +0200
On Thu, 13 Apr 2006 22:24:37 +0800 陈果 wrote:
> LUAELALIB_API int luaopen_mylib(lua_State *L) {
> luaL_register(L, "mylibname", mylib);
> /* The mylibname table is now on the stack; add any manipulation of
> that table here. */
> return 1;
> }
Personnaly, I prefer :
LUAELALIB_API int luaopen_mylib(lua_State *L) {
lua_newtable(L);
luaL_register(L, NULL, mylib);
return 1;
}
Then, if you profice others luaopen_* functions, you can easily change
the name of your module just by renaming the file.
You can also do tat in the lua modules because the lua module name is
passed as parameter.
module((...), package.seeall)
Something Idon't like about the module() functiuon is that this
functiuon creates a global table that contains the module.
I prefer when no global table is created, then, the global environment
is always clean and you know what you put in there.
Any thoughts about that ?
--
Mildred <xmpp:mildred@jabber.fr> <http://mildred632.free.fr/>
Clef GPG : <hkp://pgp.mit.edu> ou <http://mildred632.free.fr/gpg_key>
Fingerprint : 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 [9A7D 2E2B]