diff --git a/aegisub/src/auto4_lua.cpp b/aegisub/src/auto4_lua.cpp index 4455e2b8a..b6368a332 100644 --- a/aegisub/src/auto4_lua.cpp +++ b/aegisub/src/auto4_lua.cpp @@ -436,7 +436,7 @@ namespace Automation4 { // load user script if (!LoadFile(L, GetFilename())) { - std::string err = str(boost::format("Error loading Lua script \"%s\":\n\n%s") % GetPrettyFilename().string() % get_string_or_default(L, -1)); + std::string err = str(boost::format("Error loading Lua script \"%s\":\n\n%s") % GetPrettyFilename().string() % get_string_or_default(L, 1)); lua_pop(L, 1); throw ScriptLoadError(err); } @@ -556,7 +556,7 @@ namespace Automation4 { try { if (!LoadFile(L, path)) - return luaL_error(L, "Error loading Lua module \"%s\":\n\n%s", path.string().c_str(), luaL_checkstring(L, -1)); + return luaL_error(L, "Error loading Lua module \"%s\":\n\n%s", path.string().c_str(), luaL_checkstring(L, 1)); break; } catch (agi::fs::FileNotFound const&) { @@ -595,7 +595,7 @@ namespace Automation4 { return luaL_error(L, "Lua include not found: %s", filename.c_str()); if (!LoadFile(L, filepath)) - return luaL_error(L, "Error loading Lua include \"%s\":\n\n%s", filename.c_str(), luaL_checkstring(L, -1)); + return luaL_error(L, "Error loading Lua include \"%s\":\n\n%s", filename.c_str(), luaL_checkstring(L, 1)); int pretop = lua_gettop(L) - 1; // don't count the function value itself lua_call(L, 0, LUA_MULTRET); diff --git a/aegisub/src/auto4_lua_scriptreader.cpp b/aegisub/src/auto4_lua_scriptreader.cpp index a5e92074a..58676bdab 100644 --- a/aegisub/src/auto4_lua_scriptreader.cpp +++ b/aegisub/src/auto4_lua_scriptreader.cpp @@ -58,6 +58,16 @@ namespace Automation4 { return false; // Leaves error message on stack lua_pushlstring(L, &buff[0], buff.size()); lua_pushstring(L, filename.string().c_str()); - return lua_pcall(L, 2, 1, 0) == 0; // Leaves script or error message on stack + if (lua_pcall(L, 2, 2, 0)) + return false; // Leaves error message on stack + + // loadstring returns nil, error on error or a function on success + if (lua_isnil(L, 1)) { + lua_remove(L, 1); + return false; + } + + lua_pop(L, 1); // Remove the extra nil for the stackchecker + return true; } }