From 6d1a89c59dd429adad68ce06da5f71fb4ec61261 Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Mon, 17 Mar 2014 15:08:05 +0100 Subject: [PATCH] CLuaInstance: Add runScript() function for using in Lua script - Script runs in a new instance in neutrino context Example: local n = neutrino() n:runScript(filename [, args, ...]) Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/0a957abf31d0ccc6b6998746237da84eddef8260 Author: Michael Liebmann Date: 2014-03-17 (Mon, 17 Mar 2014) Origin message was: ------------------ CLuaInstance: Add runScript() function for using in Lua script - Script runs in a new instance in neutrino context Example: local n = neutrino() n:runScript(filename [, args, ...]) ------------------ This commit was generated by Migit --- src/gui/luainstance.cpp | 22 ++++++++++++++++++++++ src/gui/luainstance.h | 1 + 2 files changed, 23 insertions(+) diff --git a/src/gui/luainstance.cpp b/src/gui/luainstance.cpp index 13083b6a2..9d11a9392 100644 --- a/src/gui/luainstance.cpp +++ b/src/gui/luainstance.cpp @@ -401,6 +401,7 @@ const luaL_Reg CLuaInstance::methods[] = { "DisplayImage", CLuaInstance::DisplayImage }, { "Blit", CLuaInstance::Blit }, { "GetLanguage", CLuaInstance::GetLanguage }, + { "runScript", CLuaInstance::runScriptExt }, { NULL, NULL } }; @@ -709,6 +710,27 @@ int CLuaInstance::GetLanguage(lua_State *L) return 1; } +int CLuaInstance::runScriptExt(lua_State *L) +{ + CLuaData *W = CheckData(L, 1); + if (!W) return 0; + + int numargs = lua_gettop(L); + const char *script = luaL_checkstring(L, 2); + std::vector args; + for (int i = 3; i <= numargs; i++) { + std::string arg = luaL_checkstring(L, i); + if (!arg.empty()) + args.push_back(arg); + } + + CLuaInstance *lua = new CLuaInstance(); + lua->runScript(script, &args); + args.clear(); + delete lua; + return 0; +} + bool CLuaInstance::tableLookup(lua_State *L, const char *what, std::string &value) { bool res = false; diff --git a/src/gui/luainstance.h b/src/gui/luainstance.h index 035dea282..be9459c42 100644 --- a/src/gui/luainstance.h +++ b/src/gui/luainstance.h @@ -188,6 +188,7 @@ private: static int GCWindow(lua_State *L); static int Blit(lua_State *L); static int GetLanguage(lua_State *L); + static int runScriptExt(lua_State *L); static int GetSize(lua_State *L); static int DisplayImage(lua_State *L);