]> git.sesse.net Git - vlc/blobdiff - modules/misc/lua/libs/playlist.c
Lua dialogs: introduce "dlg:flush()"
[vlc] / modules / misc / lua / libs / playlist.c
index 58ce8c0bccdc456dbb87a75e82fab7d4c3acdaab..240b521e14946685be5efd3587915de6000c2055 100644 (file)
@@ -87,9 +87,7 @@ static int vlclua_playlist_skip( lua_State * L )
 static int vlclua_playlist_play( lua_State * L )
 {
     playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    PL_LOCK;
     playlist_Play( p_playlist );
-    PL_UNLOCK;
     vlclua_release_playlist_internal( p_playlist );
     return 0;
 }
@@ -318,7 +316,19 @@ static int vlclua_playlist_search( lua_State *L )
 static int vlclua_playlist_current( lua_State *L )
 {
     playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    lua_pushinteger( L, var_GetInteger( p_playlist, "item-current" ) );
+    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;
 }
@@ -368,45 +378,26 @@ static int vlclua_playlist_sort( lua_State *L )
     return vlclua_push_ret( L, i_ret );
 }
 
-/* FIXME: split this in 3 different functions? */
 static int vlclua_playlist_status( lua_State *L )
 {
     playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    /*
-    int i_count = 0;
-    lua_settop( L, 0 );*/
-    input_thread_t * p_input = playlist_CurrentInput( p_playlist );
-    if( 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" ) );*/
-        PL_LOCK;
-        switch( playlist_Status( p_playlist ) )
-        {
-            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_UNLOCK;
-        /*i_count += 3;*/
-        vlc_object_release( p_input );
-    }
-    else
+    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_UNLOCK;
     vlclua_release_playlist_internal( p_playlist );
     return 1;
 }
@@ -422,7 +413,8 @@ static const luaL_Reg vlclua_playlist_reg[] = {
     { "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 },