From f7a07b5a09ce81120584d024eb7af0758f10c7f5 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 21 Nov 2018 17:42:12 -0300 Subject: [PATCH] lua: Call Dialog button onclick callback with protected lua_pcall() --- src/app/script/dialog_class.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/app/script/dialog_class.cpp b/src/app/script/dialog_class.cpp index 2bdb60b0c..2500a8af7 100644 --- a/src/app/script/dialog_class.cpp +++ b/src/app/script/dialog_class.cpp @@ -293,8 +293,14 @@ int Dialog_button_base(lua_State* L, T** outputWidget = nullptr) lua_rawgeti(L, LUA_REGISTRYINDEX, ref); lua_geti(L, -1, n); - if (lua_isfunction(L, -1)) - lua_call(L, 0, 0); + if (lua_isfunction(L, -1)) { + if (lua_pcall(L, 0, 0, 0)) { + if (const char* s = lua_tostring(L, -1)) + App::instance() + ->scriptEngine() + ->consolePrint(s); + } + } else lua_pop(L, 1); lua_pop(L, 1); // Pop table from the registry