mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-30 17:01:08 +02:00
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:
@@ -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;
|
||||
|
Reference in New Issue
Block a user