mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-31 01:11:12 +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, ...])
This commit is contained in:
@@ -401,6 +401,7 @@ const luaL_Reg CLuaInstance::methods[] =
|
|||||||
{ "DisplayImage", CLuaInstance::DisplayImage },
|
{ "DisplayImage", CLuaInstance::DisplayImage },
|
||||||
{ "Blit", CLuaInstance::Blit },
|
{ "Blit", CLuaInstance::Blit },
|
||||||
{ "GetLanguage", CLuaInstance::GetLanguage },
|
{ "GetLanguage", CLuaInstance::GetLanguage },
|
||||||
|
{ "runScript", CLuaInstance::runScriptExt },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -709,6 +710,27 @@ int CLuaInstance::GetLanguage(lua_State *L)
|
|||||||
return 1;
|
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 CLuaInstance::tableLookup(lua_State *L, const char *what, std::string &value)
|
||||||
{
|
{
|
||||||
bool res = false;
|
bool res = false;
|
||||||
|
@@ -188,6 +188,7 @@ private:
|
|||||||
static int GCWindow(lua_State *L);
|
static int GCWindow(lua_State *L);
|
||||||
static int Blit(lua_State *L);
|
static int Blit(lua_State *L);
|
||||||
static int GetLanguage(lua_State *L);
|
static int GetLanguage(lua_State *L);
|
||||||
|
static int runScriptExt(lua_State *L);
|
||||||
static int GetSize(lua_State *L);
|
static int GetSize(lua_State *L);
|
||||||
static int DisplayImage(lua_State *L);
|
static int DisplayImage(lua_State *L);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user