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: 0a957abf31
Author: Michael Liebmann <tuxcode.bbg@gmail.com>
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
This commit is contained in:
Michael Liebmann
2014-03-17 15:08:05 +01:00
parent 393eb305da
commit 6d1a89c59d
2 changed files with 23 additions and 0 deletions

View File

@@ -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<std::string> 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;