From 1e13670c70b74aae3ffd7896c978e6483d438b06 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 28 Sep 2011 19:52:02 +0000 Subject: [PATCH] Improve error handling in LuaModuleLoader and don't keep trying to load modules after one has been found Originally committed to SVN as r5662. --- aegisub/src/auto4_lua.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/aegisub/src/auto4_lua.cpp b/aegisub/src/auto4_lua.cpp index eb9312546..614b7d304 100644 --- a/aegisub/src/auto4_lua.cpp +++ b/aegisub/src/auto4_lua.cpp @@ -53,6 +53,7 @@ #include #endif +#include #include #include @@ -379,6 +380,7 @@ namespace Automation4 { wxString module(get_wxstring(L, -1)); module.Replace(".", LUA_DIRSEP); + // Get the lua package include path (which the user may have modified) lua_getglobal(L, "package"); lua_pushstring(L, "path"); lua_gettable(L, -2); @@ -389,13 +391,24 @@ namespace Automation4 { while (toker.HasMoreTokens()) { wxString filename = toker.GetNextToken(); filename.Replace("?", module); - if (wxFileName::FileExists(filename)) { + try { LuaScriptReader script_reader(filename); if (lua_load(L, script_reader.reader_func, &script_reader, filename.utf8_str())) { return luaL_error(L, "Error loading Lua module \"%s\":\n\n%s", filename.utf8_str().data(), lua_tostring(L, -1)); } + break; + } + catch (agi::acs::AcsNotFound const&) { + // Not an error so swallow and continue on + } + catch (agi::acs::AcsNotAFile const&) { + // Not an error so swallow and continue on + } + catch (agi::Exception const& e) { + return luaL_error(L, "Error loading Lua module \"%s\":\n\n%s", filename.utf8_str().data(), e.GetChainedMessage().c_str()); } } + return lua_gettop(L) - pretop; }