Library Guidelines |
|
Feel free to modify it if is does not reflect the community habits. This page isn't finished yet.
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;
}
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.