]> git.sesse.net Git - vlc/blobdiff - modules/misc/lua/services_discovery.c
Merge branch 'master' into lpcm_encoder
[vlc] / modules / misc / lua / services_discovery.c
index ebe248419113825534413a0b8486ec344c637811..467a4aae4a34f98dfd629ebfa333d29b56c87e65 100644 (file)
@@ -26,7 +26,6 @@
 
 #include <vlc_common.h>
 #include <vlc_services_discovery.h>
-#include <vlc_playlist.h>
 
 #include "vlc.h"
 #include "libs.h"
@@ -36,7 +35,7 @@
  *****************************************************************************/
 static void *Run( void * );
 
-static const char * const ppsz_sd_options[] = { "sd", NULL };
+static const char * const ppsz_sd_options[] = { "sd", "longname", NULL };
 
 /*****************************************************************************
  * Local structures
@@ -57,7 +56,7 @@ int Open_LuaSD( vlc_object_t *p_this )
     services_discovery_t *p_sd = ( services_discovery_t * )p_this;
     services_discovery_sys_t *p_sys;
     lua_State *L = NULL;
-    char *psz_name = strdup(p_sd->psz_name);
+    char *psz_name = NULL;
 
     if( !strcmp(p_sd->psz_name, "lua"))
     {
@@ -94,16 +93,14 @@ int Open_LuaSD( vlc_object_t *p_this )
         msg_Err( p_sd, "Could not create new Lua State" );
         goto error;
     }
+    vlclua_set_this( L, p_sd );
     luaL_openlibs( L );
     luaL_register( L, "vlc", p_reg );
-    lua_pushlightuserdata( L, p_sd );
-    lua_setfield( L, -2, "private" );
     luaopen_input( L );
     luaopen_msg( L );
     luaopen_misc( L );
     luaopen_net( L );
     luaopen_object( L );
-    luaopen_playlist( L );
     luaopen_sd( L );
     luaopen_strings( L );
     luaopen_variables( L );
@@ -166,12 +163,17 @@ static void* Run( void *data )
     lua_getglobal( L, "main" );
     if( !lua_isfunction( L, lua_gettop( L ) ) || lua_pcall( L, 0, 1, 0 ) )
     {
-        msg_Err( p_sd, "Error while runing script %s, "
+        msg_Err( p_sd, "Error while running script %s, "
                   "function main(): %s", p_sys->psz_filename,
                   lua_tostring( L, lua_gettop( L ) ) );
         lua_pop( L, 1 );
         return NULL;
     }
-    msg_Dbg( p_sd, "LuaSD script loaded: %s", p_sd->psz_name );
+    msg_Dbg( p_sd, "LuaSD script loaded: %s", p_sys->psz_filename );
+
+    /* Force garbage collection, because the core will keep the SD
+     * open, but lua will never gc until lua_close(). */
+    lua_gc( L, LUA_GCCOLLECT, 0 );
+
     return NULL;
 }