[vlc-commits] lua playlist move and delete functions run-time
Tomas Krotil
git at videolan.org
Thu May 2 15:59:05 CEST 2013
vlc | branch: master | Tomas Krotil <krotitom at fel.cvut.cz> | Tue Apr 30 22:53:33 2013 +0200| [6daa137c1275063b4bafef81e3bfad60ec2e34d8] | committer: Jean-Baptiste Kempf
lua playlist move and delete functions run-time
Added playlist move function for lua and modified delete for detecting if item is legal
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6daa137c1275063b4bafef81e3bfad60ec2e34d8
---
modules/lua/libs/playlist.c | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/modules/lua/libs/playlist.c b/modules/lua/libs/playlist.c
index e9dbfc9..29f5e4b 100644
--- a/modules/lua/libs/playlist.c
+++ b/modules/lua/libs/playlist.c
@@ -141,7 +141,35 @@ static int vlclua_playlist_delete( lua_State * L )
int i_id = luaL_checkint( L, 1 );
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
PL_LOCK;
- int i_ret = playlist_DeleteFromInput(p_playlist, playlist_ItemGetById( p_playlist, i_id ) -> p_input, true );
+ playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
+ if( !p_item )
+ {
+ PL_UNLOCK;
+ return vlclua_push_ret( L, -1 );
+ }
+ int i_ret = playlist_DeleteFromInput( p_playlist, p_item -> p_input, true );
+ PL_UNLOCK;
+ return vlclua_push_ret( L, i_ret );
+}
+
+static int vlclua_playlist_move( lua_State * L )
+{
+ int i_item = luaL_checkint( L, 1 );
+ int i_target = luaL_checkint( L, 2 );
+ playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+ PL_LOCK;
+ playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_item );
+ playlist_item_t *p_target = playlist_ItemGetById( p_playlist, i_target );
+ if( !p_item || !p_target )
+ {
+ PL_UNLOCK;
+ return vlclua_push_ret( L, -1 );
+ }
+ int i_ret;
+ if( p_target->i_children != -1 )
+ i_ret = playlist_TreeMove( p_playlist, p_item, p_target, 0 );
+ else
+ i_ret = playlist_TreeMove( p_playlist, p_item, p_target->p_parent, p_target->i_id - p_target->p_parent->pp_children[0]->i_id + 1 );
PL_UNLOCK;
return vlclua_push_ret( L, i_ret );
}
@@ -389,6 +417,7 @@ static const luaL_Reg vlclua_playlist_reg[] = {
{ "sort", vlclua_playlist_sort },
{ "status", vlclua_playlist_status },
{ "delete", vlclua_playlist_delete },
+ { "move", vlclua_playlist_move },
{ NULL, NULL }
};
More information about the vlc-commits
mailing list