[vlc-commits] lua: Expose a mkdir function

Hugo Beauzée-Luyssen git at videolan.org
Thu Apr 12 13:01:08 CEST 2018


vlc/vlc-3.0 | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Wed Apr  4 16:54:17 2018 +0200| [2119fc852e999f4f234ca8915b9fcb0f2eb99a3b] | committer: Hugo Beauzée-Luyssen

lua: Expose a mkdir function

To avoid using os.execute...

(cherry picked from commit 67ed23cef3bbc192ebaae63914691e84e43c5551)
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=2119fc852e999f4f234ca8915b9fcb0f2eb99a3b
---

 modules/lua/libs/misc.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/modules/lua/libs/misc.c b/modules/lua/libs/misc.c
index a0472e82a2..99b8b5a0ca 100644
--- a/modules/lua/libs/misc.c
+++ b/modules/lua/libs/misc.c
@@ -35,6 +35,8 @@
 #endif
 
 #include <math.h>
+#include <stdlib.h>
+#include <errno.h>
 
 #include <vlc_common.h>
 #include <vlc_plugin.h>
@@ -42,6 +44,7 @@
 #include <vlc_interface.h>
 #include <vlc_actions.h>
 #include <vlc_interrupt.h>
+#include <vlc_fs.h>
 
 #include "../vlc.h"
 #include "../libs.h"
@@ -145,6 +148,19 @@ static int vlclua_mwait( lua_State *L )
     return 0;
 }
 
+static int vlclua_mkdir( lua_State *L )
+{
+    if( lua_gettop( L ) < 2 ) return vlclua_error( L );
+
+    const char* psz_dir = luaL_checkstring( L, 1 );
+    const char* psz_mode = luaL_checkstring( L, 2 );
+    if ( !psz_dir || !psz_mode )
+        return vlclua_error( L );
+    int i_res = vlc_mkdir( psz_dir, strtoul( psz_mode, NULL, 0 ) );
+    lua_pushboolean( L, i_res == 0 || errno == EEXIST );
+    return 1;
+}
+
 static int vlclua_action_id( lua_State *L )
 {
     vlc_action_id_t i_key = vlc_actions_get_id( luaL_checkstring( L, 1 ) );
@@ -167,6 +183,8 @@ static const luaL_Reg vlclua_misc_reg[] = {
     { "mdate", vlclua_mdate },
     { "mwait", vlclua_mwait },
 
+    { "mkdir", vlclua_mkdir },
+
     { "quit", vlclua_quit },
 
     { NULL, NULL }



More information about the vlc-commits mailing list