playlist_t *vlclua_get_playlist_internal( lua_State *L )
{
vlc_object_t *p_this = vlclua_get_this( L );
- return pl_Yield( p_this );
+ return pl_Hold( p_this );
+}
+
+void vlclua_release_playlist_internal( playlist_t *p_playlist )
+{
+ vlc_object_release( p_playlist );
}
static int vlclua_playlist_prev( lua_State * L )
{
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
playlist_Prev( p_playlist );
- pl_Release( p_playlist );
+ vlclua_release_playlist_internal( p_playlist );
return 0;
}
{
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
playlist_Next( p_playlist );
- pl_Release( p_playlist );
+ vlclua_release_playlist_internal( p_playlist );
return 0;
}
int i_skip = luaL_checkint( L, 1 );
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
playlist_Skip( p_playlist, i_skip );
- pl_Release( p_playlist );
+ vlclua_release_playlist_internal( p_playlist );
return 0;
}
{
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
playlist_Play( p_playlist );
- pl_Release( p_playlist );
+ vlclua_release_playlist_internal( p_playlist );
return 0;
}
{
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
playlist_Pause( p_playlist );
- pl_Release( p_playlist );
+ vlclua_release_playlist_internal( p_playlist );
return 0;
}
{
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
playlist_Stop( p_playlist );
- pl_Release( p_playlist );
+ vlclua_release_playlist_internal( p_playlist );
return 0;
}
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
playlist_Stop( p_playlist ); /* Isn't this already implied by Clear? */
playlist_Clear( p_playlist, pl_Unlocked );
- pl_Release( p_playlist );
+ vlclua_release_playlist_internal( p_playlist );
return 0;
}
{
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
int i_ret = vlclua_var_toggle_or_set( L, p_playlist, "repeat" );
- pl_Release( p_playlist );
+ vlclua_release_playlist_internal( p_playlist );
return i_ret;
}
{
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
int i_ret = vlclua_var_toggle_or_set( L, p_playlist, "loop" );
- pl_Release( p_playlist );
+ vlclua_release_playlist_internal( p_playlist );
return i_ret;
}
{
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
int i_ret = vlclua_var_toggle_or_set( L, p_playlist, "random" );
- pl_Release( p_playlist );
+ vlclua_release_playlist_internal( p_playlist );
return i_ret;
}
{
int i_id = luaL_checkint( L, 1 );
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+ PL_LOCK;
int i_ret = playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
true, NULL,
- playlist_ItemGetById( p_playlist, i_id,
- true ) );
- pl_Release( p_playlist );
+ playlist_ItemGetById( p_playlist, i_id ) );
+ PL_UNLOCK;
+ vlclua_release_playlist_internal( p_playlist );
return vlclua_push_ret( L, i_ret );
}
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
i_count = vlclua_playlist_add_internal( p_this, L, p_playlist,
NULL, true );
- pl_Release( p_playlist );
+ vlclua_release_playlist_internal( p_playlist );
lua_pushinteger( L, i_count );
return 1;
}
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
i_count = vlclua_playlist_add_internal( p_this, L, p_playlist,
NULL, false );
- pl_Release( p_playlist );
+ vlclua_release_playlist_internal( p_playlist );
lua_pushinteger( L, i_count );
return 1;
}
static void push_playlist_item( lua_State *L, playlist_item_t *p_item )
{
input_item_t *p_input = p_item->p_input;
- int i_flags = p_item->i_flags;
+ int i_flags = 0;
+ i_flags = p_item->i_flags;
lua_newtable( L );
lua_pushinteger( L, p_item->i_id );
lua_setfield( L, -2, "id" );
static int vlclua_playlist_get( lua_State *L )
{
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+ PL_LOCK;
int b_category = luaL_optboolean( L, 2, 1 ); /* Default to tree playlist (discared when 1st argument is a playlist_item's id) */
playlist_item_t *p_item = NULL;
if( lua_isnumber( L, 1 ) )
{
int i_id = lua_tointeger( L, 1 );
- p_item = playlist_ItemGetById( p_playlist, i_id, true );
+ p_item = playlist_ItemGetById( p_playlist, i_id );
if( !p_item )
{
- pl_Release( p_playlist );
+ PL_UNLOCK;
+ vlclua_release_playlist_internal( p_playlist );
return 0; /* Should we return an error instead? */
}
}
: p_playlist->p_root_onelevel;
else
{
- int i;
- for( i = 0; i < p_playlist->i_sds; i++ )
+#ifdef FIX_THAT_CODE_NOT_TO_MESS_WITH_PLAYLIST_INTERNALS
+ for( int i = 0; i < p_playlist->i_sds; i++ )
{
if( !strcasecmp( psz_what,
p_playlist->pp_sds[i]->p_sd->psz_module ) )
break;
}
}
+#else
+# warning "Don't access playlist iternal, broken code here."
+ abort();
+#endif
if( !p_item )
{
- pl_Release( p_playlist );
+ PL_UNLOCK;
+ vlclua_release_playlist_internal( p_playlist );
return 0; /* Should we return an error instead? */
}
}
: p_playlist->p_root_onelevel;
}
push_playlist_item( L, p_item );
- pl_Release( p_playlist );
+ PL_UNLOCK;
+ vlclua_release_playlist_internal( p_playlist );
return 1;
}
int b_category = luaL_optboolean( L, 2, 1 ); /* default to category */
playlist_item_t *p_item = b_category ? p_playlist->p_root_category
: p_playlist->p_root_onelevel;
+ PL_LOCK;
playlist_LiveSearchUpdate( p_playlist, p_item, psz_string );
+ PL_UNLOCK;
push_playlist_item( L, p_item );
- pl_Release( p_playlist );
+ vlclua_release_playlist_internal( p_playlist );
return 1;
}
static int vlclua_playlist_current( lua_State *L )
{
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
- lua_pushinteger( L, var_GetInteger( p_playlist, "playlist-current" ) );
- pl_Release( p_playlist );
+ input_thread_t *p_input = playlist_CurrentInput( p_playlist );
+ int id = -1;
+
+ if( p_input )
+ {
+ input_item_t *p_item = input_GetItem( p_input );
+ if( p_item )
+ id = p_item->i_id;
+ vlc_object_release( p_input );
+ }
+
+#warning Indexing input items by ID is unsafe,
+ lua_pushinteger( L, id );
+ vlclua_release_playlist_internal( p_playlist );
return 1;
}
int i_type = luaL_optboolean( L, 2, 0 ) ? ORDER_REVERSE : ORDER_NORMAL;
int b_category = luaL_optboolean( L, 3, 1 ); /* default to category */
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+ PL_LOCK;
playlist_item_t *p_root = b_category ? p_playlist->p_local_category
: p_playlist->p_local_onelevel;
int i_ret = playlist_RecursiveNodeSort( p_playlist, p_root, i_mode,
i_type );
- pl_Release( p_playlist );
+ PL_UNLOCK;
+ vlclua_release_playlist_internal( p_playlist );
return vlclua_push_ret( L, i_ret );
}
-/* FIXME: split this in 3 different functions? */
static int vlclua_playlist_status( lua_State *L )
{
- intf_thread_t *p_intf = (intf_thread_t *)vlclua_get_this( L );
- playlist_t *p_playlist = pl_Yield( p_intf );
- /*
- int i_count = 0;
- lua_settop( L, 0 );*/
- if( p_playlist->p_input )
- {
- /*char *psz_uri =
- input_item_GetURI( input_GetItem( p_playlist->p_input ) );
- lua_pushstring( L, psz_uri );
- free( psz_uri );
- lua_pushnumber( L, config_GetInt( p_intf, "volume" ) );*/
- vlc_object_lock( p_playlist );
- switch( p_playlist->status.i_status )
- {
- case PLAYLIST_STOPPED:
- lua_pushstring( L, "stopped" );
- break;
- case PLAYLIST_RUNNING:
- lua_pushstring( L, "playing" );
- break;
- case PLAYLIST_PAUSED:
- lua_pushstring( L, "paused" );
- break;
- default:
- lua_pushstring( L, "unknown" );
- break;
- }
- vlc_object_unlock( p_playlist );
- /*i_count += 3;*/
- }
- else
+ playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+ PL_LOCK;
+ switch( playlist_Status( p_playlist ) )
{
- lua_pushstring( L, "stopped" );
+ case PLAYLIST_STOPPED:
+ lua_pushstring( L, "stopped" );
+ break;
+ case PLAYLIST_RUNNING:
+ lua_pushstring( L, "playing" );
+ break;
+ case PLAYLIST_PAUSED:
+ lua_pushstring( L, "paused" );
+ break;
+ default:
+ lua_pushstring( L, "unknown" );
+ break;
}
- pl_Release( p_playlist );
+ PL_UNLOCK;
+ vlclua_release_playlist_internal( p_playlist );
return 1;
}
{ "pause", vlclua_playlist_pause },
{ "stop", vlclua_playlist_stop },
{ "clear", vlclua_playlist_clear },
- { "repeat", vlclua_playlist_repeat },
+ { "repeat", vlclua_playlist_repeat }, // repeat is a reserved lua keyword...
+ { "repeat_", vlclua_playlist_repeat }, // ... provide repeat_ too.
{ "loop", vlclua_playlist_loop },
{ "random", vlclua_playlist_random },
{ "goto", vlclua_playlist_goto },