Commit 87151c41 authored by Fabio Ritrovato's avatar Fabio Ritrovato

Lua SD: use a function to get the SD description

parent 80db30df
...@@ -579,6 +579,7 @@ static int vlc_sd_probe_Open( vlc_object_t *obj ) ...@@ -579,6 +579,7 @@ static int vlc_sd_probe_Open( vlc_object_t *obj )
char *psz_name; char *psz_name;
char *ppsz_dir_list[] = { NULL, NULL, NULL, NULL }; char *ppsz_dir_list[] = { NULL, NULL, NULL, NULL };
char **ppsz_dir; char **ppsz_dir;
lua_State *L = NULL;
vlclua_dir_list( obj, "sd", ppsz_dir_list ); vlclua_dir_list( obj, "sd", ppsz_dir_list );
for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ ) for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
{ {
...@@ -603,33 +604,47 @@ static int vlc_sd_probe_Open( vlc_object_t *obj ) ...@@ -603,33 +604,47 @@ static int vlc_sd_probe_Open( vlc_object_t *obj )
{ {
goto error; goto error;
} }
FILE *fd = vlc_fopen( psz_filename, "r" ); L = luaL_newstate();
if( fd ) if( !L )
{ {
char description[256]; msg_Err( probe, "Could not create new Lua State" );
if( fgets( description, 256, fd ) != NULL ) return VLC_EGENERIC;
}
luaL_openlibs( L );
if( vlclua_add_modules_path( probe, L, psz_filename ) )
{ {
char *temp = strchr( description, '\n' ); msg_Err( probe, "Error while setting the module search path for %s",
if( temp ) psz_filename );
*temp = '\0'; goto error;
temp = strchr( *ppsz_file, '.' ); }
if( luaL_dofile( L, psz_filename ) )
{
msg_Err( probe, "Error loading script %s: %s", psz_filename,
lua_tostring( L, lua_gettop( L ) ) );
lua_pop( L, 1 );
goto error;
}
char *psz_longname;
char *temp = strchr( *ppsz_file, '.' );
if( temp ) if( temp )
*temp = '\0'; *temp = '\0';
char *psz_longname; lua_getglobal( L, "descriptor" );
if( !strncmp( description, "--SD_Description=", 17 ) ) if( !lua_isfunction( L, lua_gettop( L ) ) || lua_pcall( L, 0, 1, 0 ) )
{ {
if( !( psz_longname = strdup( description + 17 ) ) ) lua_pop( L, 1 );
if( !( psz_longname = strdup( *ppsz_file ) ) )
{ {
fclose( fd );
free( psz_filename ); free( psz_filename );
goto error; goto error;
} }
} }
else else
{ {
if( !( psz_longname = strdup( *ppsz_file ) ) ) lua_getfield( L, -1, "title" );
if( !lua_isstring( L, -1 ) ||
!( psz_longname = strdup( lua_tostring( L, -1 ) ) ) )
{ {
fclose( fd );
free( psz_filename ); free( psz_filename );
goto error; goto error;
} }
...@@ -637,7 +652,6 @@ static int vlc_sd_probe_Open( vlc_object_t *obj ) ...@@ -637,7 +652,6 @@ static int vlc_sd_probe_Open( vlc_object_t *obj )
if( asprintf( &psz_name, "lua{sd=%s,longname=%s}", if( asprintf( &psz_name, "lua{sd=%s,longname=%s}",
*ppsz_file, psz_longname ) < 0 ) *ppsz_file, psz_longname ) < 0 )
{ {
fclose( fd );
free( psz_filename ); free( psz_filename );
free( psz_longname ); free( psz_longname );
goto error; goto error;
...@@ -645,10 +659,8 @@ static int vlc_sd_probe_Open( vlc_object_t *obj ) ...@@ -645,10 +659,8 @@ static int vlc_sd_probe_Open( vlc_object_t *obj )
vlc_sd_probe_Add( probe, psz_name, psz_longname, SD_CAT_INTERNET ); vlc_sd_probe_Add( probe, psz_name, psz_longname, SD_CAT_INTERNET );
free( psz_name ); free( psz_name );
free( psz_longname ); free( psz_longname );
}
fclose( fd );
}
free( psz_filename ); free( psz_filename );
lua_close( L );
} }
} }
if( ppsz_filelist ) if( ppsz_filelist )
...@@ -668,6 +680,8 @@ error: ...@@ -668,6 +680,8 @@ error:
free( *ppsz_file ); free( *ppsz_file );
free( ppsz_filelist ); free( ppsz_filelist );
} }
if( L )
lua_close( L );
vlclua_dir_list_free( ppsz_dir_list ); vlclua_dir_list_free( ppsz_dir_list );
return VLC_ENOMEM; return VLC_ENOMEM;
} }
......
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