[vlc-commits] lua: io: Add a vlc.io.unlink function

Hugo Beauzée-Luyssen git at videolan.org
Tue Apr 17 14:02:14 CEST 2018


vlc/vlc-3.0 | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Mon Apr 16 13:09:58 2018 +0200| [a63ce67991ffff0986372d752872cbb14a7af364] | committer: Hugo Beauzée-Luyssen

lua: io: Add a vlc.io.unlink function

To be able to delete files using an utf8 path

(cherry picked from commit 987952962f25deb6ee2703a5399d22a38df4e48b)
Signed-off-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>

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

 modules/lua/libs/io.c | 13 +++++++++++++
 share/lua/README.txt  |  3 +++
 2 files changed, 16 insertions(+)

diff --git a/modules/lua/libs/io.c b/modules/lua/libs/io.c
index 5d6ac4d65a..c01cf7137d 100644
--- a/modules/lua/libs/io.c
+++ b/modules/lua/libs/io.c
@@ -230,6 +230,18 @@ static int vlclua_io_readdir( lua_State *L )
     return 1;
 }
 
+static int vlclua_io_unlink( lua_State *L )
+{
+    if( lua_gettop( L ) < 1 )
+        return luaL_error( L, "Usage: vlc.io.unlink(path)" );
+    const char* psz_path = luaL_checkstring( L, 1 );
+    int i_res = vlc_unlink( psz_path );
+    int i_err = i_res != 0 ? errno : 0;
+    lua_pushinteger( L, i_res );
+    lua_pushinteger( L, i_err );
+    return 2;
+}
+
 static int vlclua_mkdir( lua_State *L )
 {
     if( lua_gettop( L ) < 2 ) return vlclua_error( L );
@@ -249,6 +261,7 @@ static const luaL_Reg vlclua_io_reg[] = {
     { "mkdir", vlclua_mkdir },
     { "open", vlclua_io_open },
     { "readdir", vlclua_io_readdir },
+    { "unlink", vlclua_io_unlink },
 
     { NULL, NULL }
 };
diff --git a/share/lua/README.txt b/share/lua/README.txt
index 1c7bf5dd63..8b92a3179d 100644
--- a/share/lua/README.txt
+++ b/share/lua/README.txt
@@ -158,6 +158,9 @@ io.open("path"[, "mode"]): Similar to lua's io.open. Mode is optional and
     .flush
     .close
   all of which are used exactly like the lua object returned by io.open
+io.unlink("path"): Similar to os.remove. First return value is 0 in case
+  of success. In case of failure, the 2nd return parameter is an error
+  code to be compared against vlc.errno values.
 
 Messages
 --------



More information about the vlc-commits mailing list