lua-users home
lua-l archive

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


Hi,

Is there any guidelines for writing C libraries for lua aviable
somewhere ? If not, why not having a such page, maybe on the lua.org
website or lua-users.org ...

For example, what is the best way to implement luaopen_* functions, How
to register userdata's metatables and things like that.

Something else, I have my own way to register metatables which use
luaL_newmetatable with uri like the ones used in XML namespaces (xmlns)
to avoid collisions. For example:

void L);
lua_State* L) {
	if(luaL_newmetatable(L, "http://purl.org/NET/louve/2006/foo";)){
		lua_pushliteral(L, "key")
		lua_push...(...);
		lua_rawset(L, -3);
	}
}

Using it:

	/* create the metatable*/
	push_metatable(L);
	lua_setmetatable(L, -2);

Is it the best way to do it ?
Does evryone uses unique URI like me ? if not, how to avoid collisions
in the registery between libraries ?


Mildred
-- 
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]


-- 
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]