Commit 8a57fce9 authored by Pierre Ynard's avatar Pierre Ynard

luasd: helper function to fetch longname

parent ceb9d2ba
......@@ -40,6 +40,41 @@ static int DoSearch( services_discovery_t *p_sd, const char *psz_query );
static int FillDescriptor( services_discovery_t *, services_discovery_descriptor_t * );
static int Control( services_discovery_t *p_sd, int i_command, va_list args );
// When successful, the returned string is stored on top of the lua
// stack and remains valid as long as it is kept in the stack.
#undef vlclua_sd_description
const char *vlclua_sd_description( vlc_object_t *obj, lua_State *L,
const char *filename )
{
lua_getglobal( L, "descriptor" );
if( !lua_isfunction( L, -1 ) )
{
msg_Warn( obj, "No 'descriptor' function in '%s'", filename );
lua_pop( L, 1 );
return NULL;
}
if( lua_pcall( L, 0, 1, 0 ) )
{
msg_Warn( obj, "Error while running script %s, "
"function descriptor(): %s", filename,
lua_tostring( L, -1 ) );
lua_pop( L, 1 );
return NULL;
}
lua_getfield( L, -1, "title" );
if ( !lua_isstring( L, -1 ) )
{
msg_Warn( obj, "'descriptor' function in '%s' returned no title",
filename );
lua_pop( L, 2 );
return NULL;
}
return lua_tostring( L, -1 );
}
static const char * const ppsz_sd_options[] = { "sd", "longname", NULL };
/*****************************************************************************
......
......@@ -678,25 +678,12 @@ static int vlc_sd_probe_Open( vlc_object_t *obj )
lua_close( L );
continue;
}
const char *psz_longname;
char *temp = strchr( *ppsz_file, '.' );
if( temp )
*temp = '\0';
lua_getglobal( L, "descriptor" );
if( !lua_isfunction( L, lua_gettop( L ) ) || lua_pcall( L, 0, 1, 0 ) )
{
msg_Warn( probe, "No 'descriptor' function in '%s'", psz_filename );
lua_pop( L, 1 );
const char *psz_longname = vlclua_sd_description( probe, L, psz_filename );
if( psz_longname == NULL )
psz_longname = *ppsz_file;
}
else
{
lua_getfield( L, -1, "title" );
if( lua_isstring( L, -1 ) )
psz_longname = lua_tostring( L, -1 );
else
psz_longname = *ppsz_file;
}
char *psz_file_esc = config_StringEscape( *ppsz_file );
char *psz_longname_esc = config_StringEscape( psz_longname );
......
......@@ -91,6 +91,10 @@ void Close_Extension( vlc_object_t * );
int Open_LuaSD( vlc_object_t * );
void Close_LuaSD( vlc_object_t * );
// Helper
const char *vlclua_sd_description( vlc_object_t *, lua_State *, const char * );
#define vlclua_sd_description(a, b, c) vlclua_sd_description(VLC_OBJECT(a), b, c)
/*****************************************************************************
* Lua debug
*****************************************************************************/
......
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