Library Guidelines

lua-users home
wiki

There are no official guidelines but it may be good to do as explained here.

Feel free to modify it if is does not reflect the community habits. This page isn't finished yet.

register function

This is the common way to do. while calling luaL_register, you can replace "modulename" by NULL. The require function will do the nessary to register the module into package.loaded[modulename] and the name of the module will be easy to change.

static const luaL_reg register_module[] = {
	{ "lua_function_name",		c_function_name },
	...
	{ NULL,				NULL	}
};

LUALIB_API int luaopen_modulename(lua_State* L) {
	luaL_register(L, "modulename", register_module);
	return 1;
}

register userdata's metatables

You should use luaL_newmetatable that push the metatable given a name, if the metatable does not exists, it creates it and pushes it, so you can fill it in. For example :

	if(luaL_newmetatable(L, "metatable name")){
		/* fill it in */
	}

You should be careful with the metatable name to avoid collisions with others modules. For example, you can use URI as the namespaces in the XML documents.


RecentChanges · preferences
edit · history
Last edited June 18, 2009 11:37 am GMT (diff)