luaobject: define an common object and a standard gc

This commit is contained in:
Julien Danjou 2009-06-16 16:12:07 +02:00
parent cbff5fe9dd
commit 6b24af7238
1 changed files with 23 additions and 0 deletions

View File

@ -38,6 +38,17 @@ luaA_settype(lua_State *L, const char *type)
DO_ARRAY(luaA_ref, luaA_ref, DO_NOTHING)
#define LUA_OBJECT_HEADER \
luaA_ref_array_t refs;
/** Generic type for all objects.
* All Lua objects can be casted to this type.
*/
typedef struct
{
LUA_OBJECT_HEADER
} lua_object_t;
#define LUA_OBJECT_FUNCS(type, prefix, lua_type) \
static inline type * \
prefix##_new(lua_State *L) \
@ -82,6 +93,18 @@ DO_ARRAY(luaA_ref, luaA_ref, DO_NOTHING)
} \
}
/** Garbage collect a Lua object.
* \param L The Lua VM state.
* \return The number of elements pushed on stack.
*/
static inline int
luaA_object_gc(lua_State *L)
{
lua_object_t *item = lua_touserdata(L, 1);
luaA_ref_array_wipe(&item->refs);
return 0;
}
#endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80