CLuaInstance::runScript: Set script parameter 0 to 'script name'...

...for compatibility with standalone lua scripts


Origin commit data
------------------
Commit: b80e7480a2
Author: Michael Liebmann <tuxcode.bbg@gmail.com>
Date: 2014-03-19 (Wed, 19 Mar 2014)
This commit is contained in:
Michael Liebmann
2014-03-19 15:15:02 +01:00
parent c700df0074
commit a27f7c3dfb

View File

@@ -339,16 +339,24 @@ void CLuaInstance::runScript(const char *fileName, std::vector<std::string> *arg
*error_string = std::string(lua_tostring(lua, -1));
return;
}
set_lua_variables(lua);
if (argv && (!argv->empty())) {
lua_createtable(lua, argv->size(), 0);
int argvSize = 1;
int n = 0;
set_lua_variables(lua);
if (argv && (!argv->empty()))
argvSize += argv->size();
lua_createtable(lua, argvSize, 0);
// arg0 is scriptname
lua_pushstring(lua, fileName);
lua_rawseti(lua, -2, n++);
if (argv && (!argv->empty())) {
for(std::vector<std::string>::iterator it = argv->begin(); it != argv->end(); ++it) {
lua_pushstring(lua, it->c_str());
lua_rawseti(lua, -2, n++);
}
lua_setglobal(lua, "arg");
}
lua_setglobal(lua, "arg");
status = lua_pcall(lua, 0, LUA_MULTRET, 0);
if (result_code)
*result_code = to_string(status);