From 5c487ae75f6868a68c2fd949df4412dbc8dab0b4 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 25 Oct 2011 01:15:03 +0000 Subject: [PATCH] Don't apply the changes from an automation macro if an error occured Originally committed to SVN as r5774. --- aegisub/src/auto4_lua.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/aegisub/src/auto4_lua.cpp b/aegisub/src/auto4_lua.cpp index f82af64aa..9a0fe3892 100644 --- a/aegisub/src/auto4_lua.cpp +++ b/aegisub/src/auto4_lua.cpp @@ -497,7 +497,7 @@ namespace Automation4 { } } - static void lua_threaded_call(ProgressSink *ps, lua_State *L, int nargs, int nresults, bool can_open_config) + static void lua_threaded_call(ProgressSink *ps, lua_State *L, int nargs, int nresults, bool can_open_config, bool *failed) { LuaProgressSink lps(L, ps, can_open_config); @@ -506,17 +506,19 @@ namespace Automation4 { ps->Log("\n\nLua reported a runtime error:\n"); ps->Log(lua_tostring(L, -1)); lua_pop(L, 1); + *failed = true; } lua_gc(L, LUA_GCCOLLECT, 0); } - - // LuaThreadedCall void LuaThreadedCall(lua_State *L, int nargs, int nresults, wxString const& title, wxWindow *parent, bool can_open_config) { + bool failed = false; BackgroundScriptRunner bsr(parent, title); - bsr.Run(bind(lua_threaded_call, std::tr1::placeholders::_1, L, nargs, nresults, can_open_config)); + bsr.Run(bind(lua_threaded_call, std::tr1::placeholders::_1, L, nargs, nresults, can_open_config, &failed)); + if (failed) + throw agi::UserCancelException("Script threw an error"); } // LuaFeature