Commit 7510a32e authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

LUA: simplify pushing VLC object

Always use the common GC wrapper around vlc_object_release(). While it
is not really required for the instance and the playlist object, the
overhead is negligible in LUA context.
parent 8d663811
......@@ -46,7 +46,7 @@
/*****************************************************************************
* Generic vlc_object_t wrapper creation
*****************************************************************************/
int vlclua_gc_release( lua_State *L )
static int vlclua_object_release( lua_State *L )
{
vlc_object_t **p_obj = (vlc_object_t **)luaL_checkudata( L, 1, "vlc_object" );
lua_pop( L, 1 );
......@@ -62,8 +62,9 @@ static int vlclua_object_find( lua_State *L )
static int vlclua_get_libvlc( lua_State *L )
{
vlclua_push_vlc_object( L, vlclua_get_this( L )->p_libvlc,
NULL );
libvlc_int_t *p_libvlc = vlclua_get_this( L )->p_libvlc;
vlc_object_hold( p_libvlc );
vlclua_push_vlc_object( L, p_libvlc );
return 1;
}
......@@ -72,8 +73,8 @@ static int vlclua_get_playlist( lua_State *L )
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
if( p_playlist )
{
vlclua_push_vlc_object( L, p_playlist, vlclua_gc_release );
vlc_object_hold( p_playlist );
vlclua_push_vlc_object( L, p_playlist );
}
else lua_pushnil( L );
return 1;
......@@ -84,15 +85,15 @@ static int vlclua_get_input( lua_State *L )
input_thread_t *p_input = vlclua_get_input_internal( L );
if( p_input )
{
vlclua_push_vlc_object( L, p_input, vlclua_gc_release );
/* NOTE: p_input is already held by vlclua_get_input_internal() */
vlclua_push_vlc_object( L, p_input );
}
else lua_pushnil( L );
return 1;
}
#undef vlclua_push_vlc_object
int vlclua_push_vlc_object( lua_State *L, vlc_object_t *p_obj,
lua_CFunction pf_gc )
int vlclua_push_vlc_object( lua_State *L, vlc_object_t *p_obj )
{
vlc_object_t **udata = (vlc_object_t **)
lua_newuserdata( L, sizeof( vlc_object_t * ) );
......@@ -103,12 +104,9 @@ int vlclua_push_vlc_object( lua_State *L, vlc_object_t *p_obj,
/* Hide the metatable */
lua_pushliteral( L, "none of your business" );
lua_setfield( L, -2, "__metatable" );
if( pf_gc ) /* FIXME */
{
/* Set the garbage collector if needed */
lua_pushcfunction( L, pf_gc );
lua_setfield( L, -2, "__gc" );
}
/* Set the garbage collector if needed */
lua_pushcfunction( L, vlclua_object_release );
lua_setfield( L, -2, "__gc" );
}
lua_setmetatable( L, -2 );
return 1;
......
......@@ -25,11 +25,9 @@
#ifndef VLC_LUA_OBJECTS_H
#define VLC_LUA_OBJECTS_H
int vlclua_push_vlc_object( lua_State *L, vlc_object_t *p_obj,
lua_CFunction pf_gc );
#define vlclua_push_vlc_object( a, b, c ) \
vlclua_push_vlc_object( a, VLC_OBJECT( b ), c )
int vlclua_gc_release( lua_State *L );
int vlclua_push_vlc_object( lua_State *L, vlc_object_t *p_obj );
#define vlclua_push_vlc_object( a, b ) \
vlclua_push_vlc_object( a, VLC_OBJECT( b ) )
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment