From fed4ac59688f08e971ab6c45d097b04248cb3968 Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Sat, 3 Sep 2016 11:44:48 +0200 Subject: [PATCH 01/17] src/gui/lua: Add lua_filehelpers.cpp Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/295ca1f7c970038af84e81aedc0adab35667c844 Author: Michael Liebmann Date: 2016-09-03 (Sat, 03 Sep 2016) --- src/gui/lua/Makefile.am | 1 + src/gui/lua/lua_filehelpers.cpp | 83 +++++++++++++++++++++++++++++++ src/gui/lua/lua_filehelpers.h | 45 +++++++++++++++++ src/gui/lua/luainstance.cpp | 2 + src/gui/lua/luainstance_helpers.h | 3 +- 5 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 src/gui/lua/lua_filehelpers.cpp create mode 100644 src/gui/lua/lua_filehelpers.h diff --git a/src/gui/lua/Makefile.am b/src/gui/lua/Makefile.am index e3861cb76..6b99ec4ce 100644 --- a/src/gui/lua/Makefile.am +++ b/src/gui/lua/Makefile.am @@ -32,6 +32,7 @@ libneutrino_gui_lua_a_SOURCES = \ lua_cc_window.cpp \ lua_configfile.cpp \ lua_curl.cpp \ + lua_filehelpers.cpp \ lua_hintbox.cpp \ lua_menue.cpp \ lua_messagebox.cpp \ diff --git a/src/gui/lua/lua_filehelpers.cpp b/src/gui/lua/lua_filehelpers.cpp new file mode 100644 index 000000000..8abffb9c3 --- /dev/null +++ b/src/gui/lua/lua_filehelpers.cpp @@ -0,0 +1,83 @@ +/* + * lua file helpers functions + * + * (C) 2016 M. Liebmann (micha-bbg) + * + * 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, see . + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "luainstance.h" +#include "lua_filehelpers.h" + +CLuaInstFileHelpers* CLuaInstFileHelpers::getInstance() +{ + static CLuaInstFileHelpers* LuaInstFileHelpers = NULL; + + if (!LuaInstFileHelpers) + LuaInstFileHelpers = new CLuaInstFileHelpers(); + return LuaInstFileHelpers; +} + +CLuaFileHelpers *CLuaInstFileHelpers::FileHelpersCheckData(lua_State *L, int n) +{ + return *(CLuaFileHelpers **) luaL_checkudata(L, n, LUA_FILEHELPER_CLASSNAME); +} + +void CLuaInstFileHelpers::LuaFileHelpersRegister(lua_State *L) +{ + luaL_Reg meth[] = { + { "new", CLuaInstFileHelpers::FileHelpersNew }, + { "__gc", CLuaInstFileHelpers::FileHelpersDelete }, + { NULL, NULL } + }; + + luaL_newmetatable(L, LUA_FILEHELPER_CLASSNAME); + luaL_setfuncs(L, meth, 0); + lua_pushvalue(L, -1); + lua_setfield(L, -1, "__index"); + lua_setglobal(L, LUA_FILEHELPER_CLASSNAME); +} + +int CLuaInstFileHelpers::FileHelpersNew(lua_State *L) +{ + CLuaFileHelpers **udata = (CLuaFileHelpers **) lua_newuserdata(L, sizeof(CLuaFileHelpers *)); + *udata = new CLuaFileHelpers(); + luaL_getmetatable(L, LUA_FILEHELPER_CLASSNAME); + lua_setmetatable(L, -2); + return 1; +} + + + + + +int CLuaInstFileHelpers::FileHelpersDelete(lua_State *L) +{ + CLuaFileHelpers *D = FileHelpersCheckData(L, 1); + if (!D) return 0; + delete D; + return 0; +} diff --git a/src/gui/lua/lua_filehelpers.h b/src/gui/lua/lua_filehelpers.h new file mode 100644 index 000000000..c086593bb --- /dev/null +++ b/src/gui/lua/lua_filehelpers.h @@ -0,0 +1,45 @@ +/* + * lua file helpers functions + * + * (C) 2016 M. Liebmann (micha-bbg) + * + * 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, see . + */ + +#ifndef _LUAFILEHELPERS_H +#define _LUAFILEHELPERS_H + +class CLuaFileHelpers +{ + public: + CLuaFileHelpers() {}; + ~CLuaFileHelpers() {}; +}; + +class CLuaInstFileHelpers +{ + public: + + CLuaInstFileHelpers() {}; + ~CLuaInstFileHelpers() {}; + static CLuaInstFileHelpers* getInstance(); + static void LuaFileHelpersRegister(lua_State *L); + + private: + static CLuaFileHelpers *FileHelpersCheckData(lua_State *L, int n); + static int FileHelpersNew(lua_State *L); + static int FileHelpersDelete(lua_State *L); +}; + +#endif //_LUAFILEHELPERS_H diff --git a/src/gui/lua/luainstance.cpp b/src/gui/lua/luainstance.cpp index d5de296b6..ad5ca34e8 100644 --- a/src/gui/lua/luainstance.cpp +++ b/src/gui/lua/luainstance.cpp @@ -44,6 +44,7 @@ #include "lua_cc_window.h" #include "lua_configfile.h" #include "lua_curl.h" +#include "lua_filehelpers.h" #include "lua_hintbox.h" #include "lua_menue.h" #include "lua_messagebox.h" @@ -621,6 +622,7 @@ void LuaInstRegisterFunctions(lua_State *L, bool fromThreads/*=false*/) CLuaInstCCWindow::getInstance()->CCWindowRegister(L); CLuaInstConfigFile::getInstance()->LuaConfigFileRegister(L); CLuaInstCurl::getInstance()->LuaCurlRegister(L); + CLuaInstFileHelpers::getInstance()->LuaFileHelpersRegister(L); CLuaInstHintbox::getInstance()->HintboxRegister(L); CLuaInstMenu::getInstance()->MenuRegister(L); CLuaInstMessagebox::getInstance()->MessageboxRegister(L); diff --git a/src/gui/lua/luainstance_helpers.h b/src/gui/lua/luainstance_helpers.h index cf6b9ba30..fa54bb690 100644 --- a/src/gui/lua/luainstance_helpers.h +++ b/src/gui/lua/luainstance_helpers.h @@ -2,7 +2,7 @@ * lua instance helper functions * * (C) 2013 Stefan Seyfried (seife) - * (C) 2014-2015 M. Liebmann (micha-bbg) + * (C) 2014-2016 M. Liebmann (micha-bbg) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -30,6 +30,7 @@ #define LUA_MISC_CLASSNAME "misc" #define LUA_CURL_CLASSNAME "curl" #define LUA_HEADER_CLASSNAME "header" +#define LUA_FILEHELPER_CLASSNAME "filehelpers" #define LUA_WIKI "https://wiki.neutrino-hd.de/wiki" //#define LUA_WIKI "https://wiki.slknet.de/wiki" From cba27701a9cbfd5078a861814b65688cb401a2fb Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Sat, 3 Sep 2016 11:44:58 +0200 Subject: [PATCH 02/17] helpers.cpp: Add itoa() function Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/38470a8a80ed969eeb0e5f87ee353e71b0bb83a5 Author: Michael Liebmann Date: 2016-09-03 (Sat, 03 Sep 2016) --- src/system/helpers.cpp | 32 ++++++++++++++++++++++++++++++++ src/system/helpers.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index 9a4b054f5..5a88ef0db 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -951,6 +951,38 @@ std::string to_string(unsigned long long i) return s.str(); } +/** + * C++ version 0.4 std::string style "itoa": + * Contributions from Stuart Lowe, Ray-Yuan Sheu, + + * Rodrigo de Salvo Braz, Luc Gallant, John Maloney + * and Brian Hunt + */ +std::string itoa(int value, int base) +{ + std::string buf; + + // check that the base if valid + if (base < 2 || base > 16) return buf; + + enum { kMaxDigits = 35 }; + buf.reserve( kMaxDigits ); // Pre-allocate enough space. + + int quotient = value; + + // Translating number to string with base: + do { + buf += "0123456789abcdef"[ std::abs( quotient % base ) ]; + quotient /= base; + } while ( quotient ); + + // Append the negative sign + if ( value < 0) buf += '-'; + + std::reverse( buf.begin(), buf.end() ); + return buf; +} + std::string getJFFS2MountPoint(int mtdPos) { FILE* fd = fopen("/proc/mounts", "r"); diff --git a/src/system/helpers.h b/src/system/helpers.h index 3b26a12a6..65146830e 100644 --- a/src/system/helpers.h +++ b/src/system/helpers.h @@ -105,6 +105,8 @@ std::string to_string(unsigned long); std::string to_string(long long); std::string to_string(unsigned long long); +std::string itoa(int value, int base); + inline int atoi(std::string &s) { return atoi(s.c_str()); } inline int atoi(const std::string &s) { return atoi(s.c_str()); } inline int access(std::string &s, int mode) { return access(s.c_str(), mode); } From c4d4a3abf6c19f4b71119caef3e914661e27e3d5 Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Sat, 3 Sep 2016 11:45:02 +0200 Subject: [PATCH 03/17] CFileHelpers::copyFile: Rewrite mode handling Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/64b5d36c5284fc111e20ef385025d113a8cc4db0 Author: Michael Liebmann Date: 2016-09-03 (Sat, 03 Sep 2016) --- src/system/helpers.cpp | 30 +++++++++++++++++++++++++++--- src/system/helpers.h | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index 5a88ef0db..3391b4e3d 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -554,12 +554,36 @@ CFileHelpers* CFileHelpers::getInstance() return FileHelpers; } -bool CFileHelpers::copyFile(const char *Src, const char *Dst, mode_t mode) +bool CFileHelpers::copyFile(const char *Src, const char *Dst, mode_t forceMode/*=0*/) { doCopyFlag = true; - unlink(Dst); + + /* + set mode for Dst + ---------------- + when forceMode==0 (default) then + when Dst exists + mode = mode from Dst + else + mode = mode from Src + else + mode = forceMode + */ + mode_t mode = forceMode & 0x0FFF; + if (mode == 0) { + static struct stat FileInfo; + const char *f = Dst; + if (!file_exists(Dst)) + f = Src; + if (lstat(f, &FileInfo) == -1) + return false; + mode = FileInfo.st_mode & 0x0FFF; + } + if ((fd1 = open(Src, O_RDONLY)) < 0) return false; + if (file_exists(Dst)) + unlink(Dst); if ((fd2 = open(Dst, O_WRONLY | O_CREAT, mode)) < 0) { close(fd1); return false; @@ -692,7 +716,7 @@ bool CFileHelpers::copyDir(const char *Src, const char *Dst, bool backupMode) std::string save = ""; if (backupMode && (CExtUpdate::getInstance()->isBlacklistEntry(srcPath))) save = ".save"; - copyFile(srcPath, (dstPath + save).c_str(), FileInfo.st_mode & 0x0FFF); + copyFile(srcPath, (dstPath + save).c_str()); /* mode is set by copyFile */ } } } diff --git a/src/system/helpers.h b/src/system/helpers.h index 65146830e..716b2a0bc 100644 --- a/src/system/helpers.h +++ b/src/system/helpers.h @@ -87,7 +87,7 @@ class CFileHelpers static CFileHelpers* getInstance(); bool doCopyFlag; - bool copyFile(const char *Src, const char *Dst, mode_t mode); + bool copyFile(const char *Src, const char *Dst, mode_t forceMode=0); bool copyDir(const char *Src, const char *Dst, bool backupMode=false); static bool createDir(std::string& Dir, mode_t mode = 755); static bool createDir(const char *Dir, mode_t mode = 755){std::string dir = std::string(Dir);return createDir(dir, mode);} From f1b6e6a33550d283ae28ce73b2107e620c26f89a Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Sat, 3 Sep 2016 21:14:57 +0200 Subject: [PATCH 04/17] helpers.cpp: Add cp() function Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/5198a13282dd7c907c92957d853589be9282ff2f Author: Michael Liebmann Date: 2016-09-03 (Sat, 03 Sep 2016) --- src/system/helpers.cpp | 110 +++++++++++++++++++++++++++++++++++++++++ src/system/helpers.h | 1 + 2 files changed, 111 insertions(+) diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index 3391b4e3d..3f3eb7c76 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -554,6 +554,116 @@ CFileHelpers* CFileHelpers::getInstance() return FileHelpers; } +bool CFileHelpers::cp(const char *Src, const char *Dst, const char *Flags/*=""*/) +{ + if ((Src == NULL) || (Dst == NULL)) + return false; + + std::string src = Src; + src = trim(src); + if (src.find_first_of("/") != 0) + src = "./" + src; + size_t pos = src.find_last_of("/"); + if (pos == src.length()-1) + src = src.substr(0, pos); + + std::string dst = Dst; + dst = trim(dst); + if (dst.find_first_of("/") != 0) + dst = "./" + dst; + pos = dst.find_last_of("/"); + if (pos == dst.length()-1) + dst = dst.substr(0, pos); + + bool wildcards = (src.find("*") != std::string::npos); + bool recursive = ((strchr(Flags, 'r') != NULL) || (strchr(Flags, 'a') != NULL)); + bool no_dereference = ((strchr(Flags, 'd') != NULL) || (strchr(Flags, 'a') != NULL)); + + static struct stat FileInfo; + char buf[PATH_MAX]; + if (wildcards == false) { + if (!file_exists(src.c_str())) + return false; + if (lstat(src.c_str(), &FileInfo) == -1) + return false; + + pos = src.find_last_of("/"); + std::string fname = src.substr(pos); + + static struct stat FileInfo2; + // is symlink + if (S_ISLNK(FileInfo.st_mode)) { + int len = readlink(src.c_str(), buf, sizeof(buf)-1); + if (len != -1) { + buf[len] = '\0'; + if (!no_dereference) { /* copy */ + std::string buf_ = (std::string)buf; + char buf2[PATH_MAX + 1]; + if (buf[0] != '/') + buf_ = getPathName(src) + "/" + buf_; + buf_ = (std::string)realpath(buf_.c_str(), buf2); + //printf("\n>>>> RealPath: %s\n \n", buf_.c_str()); + if (file_exists(dst.c_str()) && (lstat(dst.c_str(), &FileInfo2) != -1)){ + if (S_ISDIR(FileInfo2.st_mode)) + copyFile(buf_.c_str(), (dst + fname).c_str()); + else { + unlink(dst.c_str()); + copyFile(buf_.c_str(), dst.c_str()); + } + } + else + copyFile(buf_.c_str(), dst.c_str()); + } + else { /* link */ + if (file_exists(dst.c_str()) && (lstat(dst.c_str(), &FileInfo2) != -1)){ + if (S_ISDIR(FileInfo2.st_mode)) + symlink(buf, (dst + fname).c_str()); + else { + unlink(dst.c_str()); + symlink(buf, dst.c_str()); + } + } + else + symlink(buf, dst.c_str()); + } + } + } + // is directory + else if (S_ISDIR(FileInfo.st_mode)) { + if (recursive) + copyDir(src.c_str(), dst.c_str()); + else { + printf("#### [%s:%d] 'recursive flag' must be set to copy dir.\n", __func__, __LINE__); + return false; + } + } + // is file + else if (S_ISREG(FileInfo.st_mode)) { + if (file_exists(dst.c_str()) && (lstat(dst.c_str(), &FileInfo2) != -1)){ + if (S_ISDIR(FileInfo2.st_mode)) + copyFile(src.c_str(), (dst + fname).c_str()); + else { + unlink(dst.c_str()); + copyFile(src.c_str(), dst.c_str()); + } + } + else + copyFile(src.c_str(), dst.c_str()); + } + else { + printf("#### [%s:%d] Currently unsupported st_mode.\n", __func__, __LINE__); + return false; + } + + } + else { + printf("#### [%s:%d] Wildcard feature not yet realized.\n", __func__, __LINE__); + return false; + } + + return true; +} + bool CFileHelpers::copyFile(const char *Src, const char *Dst, mode_t forceMode/*=0*/) { doCopyFlag = true; diff --git a/src/system/helpers.h b/src/system/helpers.h index 716b2a0bc..74276b12e 100644 --- a/src/system/helpers.h +++ b/src/system/helpers.h @@ -87,6 +87,7 @@ class CFileHelpers static CFileHelpers* getInstance(); bool doCopyFlag; + bool cp(const char *Src, const char *Dst, const char *Flags=""); bool copyFile(const char *Src, const char *Dst, mode_t forceMode=0); bool copyDir(const char *Src, const char *Dst, bool backupMode=false); static bool createDir(std::string& Dir, mode_t mode = 755); From f6b960e97e88bffb028f945690e84ebbfa67a41c Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Sat, 3 Sep 2016 21:54:47 +0200 Subject: [PATCH 05/17] lua_filehelpers.cpp: Add lua script function 'cp()' - Set Lua api version to 1.48 Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/270cd318ec0e32f4e2b138603bdbfc2b7c4fb206 Author: Michael Liebmann Date: 2016-09-03 (Sat, 03 Sep 2016) --- src/gui/lua/lua_api_version.h | 2 +- src/gui/lua/lua_filehelpers.cpp | 45 +++++++++++++++++++++++++++++++-- src/gui/lua/lua_filehelpers.h | 1 + 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/gui/lua/lua_api_version.h b/src/gui/lua/lua_api_version.h index dd5ac6fa7..e2a052eab 100644 --- a/src/gui/lua/lua_api_version.h +++ b/src/gui/lua/lua_api_version.h @@ -4,4 +4,4 @@ * to luainstance.h changes */ #define LUA_API_VERSION_MAJOR 1 -#define LUA_API_VERSION_MINOR 47 +#define LUA_API_VERSION_MINOR 48 diff --git a/src/gui/lua/lua_filehelpers.cpp b/src/gui/lua/lua_filehelpers.cpp index 8abffb9c3..68bcaf76c 100644 --- a/src/gui/lua/lua_filehelpers.cpp +++ b/src/gui/lua/lua_filehelpers.cpp @@ -49,8 +49,9 @@ CLuaFileHelpers *CLuaInstFileHelpers::FileHelpersCheckData(lua_State *L, int n) void CLuaInstFileHelpers::LuaFileHelpersRegister(lua_State *L) { luaL_Reg meth[] = { - { "new", CLuaInstFileHelpers::FileHelpersNew }, - { "__gc", CLuaInstFileHelpers::FileHelpersDelete }, + { "new", CLuaInstFileHelpers::FileHelpersNew }, + { "cp", CLuaInstFileHelpers::FileHelpersCp }, + { "__gc", CLuaInstFileHelpers::FileHelpersDelete }, { NULL, NULL } }; @@ -70,6 +71,46 @@ int CLuaInstFileHelpers::FileHelpersNew(lua_State *L) return 1; } +int CLuaInstFileHelpers::FileHelpersCp(lua_State *L) +{ + CLuaFileHelpers *D = FileHelpersCheckData(L, 1); + if (!D) return 0; + + int numargs = lua_gettop(L) - 1; + int min_numargs = 2; + if (numargs < min_numargs) { + printf("luascript cp: not enough arguments (%d, expected %d)\n", numargs, min_numargs); + lua_pushboolean(L, false); + return 1; + } + + if (!lua_isstring(L, 2)) { + printf("luascript cp: argument 1 is not a string.\n"); + lua_pushboolean(L, false); + return 1; + } + const char *from = ""; + from = luaL_checkstring(L, 2); + + if (!lua_isstring(L, 3)) { + printf("luascript cp: argument 2 is not a string.\n"); + lua_pushboolean(L, false); + return 1; + } + const char *to = ""; + to = luaL_checkstring(L, 3); + + const char *flags = ""; + if (numargs > min_numargs) + flags = luaL_checkstring(L, 4); + + bool ret = false; + CFileHelpers fh; + ret = fh.cp(from, to, flags); + + lua_pushboolean(L, ret); + return 1; +} diff --git a/src/gui/lua/lua_filehelpers.h b/src/gui/lua/lua_filehelpers.h index c086593bb..7bdd8b642 100644 --- a/src/gui/lua/lua_filehelpers.h +++ b/src/gui/lua/lua_filehelpers.h @@ -39,6 +39,7 @@ class CLuaInstFileHelpers private: static CLuaFileHelpers *FileHelpersCheckData(lua_State *L, int n); static int FileHelpersNew(lua_State *L); + static int FileHelpersCp(lua_State *L); static int FileHelpersDelete(lua_State *L); }; From bd039291bdedd62ff3e045ba88e54017ff7af216 Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Sun, 4 Sep 2016 12:00:15 +0200 Subject: [PATCH 06/17] Add alternative variant for the display of __FILE__ (__path_file__) - __path_file__ includes the relevant parts of source path Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/92a88906a594ac1e9ce540c31f59a79d91384a7c Author: Michael Liebmann Date: 2016-09-04 (Sun, 04 Sep 2016) --- configure.ac | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configure.ac b/configure.ac index b0651c6a8..cf1fc12ee 100644 --- a/configure.ac +++ b/configure.ac @@ -228,8 +228,10 @@ fi # hack to define a short filename also for out-of-tree build if test `dirname $0` = `pwd`; then HWLIB_CFLAGS="$HWLIB_CFLAGS "'-D__file__=__FILE__' + HWLIB_CFLAGS="$HWLIB_CFLAGS "'-D__path_file__=__FILE__' else HWLIB_CFLAGS="$HWLIB_CFLAGS "'-D__file__="\"$(subst $(srcdir)/,,$(abspath $<))\""' + HWLIB_CFLAGS="$HWLIB_CFLAGS "'-D__path_file__="\"$(subst $(top_srcdir)/,,$(abspath $<))\""' fi # # Check for libtdservicedb - the new one - for testing only From 9dc7398baa0c6f5a7c62d3230a2b1e0bb0f8a522 Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Sun, 4 Sep 2016 12:00:20 +0200 Subject: [PATCH 07/17] CFileHelpers: Add DebugInfo functions for displaying error messages.. ..in lua script functions Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/83a902d524703117d5a8881c6e14d74d2fb4f1d1 Author: Michael Liebmann Date: 2016-09-04 (Sun, 04 Sep 2016) --- src/system/helpers.cpp | 32 ++++++++++++++++++++++++++++++++ src/system/helpers.h | 17 +++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index 3f3eb7c76..9cfbab8c8 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -538,6 +538,8 @@ CFileHelpers::CFileHelpers() FileBufSize = 0xFFFF; FileBuf = new char[FileBufSize]; doCopyFlag = true; + ConsoleQuiet = false; + clearDebugInfo(); } CFileHelpers::~CFileHelpers() @@ -554,6 +556,36 @@ CFileHelpers* CFileHelpers::getInstance() return FileHelpers; } +void CFileHelpers::clearDebugInfo() +{ + DebugInfo.msg.clear(); + DebugInfo.file.clear(); + DebugInfo.func.clear(); + DebugInfo.line = 0; +} + +void CFileHelpers::setDebugInfo(const char* msg, const char* file, const char* func, int line) +{ + DebugInfo.msg = msg; + DebugInfo.file = file; + DebugInfo.func = func; + DebugInfo.line = line; +} + +void CFileHelpers::readDebugInfo(helpersDebugInfo* di) +{ + di->msg = DebugInfo.msg; + di->file = DebugInfo.file; + di->func = DebugInfo.func; + di->line = DebugInfo.line; +} + +void CFileHelpers::printDebugInfo() +{ + if (!ConsoleQuiet) + printf(">>>> [%s:%d] %s\n", DebugInfo.func.c_str(), DebugInfo.line, DebugInfo.msg.c_str()); +} + bool CFileHelpers::cp(const char *Src, const char *Dst, const char *Flags/*=""*/) { if ((Src == NULL) || (Dst == NULL)) diff --git a/src/system/helpers.h b/src/system/helpers.h index 74276b12e..3f11909dd 100644 --- a/src/system/helpers.h +++ b/src/system/helpers.h @@ -74,6 +74,13 @@ time_t toEpoch(std::string &date); std::string& str_replace(const std::string &search, const std::string &replace, std::string &text); std::string& htmlEntityDecode(std::string& text); +struct helpersDebugInfo { + std::string msg; + std::string file; + std::string func; + int line; +}; + class CFileHelpers { private: @@ -81,12 +88,22 @@ class CFileHelpers char *FileBuf; int fd1, fd2; + bool ConsoleQuiet; + helpersDebugInfo DebugInfo; + void setDebugInfo(const char* msg, const char* file, const char* func, int line); + void printDebugInfo(); + public: CFileHelpers(); ~CFileHelpers(); static CFileHelpers* getInstance(); bool doCopyFlag; + void clearDebugInfo(); + void readDebugInfo(helpersDebugInfo* di); + void setConsoleQuiet(bool q) { ConsoleQuiet = q; }; + bool getConsoleQuiet() { return ConsoleQuiet; }; + bool cp(const char *Src, const char *Dst, const char *Flags=""); bool copyFile(const char *Src, const char *Dst, mode_t forceMode=0); bool copyDir(const char *Src, const char *Dst, bool backupMode=false); From 0143837e949f14470f71f4e0fe9e480b922ef9cf Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Sun, 4 Sep 2016 12:00:24 +0200 Subject: [PATCH 08/17] Use DebugInfo functions in CFileHelpers::cp / lua cp Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/de07369d68a0d7c6cd474616682f56d39fea74cc Author: Michael Liebmann Date: 2016-09-04 (Sun, 04 Sep 2016) --- src/gui/lua/lua_filehelpers.cpp | 10 ++++++++++ src/system/helpers.cpp | 26 +++++++++++++++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/gui/lua/lua_filehelpers.cpp b/src/gui/lua/lua_filehelpers.cpp index 68bcaf76c..4b11c3bdf 100644 --- a/src/gui/lua/lua_filehelpers.cpp +++ b/src/gui/lua/lua_filehelpers.cpp @@ -106,7 +106,17 @@ int CLuaInstFileHelpers::FileHelpersCp(lua_State *L) bool ret = false; CFileHelpers fh; + fh.setConsoleQuiet(true); ret = fh.cp(from, to, flags); + if (ret == false) { + helpersDebugInfo di; + fh.readDebugInfo(&di); + lua_Debug ar; + lua_getstack(L, 1, &ar); + lua_getinfo(L, "Sl", &ar); + printf(">>> Lua script error [%s:%d] %s\n (error from neutrino: [%s:%d])\n", + ar.short_src, ar.currentline, di.msg.c_str(), di.file.c_str(), di.line); + } lua_pushboolean(L, ret); return 1; diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index 9cfbab8c8..61cb77718 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -588,8 +588,12 @@ void CFileHelpers::printDebugInfo() bool CFileHelpers::cp(const char *Src, const char *Dst, const char *Flags/*=""*/) { - if ((Src == NULL) || (Dst == NULL)) + clearDebugInfo(); + if ((Src == NULL) || (Dst == NULL)) { + setDebugInfo("One or more parameters are NULL", __path_file__, __func__, __LINE__); + printDebugInfo(); return false; + } std::string src = Src; src = trim(src); @@ -614,10 +618,16 @@ bool CFileHelpers::cp(const char *Src, const char *Dst, const char *Flags/*=""*/ static struct stat FileInfo; char buf[PATH_MAX]; if (wildcards == false) { - if (!file_exists(src.c_str())) + if (!file_exists(src.c_str())) { + setDebugInfo("Source file not exist", __path_file__, __func__, __LINE__); + printDebugInfo(); return false; - if (lstat(src.c_str(), &FileInfo) == -1) + } + if (lstat(src.c_str(), &FileInfo) == -1) { + setDebugInfo("lstat error", __path_file__, __func__, __LINE__); + printDebugInfo(); return false; + } pos = src.find_last_of("/"); std::string fname = src.substr(pos); @@ -665,7 +675,8 @@ bool CFileHelpers::cp(const char *Src, const char *Dst, const char *Flags/*=""*/ if (recursive) copyDir(src.c_str(), dst.c_str()); else { - printf("#### [%s:%d] 'recursive flag' must be set to copy dir.\n", __func__, __LINE__); + setDebugInfo("'recursive flag' must be set to copy dir.", __path_file__, __func__, __LINE__); + printDebugInfo(); return false; } } @@ -683,13 +694,14 @@ bool CFileHelpers::cp(const char *Src, const char *Dst, const char *Flags/*=""*/ copyFile(src.c_str(), dst.c_str()); } else { - printf("#### [%s:%d] Currently unsupported st_mode.\n", __func__, __LINE__); + setDebugInfo("Currently unsupported st_mode.", __path_file__, __func__, __LINE__); + printDebugInfo(); return false; } - } else { - printf("#### [%s:%d] Wildcard feature not yet realized.\n", __func__, __LINE__); + setDebugInfo("Wildcard feature not yet realized.", __path_file__, __func__, __LINE__); + printDebugInfo(); return false; } From 3bd7c3f7d9e812fcbb5fd536b36ca1268b0c0c29 Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Sun, 4 Sep 2016 18:54:45 +0200 Subject: [PATCH 09/17] lua_filehelpers.cpp: Add lua script function 'chmod()' - Set Lua api version to 1.49 Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/ab7d90de3f20a22bb5f6f7af5972304a5b67a26c Author: Michael Liebmann Date: 2016-09-04 (Sun, 04 Sep 2016) --- src/gui/lua/lua_api_version.h | 2 +- src/gui/lua/lua_filehelpers.cpp | 39 +++++++++++++++++++++++++++++++++ src/gui/lua/lua_filehelpers.h | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/gui/lua/lua_api_version.h b/src/gui/lua/lua_api_version.h index e2a052eab..54b49c965 100644 --- a/src/gui/lua/lua_api_version.h +++ b/src/gui/lua/lua_api_version.h @@ -4,4 +4,4 @@ * to luainstance.h changes */ #define LUA_API_VERSION_MAJOR 1 -#define LUA_API_VERSION_MINOR 48 +#define LUA_API_VERSION_MINOR 49 diff --git a/src/gui/lua/lua_filehelpers.cpp b/src/gui/lua/lua_filehelpers.cpp index 4b11c3bdf..e27d46fc9 100644 --- a/src/gui/lua/lua_filehelpers.cpp +++ b/src/gui/lua/lua_filehelpers.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -51,6 +52,7 @@ void CLuaInstFileHelpers::LuaFileHelpersRegister(lua_State *L) luaL_Reg meth[] = { { "new", CLuaInstFileHelpers::FileHelpersNew }, { "cp", CLuaInstFileHelpers::FileHelpersCp }, + { "chmod", CLuaInstFileHelpers::FileHelpersChmod }, { "__gc", CLuaInstFileHelpers::FileHelpersDelete }, { NULL, NULL } }; @@ -122,6 +124,43 @@ int CLuaInstFileHelpers::FileHelpersCp(lua_State *L) return 1; } +int CLuaInstFileHelpers::FileHelpersChmod(lua_State *L) +{ + CLuaFileHelpers *D = FileHelpersCheckData(L, 1); + if (!D) return 0; + + int numargs = lua_gettop(L) - 1; + int min_numargs = 2; + if (numargs < min_numargs) { + printf("luascript chmod: not enough arguments (%d, expected %d)\n", numargs, min_numargs); + lua_pushboolean(L, false); + return 1; + } + + const char *file = ""; + file = luaL_checkstring(L, 2); + + int mode_i = luaL_checkint(L, 3); + /* Hack for convert lua number to octal */ + std::string mode_s = itoa(mode_i, 10); + mode_t mode = (mode_t)(strtol(mode_s.c_str(), (char **)NULL, 8) & 0x0FFF); + //printf("\n##### [%s:%d] str: %s, okt: %o \n \n", __func__, __LINE__, mode_s.c_str(), (int)mode); + + bool ret = true; + if (chmod(file, mode) != 0) { + ret = false; + lua_Debug ar; + lua_getstack(L, 1, &ar); + lua_getinfo(L, "Sl", &ar); + const char* s = strerror(errno); + printf(">>> Lua script error [%s:%d] %s\n (error from neutrino: [%s:%d])\n", + ar.short_src, ar.currentline, s, __path_file__, __LINE__); + } + + lua_pushboolean(L, ret); + return 1; +} + diff --git a/src/gui/lua/lua_filehelpers.h b/src/gui/lua/lua_filehelpers.h index 7bdd8b642..72dc9c871 100644 --- a/src/gui/lua/lua_filehelpers.h +++ b/src/gui/lua/lua_filehelpers.h @@ -40,6 +40,7 @@ class CLuaInstFileHelpers static CLuaFileHelpers *FileHelpersCheckData(lua_State *L, int n); static int FileHelpersNew(lua_State *L); static int FileHelpersCp(lua_State *L); + static int FileHelpersChmod(lua_State *L); static int FileHelpersDelete(lua_State *L); }; From a956b1c01fa1052dc68cc8cee9965dec4264e2d0 Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Sun, 4 Sep 2016 18:54:50 +0200 Subject: [PATCH 10/17] lua_filehelpers.cpp: Add lua script function 'touch()' - Set Lua api version to 1.50 Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/ab322416dc124cf1dc51170198e9f017c131fdee Author: Michael Liebmann Date: 2016-09-04 (Sun, 04 Sep 2016) --- src/gui/lua/lua_api_version.h | 2 +- src/gui/lua/lua_filehelpers.cpp | 64 +++++++++++++++++++++++++++++++++ src/gui/lua/lua_filehelpers.h | 1 + 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/gui/lua/lua_api_version.h b/src/gui/lua/lua_api_version.h index 54b49c965..26835c5c1 100644 --- a/src/gui/lua/lua_api_version.h +++ b/src/gui/lua/lua_api_version.h @@ -4,4 +4,4 @@ * to luainstance.h changes */ #define LUA_API_VERSION_MAJOR 1 -#define LUA_API_VERSION_MINOR 49 +#define LUA_API_VERSION_MINOR 50 diff --git a/src/gui/lua/lua_filehelpers.cpp b/src/gui/lua/lua_filehelpers.cpp index e27d46fc9..5a5c5a31f 100644 --- a/src/gui/lua/lua_filehelpers.cpp +++ b/src/gui/lua/lua_filehelpers.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -53,6 +54,7 @@ void CLuaInstFileHelpers::LuaFileHelpersRegister(lua_State *L) { "new", CLuaInstFileHelpers::FileHelpersNew }, { "cp", CLuaInstFileHelpers::FileHelpersCp }, { "chmod", CLuaInstFileHelpers::FileHelpersChmod }, + { "touch", CLuaInstFileHelpers::FileHelpersTouch }, { "__gc", CLuaInstFileHelpers::FileHelpersDelete }, { NULL, NULL } }; @@ -161,6 +163,68 @@ int CLuaInstFileHelpers::FileHelpersChmod(lua_State *L) return 1; } +int CLuaInstFileHelpers::FileHelpersTouch(lua_State *L) +{ + CLuaFileHelpers *D = FileHelpersCheckData(L, 1); + if (!D) return 0; + + int numargs = lua_gettop(L) - 1; + int min_numargs = 1; + if (numargs < min_numargs) { + printf("luascript touch: not enough arguments (%d, expected %d)\n", numargs, min_numargs); + lua_pushboolean(L, false); + return 1; + } + + const char *file = ""; + file = luaL_checkstring(L, 2); + + bool ret = true; + lua_Debug ar; + + if (!file_exists(file)) { + FILE *f = fopen(file, "w"); + if (f == NULL) { + ret = false; + lua_getstack(L, 1, &ar); + lua_getinfo(L, "Sl", &ar); + const char* s = strerror(errno); + printf(">>> Lua script error [%s:%d] %s\n (error from neutrino: [%s:%d])\n", + ar.short_src, ar.currentline, s, __path_file__, __LINE__); + lua_pushboolean(L, ret); + return 1; + } + fclose(f); + if (numargs == min_numargs) { + lua_pushboolean(L, ret); + return 1; + } + } + + time_t modTime; + if (numargs == min_numargs) + /* current time */ + modTime = time(NULL); + else + /* new time */ + modTime = (time_t)luaL_checkint(L, 3); + + utimbuf utb; + utb.actime = modTime; + utb.modtime = modTime; + if (utime(file, &utb) != 0) { + ret = false; + lua_getstack(L, 1, &ar); + lua_getinfo(L, "Sl", &ar); + const char* s = strerror(errno); + printf(">>> Lua script error [%s:%d] %s\n (error from neutrino: [%s:%d])\n", + ar.short_src, ar.currentline, s, __path_file__, __LINE__); + } + + lua_pushboolean(L, ret); + return 1; +} + diff --git a/src/gui/lua/lua_filehelpers.h b/src/gui/lua/lua_filehelpers.h index 72dc9c871..94dbff985 100644 --- a/src/gui/lua/lua_filehelpers.h +++ b/src/gui/lua/lua_filehelpers.h @@ -41,6 +41,7 @@ class CLuaInstFileHelpers static int FileHelpersNew(lua_State *L); static int FileHelpersCp(lua_State *L); static int FileHelpersChmod(lua_State *L); + static int FileHelpersTouch(lua_State *L); static int FileHelpersDelete(lua_State *L); }; From 270d2d023b0254bc3166d78c6dcc6ecf7cd15486 Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Sun, 4 Sep 2016 20:56:06 +0200 Subject: [PATCH 11/17] src/system/helpers.h:createDir(): Set correct default for mode Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/689bc50a627a07e9df2f48d56e48325b695a9e34 Author: Michael Liebmann Date: 2016-09-04 (Sun, 04 Sep 2016) --- src/system/helpers.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/system/helpers.h b/src/system/helpers.h index 3f11909dd..1d56fe743 100644 --- a/src/system/helpers.h +++ b/src/system/helpers.h @@ -107,8 +107,8 @@ class CFileHelpers bool cp(const char *Src, const char *Dst, const char *Flags=""); bool copyFile(const char *Src, const char *Dst, mode_t forceMode=0); bool copyDir(const char *Src, const char *Dst, bool backupMode=false); - static bool createDir(std::string& Dir, mode_t mode = 755); - static bool createDir(const char *Dir, mode_t mode = 755){std::string dir = std::string(Dir);return createDir(dir, mode);} + static bool createDir(std::string& Dir, mode_t mode = 0755); + static bool createDir(const char *Dir, mode_t mode = 0755){std::string dir = std::string(Dir);return createDir(dir, mode);} static bool removeDir(const char *Dir); static uint64_t getDirSize(const char *dir); static uint64_t getDirSize(const std::string& dir){return getDirSize(dir.c_str());}; From a262f1c85ab39f06e8065ecce8782d57df7ab2e2 Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Sun, 4 Sep 2016 20:56:11 +0200 Subject: [PATCH 12/17] lua_filehelpers.cpp: Add lua script function 'rmdir()' - Set Lua api version to 1.51 Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/631708f3803db8cce7e24d36a952dcda8a3c9849 Author: Michael Liebmann Date: 2016-09-04 (Sun, 04 Sep 2016) --- src/gui/lua/lua_api_version.h | 2 +- src/gui/lua/lua_filehelpers.cpp | 34 +++++++++++++++++++++++++++++++++ src/gui/lua/lua_filehelpers.h | 1 + src/system/helpers.cpp | 5 ++++- 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/gui/lua/lua_api_version.h b/src/gui/lua/lua_api_version.h index 26835c5c1..22fc714af 100644 --- a/src/gui/lua/lua_api_version.h +++ b/src/gui/lua/lua_api_version.h @@ -4,4 +4,4 @@ * to luainstance.h changes */ #define LUA_API_VERSION_MAJOR 1 -#define LUA_API_VERSION_MINOR 50 +#define LUA_API_VERSION_MINOR 51 diff --git a/src/gui/lua/lua_filehelpers.cpp b/src/gui/lua/lua_filehelpers.cpp index 5a5c5a31f..0e472bfc9 100644 --- a/src/gui/lua/lua_filehelpers.cpp +++ b/src/gui/lua/lua_filehelpers.cpp @@ -55,6 +55,7 @@ void CLuaInstFileHelpers::LuaFileHelpersRegister(lua_State *L) { "cp", CLuaInstFileHelpers::FileHelpersCp }, { "chmod", CLuaInstFileHelpers::FileHelpersChmod }, { "touch", CLuaInstFileHelpers::FileHelpersTouch }, + { "rmdir", CLuaInstFileHelpers::FileHelpersRmdir }, { "__gc", CLuaInstFileHelpers::FileHelpersDelete }, { NULL, NULL } }; @@ -225,6 +226,39 @@ int CLuaInstFileHelpers::FileHelpersTouch(lua_State *L) return 1; } +int CLuaInstFileHelpers::FileHelpersRmdir(lua_State *L) +{ + CLuaFileHelpers *D = FileHelpersCheckData(L, 1); + if (!D) return 0; + + int numargs = lua_gettop(L) - 1; + int min_numargs = 1; + if (numargs < min_numargs) { + printf("luascript rmdir: not enough arguments (%d, expected %d)\n", numargs, min_numargs); + lua_pushboolean(L, false); + return 1; + } + + const char *dir = ""; + dir = luaL_checkstring(L, 2); + + bool ret = false; + CFileHelpers* fh = CFileHelpers::getInstance(); + fh->setConsoleQuiet(true); + ret = fh->removeDir(dir); + if (ret == false) { + helpersDebugInfo di; + fh->readDebugInfo(&di); + lua_Debug ar; + lua_getstack(L, 1, &ar); + lua_getinfo(L, "Sl", &ar); + printf(">>> Lua script error [%s:%d] %s\n (error from neutrino: [%s:%d])\n", + ar.short_src, ar.currentline, di.msg.c_str(), di.file.c_str(), di.line); + } + + lua_pushboolean(L, ret); + return 1; +} diff --git a/src/gui/lua/lua_filehelpers.h b/src/gui/lua/lua_filehelpers.h index 94dbff985..f9c5ebac4 100644 --- a/src/gui/lua/lua_filehelpers.h +++ b/src/gui/lua/lua_filehelpers.h @@ -42,6 +42,7 @@ class CLuaInstFileHelpers static int FileHelpersCp(lua_State *L); static int FileHelpersChmod(lua_State *L); static int FileHelpersTouch(lua_State *L); + static int FileHelpersRmdir(lua_State *L); static int FileHelpersDelete(lua_State *L); }; diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index 61cb77718..e6cf04e64 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -910,13 +910,16 @@ bool CFileHelpers::createDir(string& Dir, mode_t mode) bool CFileHelpers::removeDir(const char *Dir) { + CFileHelpers* fh = CFileHelpers::getInstance(); + fh->clearDebugInfo(); DIR *dir; struct dirent *entry; char path[PATH_MAX]; dir = opendir(Dir); if (dir == NULL) { - printf("Error opendir()\n"); + fh->setDebugInfo("Error opendir().", __path_file__, __func__, __LINE__); + fh->printDebugInfo(); return false; } while ((entry = readdir(dir)) != NULL) { From 389ef2d93cdcdc8f5793e33aa98aceaff6cdb8b3 Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Sun, 4 Sep 2016 20:56:15 +0200 Subject: [PATCH 13/17] lua_filehelpers.cpp: Add lua script function 'mkdir()' - Set Lua api version to 1.52 Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/906e9a2156ede50f14940160d2bf4b2e6073036b Author: Michael Liebmann Date: 2016-09-04 (Sun, 04 Sep 2016) --- src/gui/lua/lua_api_version.h | 2 +- src/gui/lua/lua_filehelpers.cpp | 44 +++++++++++++++++++++++++++++++++ src/gui/lua/lua_filehelpers.h | 1 + src/system/helpers.cpp | 9 ++++++- 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/gui/lua/lua_api_version.h b/src/gui/lua/lua_api_version.h index 22fc714af..c02208fb6 100644 --- a/src/gui/lua/lua_api_version.h +++ b/src/gui/lua/lua_api_version.h @@ -4,4 +4,4 @@ * to luainstance.h changes */ #define LUA_API_VERSION_MAJOR 1 -#define LUA_API_VERSION_MINOR 51 +#define LUA_API_VERSION_MINOR 52 diff --git a/src/gui/lua/lua_filehelpers.cpp b/src/gui/lua/lua_filehelpers.cpp index 0e472bfc9..5ff80d118 100644 --- a/src/gui/lua/lua_filehelpers.cpp +++ b/src/gui/lua/lua_filehelpers.cpp @@ -56,6 +56,7 @@ void CLuaInstFileHelpers::LuaFileHelpersRegister(lua_State *L) { "chmod", CLuaInstFileHelpers::FileHelpersChmod }, { "touch", CLuaInstFileHelpers::FileHelpersTouch }, { "rmdir", CLuaInstFileHelpers::FileHelpersRmdir }, + { "mkdir", CLuaInstFileHelpers::FileHelpersMkdir }, { "__gc", CLuaInstFileHelpers::FileHelpersDelete }, { NULL, NULL } }; @@ -260,6 +261,49 @@ int CLuaInstFileHelpers::FileHelpersRmdir(lua_State *L) return 1; } +int CLuaInstFileHelpers::FileHelpersMkdir(lua_State *L) +{ + CLuaFileHelpers *D = FileHelpersCheckData(L, 1); + if (!D) return 0; + + int numargs = lua_gettop(L) - 1; + int min_numargs = 1; + if (numargs < min_numargs) { + printf("luascript mkdir: not enough arguments (%d, expected %d)\n", numargs, min_numargs); + lua_pushboolean(L, false); + return 1; + } + + const char *dir = ""; + dir = luaL_checkstring(L, 2); + + mode_t mode = 0755; + if (numargs > min_numargs) { + int mode_i = luaL_checkint(L, 3); + /* Hack for convert lua number to octal */ + std::string mode_s = itoa(mode_i, 10); + mode = (mode_t)(strtol(mode_s.c_str(), (char **)NULL, 8) & 0x0FFF); + //printf("\n##### [%s:%d] str: %s, okt: %o \n \n", __func__, __LINE__, mode_s.c_str(), (int)mode); + } + + bool ret = false; + CFileHelpers* fh = CFileHelpers::getInstance(); + fh->setConsoleQuiet(true); + ret = fh->createDir(dir, mode); + if (ret == false) { + helpersDebugInfo di; + fh->readDebugInfo(&di); + lua_Debug ar; + lua_getstack(L, 1, &ar); + lua_getinfo(L, "Sl", &ar); + printf(">>> Lua script error [%s:%d] %s\n (error from neutrino: [%s:%d])\n", + ar.short_src, ar.currentline, di.msg.c_str(), di.file.c_str(), di.line); + } + + lua_pushboolean(L, ret); + return 1; +} + int CLuaInstFileHelpers::FileHelpersDelete(lua_State *L) diff --git a/src/gui/lua/lua_filehelpers.h b/src/gui/lua/lua_filehelpers.h index f9c5ebac4..78d03fea4 100644 --- a/src/gui/lua/lua_filehelpers.h +++ b/src/gui/lua/lua_filehelpers.h @@ -43,6 +43,7 @@ class CLuaInstFileHelpers static int FileHelpersChmod(lua_State *L); static int FileHelpersTouch(lua_State *L); static int FileHelpersRmdir(lua_State *L); + static int FileHelpersMkdir(lua_State *L); static int FileHelpersDelete(lua_State *L); }; diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index e6cf04e64..246831c56 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -882,6 +882,8 @@ bool CFileHelpers::copyDir(const char *Src, const char *Dst, bool backupMode) // false - errno is set bool CFileHelpers::createDir(string& Dir, mode_t mode) { + CFileHelpers* fh = CFileHelpers::getInstance(); + fh->clearDebugInfo(); int res = 0; for(string::iterator iter = Dir.begin() ; iter != Dir.end();) { string::iterator newIter = find(iter, Dir.end(), '/' ); @@ -895,7 +897,12 @@ bool CFileHelpers::createDir(string& Dir, mode_t mode) // We can assume that if an error // occured, following will fail too, // so break here. - dprintf(DEBUG_NORMAL, "[CFileHelpers %s] creating directory %s: %s\n", __func__, newPath.c_str(), strerror(errno)); + if (!fh->getConsoleQuiet()) + dprintf(DEBUG_NORMAL, "[CFileHelpers %s] creating directory %s: %s\n", __func__, newPath.c_str(), strerror(errno)); + char buf[1024]; + memset(buf, '\0', sizeof(buf)); + snprintf(buf, sizeof(buf)-1, "creating directory %s: %s", newPath.c_str(), strerror(errno)); + fh->setDebugInfo(buf, __path_file__, __func__, __LINE__); break; } } From 7ff676f0c0dcb510bcf839ad50870bb4dff8f57f Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Sun, 4 Sep 2016 23:35:49 +0200 Subject: [PATCH 14/17] lua_filehelpers.cpp: Add lua script function 'readlink()' - Set Lua api version to 1.53 Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/b50886faca4002682d480f9e5f62f4f712a206d2 Author: Michael Liebmann Date: 2016-09-04 (Sun, 04 Sep 2016) --- src/gui/lua/lua_api_version.h | 2 +- src/gui/lua/lua_filehelpers.cpp | 35 +++++++++++++++++++++++++++++++++ src/gui/lua/lua_filehelpers.h | 1 + 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/gui/lua/lua_api_version.h b/src/gui/lua/lua_api_version.h index c02208fb6..6e1356615 100644 --- a/src/gui/lua/lua_api_version.h +++ b/src/gui/lua/lua_api_version.h @@ -4,4 +4,4 @@ * to luainstance.h changes */ #define LUA_API_VERSION_MAJOR 1 -#define LUA_API_VERSION_MINOR 52 +#define LUA_API_VERSION_MINOR 53 diff --git a/src/gui/lua/lua_filehelpers.cpp b/src/gui/lua/lua_filehelpers.cpp index 5ff80d118..0112a0c44 100644 --- a/src/gui/lua/lua_filehelpers.cpp +++ b/src/gui/lua/lua_filehelpers.cpp @@ -57,6 +57,7 @@ void CLuaInstFileHelpers::LuaFileHelpersRegister(lua_State *L) { "touch", CLuaInstFileHelpers::FileHelpersTouch }, { "rmdir", CLuaInstFileHelpers::FileHelpersRmdir }, { "mkdir", CLuaInstFileHelpers::FileHelpersMkdir }, + { "readlink", CLuaInstFileHelpers::FileHelpersReadlink }, { "__gc", CLuaInstFileHelpers::FileHelpersDelete }, { NULL, NULL } }; @@ -304,6 +305,40 @@ int CLuaInstFileHelpers::FileHelpersMkdir(lua_State *L) return 1; } +int CLuaInstFileHelpers::FileHelpersReadlink(lua_State *L) +{ + CLuaFileHelpers *D = FileHelpersCheckData(L, 1); + if (!D) return 0; + + int numargs = lua_gettop(L) - 1; + int min_numargs = 1; + if (numargs < min_numargs) { + printf("luascript readlink: not enough arguments (%d, expected %d)\n", numargs, min_numargs); + lua_pushnil(L); + return 1; + } + + const char *link = ""; + link = luaL_checkstring(L, 2); + + char buf[PATH_MAX]; + memset(buf, '\0', sizeof(buf)); + if (readlink(link, buf, sizeof(buf)-1) == -1) { + lua_Debug ar; + lua_getstack(L, 1, &ar); + lua_getinfo(L, "Sl", &ar); + const char* s = strerror(errno); + printf(">>> Lua script error [%s:%d] %s\n (error from neutrino: [%s:%d])\n", + ar.short_src, ar.currentline, s, __path_file__, __LINE__); + + lua_pushnil(L); + return 1; + } + + lua_pushstring(L, buf); + return 1; +} + int CLuaInstFileHelpers::FileHelpersDelete(lua_State *L) diff --git a/src/gui/lua/lua_filehelpers.h b/src/gui/lua/lua_filehelpers.h index 78d03fea4..ea7fb6ee5 100644 --- a/src/gui/lua/lua_filehelpers.h +++ b/src/gui/lua/lua_filehelpers.h @@ -44,6 +44,7 @@ class CLuaInstFileHelpers static int FileHelpersTouch(lua_State *L); static int FileHelpersRmdir(lua_State *L); static int FileHelpersMkdir(lua_State *L); + static int FileHelpersReadlink(lua_State *L); static int FileHelpersDelete(lua_State *L); }; From e217a03f2c971eea9ed1d269fa752b52ee56cdbd Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Mon, 5 Sep 2016 00:27:05 +0200 Subject: [PATCH 15/17] lua_filehelpers.cpp: Add lua script function 'ln()' - Set Lua api version to 1.54 Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/95a078742b48e6c99751f3039bd18f5e05b62ef4 Author: Michael Liebmann Date: 2016-09-05 (Mon, 05 Sep 2016) --- src/gui/lua/lua_api_version.h | 2 +- src/gui/lua/lua_filehelpers.cpp | 60 +++++++++++++++++++++++++++++++++ src/gui/lua/lua_filehelpers.h | 1 + 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/gui/lua/lua_api_version.h b/src/gui/lua/lua_api_version.h index 6e1356615..dd4987b95 100644 --- a/src/gui/lua/lua_api_version.h +++ b/src/gui/lua/lua_api_version.h @@ -4,4 +4,4 @@ * to luainstance.h changes */ #define LUA_API_VERSION_MAJOR 1 -#define LUA_API_VERSION_MINOR 53 +#define LUA_API_VERSION_MINOR 54 diff --git a/src/gui/lua/lua_filehelpers.cpp b/src/gui/lua/lua_filehelpers.cpp index 0112a0c44..2335d32f0 100644 --- a/src/gui/lua/lua_filehelpers.cpp +++ b/src/gui/lua/lua_filehelpers.cpp @@ -58,6 +58,7 @@ void CLuaInstFileHelpers::LuaFileHelpersRegister(lua_State *L) { "rmdir", CLuaInstFileHelpers::FileHelpersRmdir }, { "mkdir", CLuaInstFileHelpers::FileHelpersMkdir }, { "readlink", CLuaInstFileHelpers::FileHelpersReadlink }, + { "ln", CLuaInstFileHelpers::FileHelpersLn }, { "__gc", CLuaInstFileHelpers::FileHelpersDelete }, { NULL, NULL } }; @@ -339,6 +340,65 @@ int CLuaInstFileHelpers::FileHelpersReadlink(lua_State *L) return 1; } +int CLuaInstFileHelpers::FileHelpersLn(lua_State *L) +{ + CLuaFileHelpers *D = FileHelpersCheckData(L, 1); + if (!D) return 0; + + int numargs = lua_gettop(L) - 1; + int min_numargs = 2; + if (numargs < min_numargs) { + printf("luascript ln: not enough arguments (%d, expected %d)\n", numargs, min_numargs); + lua_pushboolean(L, false); + return 1; + } + + const char *src = ""; + src = luaL_checkstring(L, 2); + const char *link = ""; + link = luaL_checkstring(L, 3); + + const char *flags = ""; + if (numargs > min_numargs) + flags = luaL_checkstring(L, 4); + + bool symlnk = (strchr(flags, 's') != NULL); + bool force = (strchr(flags, 'f') != NULL); + lua_Debug ar; + + if (!symlnk) { + lua_getstack(L, 1, &ar); + lua_getinfo(L, "Sl", &ar); + const char* s = "Currently only supports symlinks."; + printf(">>> Lua script error [%s:%d] %s\n (error from neutrino: [%s:%d])\n", + ar.short_src, ar.currentline, s, __path_file__, __LINE__); + lua_pushboolean(L, false); + return 1; + } + + bool ret = true; + if (symlink(src, link) != 0) { + if (force && (errno == EEXIST)) { + if (unlink(link) == 0) { + if (symlink(src, link) == 0) { + lua_pushboolean(L, ret); + return 1; + } + } + } + ret = false; + lua_getstack(L, 1, &ar); + lua_getinfo(L, "Sl", &ar); + const char* s = strerror(errno); + printf(">>> Lua script error [%s:%d] %s\n (error from neutrino: [%s:%d])\n", + ar.short_src, ar.currentline, s, __path_file__, __LINE__); + + } + + lua_pushboolean(L, ret); + return 1; +} + int CLuaInstFileHelpers::FileHelpersDelete(lua_State *L) diff --git a/src/gui/lua/lua_filehelpers.h b/src/gui/lua/lua_filehelpers.h index ea7fb6ee5..23f8fbf08 100644 --- a/src/gui/lua/lua_filehelpers.h +++ b/src/gui/lua/lua_filehelpers.h @@ -45,6 +45,7 @@ class CLuaInstFileHelpers static int FileHelpersRmdir(lua_State *L); static int FileHelpersMkdir(lua_State *L); static int FileHelpersReadlink(lua_State *L); + static int FileHelpersLn(lua_State *L); static int FileHelpersDelete(lua_State *L); }; From c8e4c6e0a57a9e7fc127268543e019b5b87941b4 Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Mon, 5 Sep 2016 15:25:07 +0200 Subject: [PATCH 16/17] lua_filehelpers.cpp: Add lua script function 'exist()' - Set Lua api version to 1.55 Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/52c489f211e1dec9f8af21a3c58c83f67ba2e720 Author: Michael Liebmann Date: 2016-09-05 (Mon, 05 Sep 2016) --- src/gui/lua/lua_api_version.h | 2 +- src/gui/lua/lua_filehelpers.cpp | 64 +++++++++++++++++++++++++++++++++ src/gui/lua/lua_filehelpers.h | 1 + 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/gui/lua/lua_api_version.h b/src/gui/lua/lua_api_version.h index dd4987b95..5c47c47e2 100644 --- a/src/gui/lua/lua_api_version.h +++ b/src/gui/lua/lua_api_version.h @@ -4,4 +4,4 @@ * to luainstance.h changes */ #define LUA_API_VERSION_MAJOR 1 -#define LUA_API_VERSION_MINOR 54 +#define LUA_API_VERSION_MINOR 55 diff --git a/src/gui/lua/lua_filehelpers.cpp b/src/gui/lua/lua_filehelpers.cpp index 2335d32f0..c8d1cd252 100644 --- a/src/gui/lua/lua_filehelpers.cpp +++ b/src/gui/lua/lua_filehelpers.cpp @@ -59,6 +59,7 @@ void CLuaInstFileHelpers::LuaFileHelpersRegister(lua_State *L) { "mkdir", CLuaInstFileHelpers::FileHelpersMkdir }, { "readlink", CLuaInstFileHelpers::FileHelpersReadlink }, { "ln", CLuaInstFileHelpers::FileHelpersLn }, + { "exist", CLuaInstFileHelpers::FileHelpersExist }, { "__gc", CLuaInstFileHelpers::FileHelpersDelete }, { NULL, NULL } }; @@ -399,6 +400,69 @@ int CLuaInstFileHelpers::FileHelpersLn(lua_State *L) return 1; } +int CLuaInstFileHelpers::FileHelpersExist(lua_State *L) +{ + CLuaFileHelpers *D = FileHelpersCheckData(L, 1); + if (!D) return 0; + + int numargs = lua_gettop(L) - 1; + int min_numargs = 2; + if (numargs < min_numargs) { + printf("luascript exist: not enough arguments (%d, expected %d)\n", numargs, min_numargs); + lua_pushnil(L); + return 1; + } + + bool ret = false; + bool err = false; + int errLine = 0; + std::string errMsg = ""; + + const char *file = ""; + file = luaL_checkstring(L, 2); + const char *flag = ""; + flag = luaL_checkstring(L, 3); + + if (file_exists(file)) { + struct stat FileInfo; + if (lstat(file, &FileInfo) == -1) { + err = true; + errLine = __LINE__; + errMsg = (std::string)strerror(errno); + } + else if (strchr(flag, 'f') != NULL) { + if (S_ISREG(FileInfo.st_mode)) + ret = true; + } + else if (strchr(flag, 'l') != NULL) { + if (S_ISLNK(FileInfo.st_mode)) + ret = true; + } + else if (strchr(flag, 'd') != NULL) { + if (S_ISDIR(FileInfo.st_mode)) + ret = true; + } + else { + err = true; + errLine = __LINE__; + errMsg = (strlen(flag) == 0) ? "no" : "unknown"; + errMsg += " flag given."; + } + } + + if (err) { + lua_Debug ar; + lua_getstack(L, 1, &ar); + lua_getinfo(L, "Sl", &ar); + printf(">>> Lua script error [%s:%d] %s\n (error from neutrino: [%s:%d])\n", + ar.short_src, ar.currentline, errMsg.c_str(), __path_file__, errLine); + lua_pushnil(L); + return 1; + } + + lua_pushboolean(L, ret); + return 1; +} int CLuaInstFileHelpers::FileHelpersDelete(lua_State *L) diff --git a/src/gui/lua/lua_filehelpers.h b/src/gui/lua/lua_filehelpers.h index 23f8fbf08..853f9768e 100644 --- a/src/gui/lua/lua_filehelpers.h +++ b/src/gui/lua/lua_filehelpers.h @@ -46,6 +46,7 @@ class CLuaInstFileHelpers static int FileHelpersMkdir(lua_State *L); static int FileHelpersReadlink(lua_State *L); static int FileHelpersLn(lua_State *L); + static int FileHelpersExist(lua_State *L); static int FileHelpersDelete(lua_State *L); }; From fb44db9e19c69aeee41d3e346a2ee7d41fd26b2c Mon Sep 17 00:00:00 2001 From: vanhofen Date: Mon, 5 Sep 2016 23:49:37 +0200 Subject: [PATCH 17/17] lua: add stand-alone stringinput; set lua api version to 1.56 Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/0fa4486077296696849a9a201f5e81113ce370cb Author: vanhofen Date: 2016-09-05 (Mon, 05 Sep 2016) Origin message was: ------------------ - lua: add stand-alone stringinput; set lua api version to 1.56 --- src/gui/lua/Makefile.am | 1 + src/gui/lua/lua_api_version.h | 2 +- src/gui/lua/lua_stringinput.cpp | 106 ++++++++++++++++++++++++++++++++ src/gui/lua/lua_stringinput.h | 44 +++++++++++++ src/gui/lua/luainstance.cpp | 2 + 5 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 src/gui/lua/lua_stringinput.cpp create mode 100644 src/gui/lua/lua_stringinput.h diff --git a/src/gui/lua/Makefile.am b/src/gui/lua/Makefile.am index 6b99ec4ce..05a3b91a8 100644 --- a/src/gui/lua/Makefile.am +++ b/src/gui/lua/Makefile.am @@ -37,6 +37,7 @@ libneutrino_gui_lua_a_SOURCES = \ lua_menue.cpp \ lua_messagebox.cpp \ lua_misc.cpp \ + lua_stringinput.cpp \ lua_threads.cpp \ lua_threads_copy.cpp \ lua_threads_functions.cpp \ diff --git a/src/gui/lua/lua_api_version.h b/src/gui/lua/lua_api_version.h index 5c47c47e2..b5e974561 100644 --- a/src/gui/lua/lua_api_version.h +++ b/src/gui/lua/lua_api_version.h @@ -4,4 +4,4 @@ * to luainstance.h changes */ #define LUA_API_VERSION_MAJOR 1 -#define LUA_API_VERSION_MINOR 55 +#define LUA_API_VERSION_MINOR 56 diff --git a/src/gui/lua/lua_stringinput.cpp b/src/gui/lua/lua_stringinput.cpp new file mode 100644 index 000000000..e61264b50 --- /dev/null +++ b/src/gui/lua/lua_stringinput.cpp @@ -0,0 +1,106 @@ +/* + * lua stringinput + * + * (C) 2016 Sven Hoefer (svenhoefer) + * (C) 2016 M. Liebmann (micha-bbg) + * + * 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, see . + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "luainstance.h" +#include "lua_stringinput.h" + +CLuaInstStringInput* CLuaInstStringInput::getInstance() +{ + static CLuaInstStringInput* LuaInstStringInput = NULL; + + if (!LuaInstStringInput) + LuaInstStringInput = new CLuaInstStringInput(); + return LuaInstStringInput; +} + +void CLuaInstStringInput::StringInputRegister(lua_State *L) +{ + luaL_Reg meth[] = { + { "exec", CLuaInstStringInput::StringInputExec }, + { NULL, NULL } + }; + + luaL_newmetatable(L, "stringinput"); + luaL_setfuncs(L, meth, 0); + lua_pushvalue(L, -1); + lua_setfield(L, -1, "__index"); + lua_setglobal(L, "stringinput"); +} + +/* + local return_value = stringinput.exec{ + caption="Title", + value="value", + icon="settings", + valid_chars="0123456789", + size=4 + } +*/ +int CLuaInstStringInput::StringInputExec(lua_State *L) +{ + lua_assert(lua_istable(L,1)); + + std::string name; + tableLookup(L, "name", name) || tableLookup(L, "title", name) || tableLookup(L, "caption", name); + + std::string value; + tableLookup(L, "value", value); + + lua_Integer size = 30; + tableLookup(L, "size", size); + + // TODO: Locales? + + std::string valid_chars = "abcdefghijklmnopqrstuvwxyz0123456789!\"§$%&/()=?-.@,_: "; + tableLookup(L, "valid_chars", valid_chars); + + // TODO: CChangeObserver? + + std::string icon = std::string(NEUTRINO_ICON_INFO); + tableLookup(L, "icon", icon); + + lua_Integer sms = 0; + tableLookup(L, "sms", sms); + + CStringInput *i; + if (sms) + i = new CStringInputSMS(name, &value, size, + NONEXISTANT_LOCALE, NONEXISTANT_LOCALE, valid_chars.c_str(), NULL, icon.c_str()); + else + i = new CStringInput(name, &value, size, + NONEXISTANT_LOCALE, NONEXISTANT_LOCALE, valid_chars.c_str(), NULL, icon.c_str()); + i->exec(NULL, ""); + delete i; + + lua_pushstring(L, value.c_str()); + + return 1; +} diff --git a/src/gui/lua/lua_stringinput.h b/src/gui/lua/lua_stringinput.h new file mode 100644 index 000000000..c49ad7dc0 --- /dev/null +++ b/src/gui/lua/lua_stringinput.h @@ -0,0 +1,44 @@ +/* + * lua stringinput + * + * (C) 2016 Sven Hoefer (svenhoefer) + * (C) 2016 M. Liebmann (micha-bbg) + * + * 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, see . + */ + +#ifndef _LUASTRINGINPUT_H +#define _LUASTRINGINPUT_H + +class CLuaStringInput +{ + public: + CStringInput *b; + CLuaStringInput(); + ~CLuaStringInput(); +}; + +class CLuaInstStringInput +{ + public: + CLuaInstStringInput() {}; + ~CLuaInstStringInput() {}; + static CLuaInstStringInput* getInstance(); + static void StringInputRegister(lua_State *L); + + private: + static int StringInputExec(lua_State *L); +}; + +#endif //_LUASTRINGINPUT_H diff --git a/src/gui/lua/luainstance.cpp b/src/gui/lua/luainstance.cpp index ad5ca34e8..a21cac683 100644 --- a/src/gui/lua/luainstance.cpp +++ b/src/gui/lua/luainstance.cpp @@ -49,6 +49,7 @@ #include "lua_menue.h" #include "lua_messagebox.h" #include "lua_misc.h" +#include "lua_stringinput.h" #include "lua_threads.h" #include "lua_video.h" @@ -626,6 +627,7 @@ void LuaInstRegisterFunctions(lua_State *L, bool fromThreads/*=false*/) CLuaInstHintbox::getInstance()->HintboxRegister(L); CLuaInstMenu::getInstance()->MenuRegister(L); CLuaInstMessagebox::getInstance()->MessageboxRegister(L); + CLuaInstStringInput::getInstance()->StringInputRegister(L); CLuaInstMisc::getInstance()->LuaMiscRegister(L); CLuaInstVideo::getInstance()->LuaVideoRegister(L); if (!fromThreads)