diff --git a/apps/openmw/mwlua/actions.cpp b/apps/openmw/mwlua/actions.cpp index 7389363fe6..49bb5cfcb4 100644 --- a/apps/openmw/mwlua/actions.cpp +++ b/apps/openmw/mwlua/actions.cpp @@ -4,6 +4,7 @@ #include #include +#include #include "../mwworld/cellstore.hpp" #include "../mwworld/class.hpp" @@ -12,12 +13,12 @@ namespace MWLua { - -#ifdef NDEBUG - Action::Action(LuaUtil::LuaState* state) {} -#else - Action::Action(LuaUtil::LuaState* state) : mCallerTraceback(state->debugTraceback()) {} -#endif + Action::Action(LuaUtil::LuaState* state) + { + static const bool luaDebug = Settings::Manager::getBool("lua debug", "Lua"); + if (luaDebug) + mCallerTraceback = state->debugTraceback(); + } void Action::safeApply(WorldView& w) const { @@ -28,11 +29,11 @@ namespace MWLua catch (const std::exception& e) { Log(Debug::Error) << "Error in " << this->toString() << ": " << e.what(); -#ifdef NDEBUG - Log(Debug::Error) << "Traceback is available only in debug builds"; -#else - Log(Debug::Error) << "Caller " << mCallerTraceback; -#endif + + if (mCallerTraceback.empty()) + Log(Debug::Error) << "Set 'lua_debug=true' in settings.cfg to enable action tracebacks"; + else + Log(Debug::Error) << "Caller " << mCallerTraceback; } } diff --git a/apps/openmw/mwlua/actions.hpp b/apps/openmw/mwlua/actions.hpp index 3b71eef4a9..e88b39e83c 100644 --- a/apps/openmw/mwlua/actions.hpp +++ b/apps/openmw/mwlua/actions.hpp @@ -29,9 +29,7 @@ namespace MWLua virtual std::string toString() const = 0; private: -#ifndef NDEBUG std::string mCallerTraceback; -#endif }; class TeleportAction final : public Action diff --git a/docs/source/reference/modding/settings/lua.rst b/docs/source/reference/modding/settings/lua.rst index 4d1a3ca808..65faf884ae 100644 --- a/docs/source/reference/modding/settings/lua.rst +++ b/docs/source/reference/modding/settings/lua.rst @@ -1,6 +1,18 @@ Lua Settings ############ +lua debug +--------- + +:Type: boolean +:Range: True/False +:Default: False + +Enables debug tracebacks for Lua actions. +It adds significant performance overhead, don't enable if you don't need it. + +This setting can only be configured by editing the settings configuration file. + lua num threads --------------- diff --git a/files/settings-default.cfg b/files/settings-default.cfg index c0083e4238..9715e3793e 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -1106,6 +1106,9 @@ stomp intensity = 1 [Lua] +# Enable performance-heavy debug features +lua debug = false + # Set the maximum number of threads used for Lua scripts. # If zero, Lua scripts are processed in the main thread. lua num threads = 1