[vlc-devel] [PATCH 4/9] lua: add playlist.current_item()

Romain Vimont rom1v at videolabs.io
Mon Mar 4 11:53:24 CET 2019


In addition to the existant playlist.current(), returning the current
item id, expose a function returning the item itself.
---
 modules/lua/libs/playlist.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/modules/lua/libs/playlist.c b/modules/lua/libs/playlist.c
index a15b4ff11e..e7f2df0ddd 100644
--- a/modules/lua/libs/playlist.c
+++ b/modules/lua/libs/playlist.c
@@ -407,6 +407,23 @@ static int vlclua_playlist_current(lua_State *L)
     return 1;
 }
 
+static int vlclua_playlist_current_item(lua_State *L)
+{
+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
+
+    vlc_playlist_Lock(playlist);
+    ssize_t index = vlc_playlist_GetCurrentIndex(playlist);
+    vlc_playlist_item_t *item = index != -1 ? vlc_playlist_Get(playlist, index)
+                                            : NULL;
+    if (item)
+        push_playlist_item(L, item);
+    else
+        lua_pushnil(L);
+    vlc_playlist_Unlock(playlist);
+
+    return 1;
+}
+
 static bool vlc_sort_key_from_string(const char *keyname,
                                      enum vlc_playlist_sort_key *key)
 {
@@ -518,6 +535,7 @@ static const luaL_Reg vlclua_playlist_reg[] = {
     { "enqueue", vlclua_playlist_enqueue },
     { "get", vlclua_playlist_get },
     { "current", vlclua_playlist_current },
+    { "current_item", vlclua_playlist_current_item },
     { "sort", vlclua_playlist_sort },
     { "status", vlclua_playlist_status },
     { "delete", vlclua_playlist_delete },
-- 
2.20.1



More information about the vlc-devel mailing list