From b80e7480a2c139f72d5869d5b41060a7c7fef530 Mon Sep 17 00:00:00 2001 From: "M. Liebmann" Date: Wed, 19 Mar 2014 15:15:02 +0100 Subject: [PATCH] CLuaInstance::runScript: Set script parameter 0 to 'script name'... ...for compatibility with standalone lua scripts --- src/gui/luainstance.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/gui/luainstance.cpp b/src/gui/luainstance.cpp index 9d11a9392..6883c68fe 100644 --- a/src/gui/luainstance.cpp +++ b/src/gui/luainstance.cpp @@ -339,16 +339,24 @@ void CLuaInstance::runScript(const char *fileName, std::vector *arg *error_string = std::string(lua_tostring(lua, -1)); return; } + 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())) { - lua_createtable(lua, argv->size(), 0); - int n = 0; for(std::vector::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);