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

Hugo Beauzée-Luyssen git at videolan.org
Mon Apr 16 18:57:05 CEST 2018


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

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

To be able to delete files using an utf8 path

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

 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 43e0926f83..b2e681cba6 100644
--- a/share/lua/README.txt
+++ b/share/lua/README.txt
@@ -156,6 +156,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