diff options
Diffstat (limited to 'indra/llcommon')
-rw-r--r-- | indra/llcommon/lua_function.cpp | 3 | ||||
-rw-r--r-- | indra/llcommon/lua_function.h | 37 |
2 files changed, 39 insertions, 1 deletions
diff --git a/indra/llcommon/lua_function.cpp b/indra/llcommon/lua_function.cpp index a5f1f582d9..78abb8ba7e 100644 --- a/indra/llcommon/lua_function.cpp +++ b/indra/llcommon/lua_function.cpp @@ -789,7 +789,8 @@ std::ostream& operator<<(std::ostream& out, const lua_what& self) *****************************************************************************/ std::ostream& operator<<(std::ostream& out, const lua_stack& self) { - const char* sep = "stack: ["; + out << "stack: ["; + const char* sep = ""; for (int index = 1; index <= lua_gettop(self.L); ++index) { out << sep << lua_what(self.L, index); diff --git a/indra/llcommon/lua_function.h b/indra/llcommon/lua_function.h index 08a2353d29..07848e38af 100644 --- a/indra/llcommon/lua_function.h +++ b/indra/llcommon/lua_function.h @@ -17,6 +17,7 @@ #include "luau/luaconf.h" #include "luau/lualib.h" #include "stringize.h" +#include <exception> // std::uncaught_exceptions() #include <memory> // std::shared_ptr #include <utility> // std::pair @@ -216,4 +217,40 @@ private: lua_State* L; }; +// adapted from indra/test/debug.h +// can't generalize Debug::operator() target because it's a variadic template +class LuaLog +{ +public: + template <typename... ARGS> + LuaLog(lua_State* L, ARGS&&... args): + L(L), + mBlock(stringize(std::forward<ARGS>(args)...)) + { + (*this)("entry ", lua_stack(L)); + } + + // non-copyable + LuaLog(const LuaLog&) = delete; + LuaLog& operator=(const LuaLog&) = delete; + + ~LuaLog() + { + auto exceptional{ std::uncaught_exceptions()? "exceptional " : "" }; + (*this)(exceptional, "exit ", lua_stack(L)); + } + + template <typename... ARGS> + void operator()(ARGS&&... args) + { + LL_INFOS("Lua") << mBlock << ' '; + stream_to(LL_CONT, std::forward<ARGS>(args)...); + LL_ENDL; + } + +private: + lua_State* L; + const std::string mBlock; +}; + #endif /* ! defined(LL_LUA_FUNCTION_H) */ |