[vlc-commits] lua: return playlist item ID from playlist.current()

Rémi Denis-Courmont git at videolan.org
Tue Nov 15 19:27:37 CET 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Nov 15 20:26:00 2016 +0200| [2a70d8415186f4a552231ec937eedfff6729a8ea] | committer: Rémi Denis-Courmont

lua: return playlist item ID from playlist.current()

This makes more sense than returning the input item ID, which is not
exposed in any other place and manner through Lua. And it seems that
was the intent too.

Then again, the value is either way potentially invalid by the time it
is returned.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2a70d8415186f4a552231ec937eedfff6729a8ea
---

 modules/lua/libs/playlist.c | 16 ++++++----------
 share/lua/README.txt        |  2 +-
 2 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/modules/lua/libs/playlist.c b/modules/lua/libs/playlist.c
index d4b07a5..0657385 100644
--- a/modules/lua/libs/playlist.c
+++ b/modules/lua/libs/playlist.c
@@ -312,18 +312,14 @@ 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 );
-    input_thread_t *p_input = playlist_CurrentInput( p_playlist );
+    playlist_item_t *item;
     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,
+    PL_LOCK;
+    item = playlist_CurrentPlayingItem( p_playlist );
+    if( item != NULL )
+        id = item->i_id;
+    PL_UNLOCK;
     lua_pushinteger( L, id );
     return 1;
 }
diff --git a/share/lua/README.txt b/share/lua/README.txt
index 5562aa0..4ef2de7 100644
--- a/share/lua/README.txt
+++ b/share/lua/README.txt
@@ -298,7 +298,7 @@ playlist.get( [what, [tree]] ): Get the playlist.
       .nb_played:
       .children: A table of children playlist items.
 playlist.search( name ): filter the playlist items with the given string
-playlist.current(): return the current input item id
+playlist.current(): return the current playlist item id
 playlist.sort( key ): sort the playlist according to the key.
   Key must be one of the followings values: 'id', 'title', 'title nodes first',
                                             'artist', 'genre', 'random', 'duration',



More information about the vlc-commits mailing list