Extends lua's SD API to add a remove_node method, similar for remove_item
authorJulien 'Lta' BALLET <contact@lta.io>
Tue, 21 Jan 2014 15:45:08 +0000 (16:45 +0100)
committerJean-Baptiste Kempf <jb@videolan.org>
Wed, 22 Jan 2014 20:04:15 +0000 (21:04 +0100)
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/lua/libs/sd.c

index 4bbf1d7..fe5ac57 100644 (file)
@@ -319,6 +319,21 @@ static int vlclua_sd_remove_item( lua_State *L )
     return 1;
 }
 
+static int vlclua_sd_remove_node( lua_State *L )
+{
+    services_discovery_t *p_sd = (services_discovery_t *)vlclua_get_this( L );
+    if( !lua_isnil( L, 1 ) )
+    {
+        input_item_t **pp_input = luaL_checkudata( L, 1, "node" );
+        if( *pp_input )
+            services_discovery_RemoveItem( p_sd, *pp_input );
+        /* Make sure we won't try to remove it again */
+        *pp_input = NULL;
+    }
+    return 1;
+}
+
+
 static int vlclua_sd_remove_all_items_nodes( lua_State *L )
 {
     services_discovery_t *p_sd = (services_discovery_t *)vlclua_get_this( L );
@@ -458,6 +473,7 @@ static const luaL_Reg vlclua_sd_reg[] = {
     { "add_node", vlclua_sd_add_node },
     { "add_item", vlclua_sd_add_item },
     { "remove_item", vlclua_sd_remove_item },
+    { "remove_node", vlclua_sd_remove_node },
     { "remove_all_items_nodes", vlclua_sd_remove_all_items_nodes },
     { NULL, NULL }
 };