luaa: split luaA_register() out of luaA_registerfct()

This allow to register other items.

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-10-20 11:43:58 +02:00
parent e39535c9fd
commit 1f4df91c30
1 changed files with 20 additions and 6 deletions

26
luaa.h
View File

@ -254,23 +254,37 @@ luaA_usemetatable(lua_State *L, int idxobj, int idxfield)
return 0;
}
/** Register an Lua object.
* \param L The Lua stack.
* \param idx Index of the object in the stack.
* \param fct A luaA_ref address: it will be filled with the luaA_ref
* registered. If the adresse point to an already registered object, it will
* be unregistered.
* \return Always 0.
*/
static inline int
luaA_register(lua_State *L, int idx, luaA_ref *ref)
{
lua_pushvalue(L, idx);
if(*ref != LUA_REFNIL)
luaL_unref(L, LUA_REGISTRYINDEX, *ref);
*ref = luaL_ref(L, LUA_REGISTRYINDEX);
return 0;
}
/** Register a function.
* \param L The Lua stack.
* \param idx Index of the function in the stack.
* \param fct A luaA_ref address: it will be filled with the luaA_ref
* registered. If the adresse point to an already registered function, it will
* be unregistered.
* \return Always 0.
* \return luaA_register value.
*/
static inline int
luaA_registerfct(lua_State *L, int idx, luaA_ref *fct)
{
luaA_checkfunction(L, idx);
lua_pushvalue(L, idx);
if(*fct != LUA_REFNIL)
luaL_unref(L, LUA_REGISTRYINDEX, *fct);
*fct = luaL_ref(L, LUA_REGISTRYINDEX);
return 0;
return luaA_register(L, idx, fct);
}
/** Execute an Lua function.