From 64c7043123f3bf3d638f2a83d7e92bea915eddac Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Fri, 20 Jan 2012 21:33:20 +0000 Subject: [PATCH] Add aegisub.cancel(), which immediates ends macro execution without applying any of the changes that have been made Originally committed to SVN as r6325. --- aegisub/src/auto4_lua.cpp | 15 ++++++++++++--- aegisub/src/auto4_lua.h | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/aegisub/src/auto4_lua.cpp b/aegisub/src/auto4_lua.cpp index 8d1c6bd18..c3c941901 100644 --- a/aegisub/src/auto4_lua.cpp +++ b/aegisub/src/auto4_lua.cpp @@ -263,6 +263,7 @@ namespace Automation4 { set_field(L, "video_size", LuaVideoSize); set_field(L, "keyframes", LuaGetKeyframes); set_field(L, "decode_path", LuaDecodePath); + set_field(L, "cancel", LuaCancel); set_field(L, "lua_automation_version", 4); // store aegisub table to globals @@ -525,14 +526,22 @@ namespace Automation4 { return 1; } + int LuaScript::LuaCancel(lua_State *L) + { + lua_pushnil(L); + return lua_error(L); + } + 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); if (lua_pcall(L, nargs, nresults, 0)) { - // if the call failed, log the error here - ps->Log("\n\nLua reported a runtime error:\n"); - ps->Log(lua_tostring(L, -1)); + if (!lua_isnil(L, -1)) { + // if the call failed, log the error here + ps->Log("\n\nLua reported a runtime error:\n"); + ps->Log(lua_tostring(L, -1)); + } lua_pop(L, 1); *failed = true; } diff --git a/aegisub/src/auto4_lua.h b/aegisub/src/auto4_lua.h index fd419fced..95caab948 100644 --- a/aegisub/src/auto4_lua.h +++ b/aegisub/src/auto4_lua.h @@ -310,6 +310,7 @@ namespace Automation4 { static int LuaVideoSize(lua_State *L); static int LuaGetKeyframes(lua_State *L); static int LuaDecodePath(lua_State *L); + static int LuaCancel(lua_State *L); public: LuaScript(const wxString &filename);