[vlc-commits] lua: libs: Add a vlc.io and move mkdir there

Hugo Beauzée-Luyssen git at videolan.org
Mon Apr 9 17:01:59 CEST 2018


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Fri Apr  6 13:04:35 2018 +0200| [50f61974a26f2e7ada90d70ae8df9eca3f0f4cba] | committer: Hugo Beauzée-Luyssen

lua: libs: Add a vlc.io and move mkdir there

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

 modules/lua/Makefile.am        |  4 ++-
 modules/lua/extension.c        |  1 +
 modules/lua/intf.c             |  3 ++-
 modules/lua/libs.h             |  1 +
 modules/lua/libs/io.c          | 59 ++++++++++++++++++++++++++++++++++++++++++
 modules/lua/libs/misc.c        | 17 ------------
 share/lua/extensions/VLSub.lua |  2 +-
 7 files changed, 67 insertions(+), 20 deletions(-)

diff --git a/modules/lua/Makefile.am b/modules/lua/Makefile.am
index 38a1b8dcae..0713180a48 100644
--- a/modules/lua/Makefile.am
+++ b/modules/lua/Makefile.am
@@ -28,7 +28,9 @@ liblua_plugin_la_SOURCES = \
 	lua/libs/video.c \
 	lua/libs/vlm.c \
 	lua/libs/volume.c \
-	lua/libs/xml.c
+	lua/libs/xml.c \
+	lua/libs/io.c
+
 if HAVE_WIN32
 liblua_plugin_la_SOURCES += lua/libs/win.c
 endif
diff --git a/modules/lua/extension.c b/modules/lua/extension.c
index 10ec8c82cc..f0751dacf8 100644
--- a/modules/lua/extension.c
+++ b/modules/lua/extension.c
@@ -852,6 +852,7 @@ static lua_State* GetLuaState( extensions_manager_t *p_mgr,
         luaopen_vlm( L );
         luaopen_volume( L );
         luaopen_xml( L );
+        luaopen_vlcio( L );
 #if defined(_WIN32) && !VLC_WINSTORE_APP
         luaopen_win( L );
 #endif
diff --git a/modules/lua/intf.c b/modules/lua/intf.c
index 7218a99380..64564e4e89 100644
--- a/modules/lua/intf.c
+++ b/modules/lua/intf.c
@@ -156,7 +156,7 @@ static char *StripPasswords( const char *psz_config )
     }
     if (n == 0)
         return strdup(psz_config);
- 
+
     char *psz_log = malloc(strlen(psz_config) + n * strlen("******") + 1);
     if (psz_log == NULL)
         return NULL;
@@ -277,6 +277,7 @@ static int Start_LuaIntf( vlc_object_t *p_this, const char *name )
     luaopen_gettext( L );
     luaopen_xml( L );
     luaopen_equalizer( L );
+    luaopen_vlcio( L );
 #if defined(_WIN32) && !VLC_WINSTORE_APP
     luaopen_win( L );
 #endif
diff --git a/modules/lua/libs.h b/modules/lua/libs.h
index 945c5583e9..b62aebd2d6 100644
--- a/modules/lua/libs.h
+++ b/modules/lua/libs.h
@@ -45,6 +45,7 @@ void luaopen_gettext( lua_State * );
 void luaopen_input_item( lua_State *L, input_item_t *item );
 void luaopen_xml( lua_State *L );
 void luaopen_equalizer( lua_State *L );
+void luaopen_vlcio( lua_State *L );
 #ifdef _WIN32
 void luaopen_win( lua_State *L );
 #endif
diff --git a/modules/lua/libs/io.c b/modules/lua/libs/io.c
new file mode 100644
index 0000000000..f3bbefe4c0
--- /dev/null
+++ b/modules/lua/libs/io.c
@@ -0,0 +1,59 @@
+/*****************************************************************************
+ * misc.c
+ *****************************************************************************
+ * Copyright (C) 2007-2018 the VideoLAN team
+ *
+ * Authors: Hugo Beauzée-Luyssen <hugo at beauzee.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <errno.h>
+
+#include <vlc_common.h>
+#include <vlc_fs.h>
+
+#include "../vlc.h"
+#include "../libs.h"
+
+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 const luaL_Reg vlclua_io_reg[] = {
+    { "mkdir", vlclua_mkdir },
+
+    { NULL, NULL }
+};
+
+void luaopen_vlcio( lua_State *L )
+{
+    lua_newtable( L );
+    luaL_register( L, NULL, vlclua_io_reg );
+    lua_setfield( L, -2, "io" );
+}
diff --git a/modules/lua/libs/misc.c b/modules/lua/libs/misc.c
index 99b8b5a0ca..7aecce03bb 100644
--- a/modules/lua/libs/misc.c
+++ b/modules/lua/libs/misc.c
@@ -36,7 +36,6 @@
 
 #include <math.h>
 #include <stdlib.h>
-#include <errno.h>
 
 #include <vlc_common.h>
 #include <vlc_plugin.h>
@@ -44,7 +43,6 @@
 #include <vlc_interface.h>
 #include <vlc_actions.h>
 #include <vlc_interrupt.h>
-#include <vlc_fs.h>
 
 #include "../vlc.h"
 #include "../libs.h"
@@ -148,19 +146,6 @@ 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 ) );
@@ -183,8 +168,6 @@ static const luaL_Reg vlclua_misc_reg[] = {
     { "mdate", vlclua_mdate },
     { "mwait", vlclua_mwait },
 
-    { "mkdir", vlclua_mkdir },
-
     { "quit", vlclua_quit },
 
     { NULL, NULL }
diff --git a/share/lua/extensions/VLSub.lua b/share/lua/extensions/VLSub.lua
index c1ae5a606c..c7516d71a4 100644
--- a/share/lua/extensions/VLSub.lua
+++ b/share/lua/extensions/VLSub.lua
@@ -667,7 +667,7 @@ function check_config()
   openSub.conf.dirPath = vlc.config.userdatadir()
   local subdirs = { "lua", "extensions", "userdata", "vlsub" }
   for _, dir in ipairs(subdirs) do
-    if not vlc.misc.mkdir( openSub.conf.dirPath .. slash .. dir, "0700" ) then
+    if not vlc.io.mkdir( openSub.conf.dirPath .. slash .. dir, "0700" ) then
       vlc.msg.warn("Failed to create " .. openSub.conf.dirPath .. slash .. dir )
       return false
     end



More information about the vlc-commits mailing list