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:
parent
e39535c9fd
commit
1f4df91c30
26
luaa.h
26
luaa.h
|
@ -254,23 +254,37 @@ luaA_usemetatable(lua_State *L, int idxobj, int idxfield)
|
||||||
return 0;
|
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.
|
/** Register a function.
|
||||||
* \param L The Lua stack.
|
* \param L The Lua stack.
|
||||||
* \param idx Index of the function in the stack.
|
* \param idx Index of the function in the stack.
|
||||||
* \param fct A luaA_ref address: it will be filled with the luaA_ref
|
* \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
|
* registered. If the adresse point to an already registered function, it will
|
||||||
* be unregistered.
|
* be unregistered.
|
||||||
* \return Always 0.
|
* \return luaA_register value.
|
||||||
*/
|
*/
|
||||||
static inline int
|
static inline int
|
||||||
luaA_registerfct(lua_State *L, int idx, luaA_ref *fct)
|
luaA_registerfct(lua_State *L, int idx, luaA_ref *fct)
|
||||||
{
|
{
|
||||||
luaA_checkfunction(L, idx);
|
luaA_checkfunction(L, idx);
|
||||||
lua_pushvalue(L, idx);
|
return luaA_register(L, idx, fct);
|
||||||
if(*fct != LUA_REFNIL)
|
|
||||||
luaL_unref(L, LUA_REGISTRYINDEX, *fct);
|
|
||||||
*fct = luaL_ref(L, LUA_REGISTRYINDEX);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Execute an Lua function.
|
/** Execute an Lua function.
|
||||||
|
|
Loading…
Reference in New Issue