From 91a87084ffb0001a32c7a7a23b0e8cd464354005 Mon Sep 17 00:00:00 2001 From: mihacooper Date: Tue, 24 Jan 2017 19:27:33 +0300 Subject: [PATCH] fix review comments --- src/stored-object.cpp | 6 +++--- src/threading.cpp | 2 +- src/utils.h | 28 +++++++++++++++++----------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/stored-object.cpp b/src/stored-object.cpp index 93441d7..a549d06 100644 --- a/src/stored-object.cpp +++ b/src/stored-object.cpp @@ -68,8 +68,8 @@ public: ASSERT(loader.valid()); sol::function result = loader(function_); - ASSERT(result.valid()) << "Unable to restore function!" << std::endl - << "Content:" << std::endl << function_ << std::endl; + ASSERT(result.valid()) << "Unable to restore function!\n" + << "Content:\n" << function_; return sol::make_object(state, result); } @@ -141,7 +141,7 @@ std::unique_ptr fromSolObject(const SolObject& luaObject) { return std::make_unique>(sol::type::userdata, table); } default: - ERROR << "Unable to store object of that type: " << (int)luaObject.get_type() << std::endl; + ERROR << "Unable to store object of that type: " << (int)luaObject.get_type() << "\n"; } return nullptr; } diff --git a/src/threading.cpp b/src/threading.cpp index 9e7af23..d54d2a1 100644 --- a/src/threading.cpp +++ b/src/threading.cpp @@ -49,7 +49,7 @@ void LuaThread::detach() noexcept { } void LuaThread::work() noexcept { - ASSERT(p_state_.get() && p_arguments_.get()) << "invalid thread Lua state" << std::endl; + ASSERT(p_state_.get() && p_arguments_.get()) << "invalid thread Lua state\n"; std::string func_owner = std::move(str_function_); std::shared_ptr state_owner = p_state_; diff --git a/src/utils.h b/src/utils.h index d9b435a..07cd984 100644 --- a/src/utils.h +++ b/src/utils.h @@ -5,25 +5,31 @@ #include +namespace effil { namespace utils { -class ExceptionThrower -{ +class Exception : public sol::error { public: - void operator =(const std::ostream& os) - { - throw sol::error(static_cast(os).str()); + Exception() noexcept : sol::error("") {} + + template + Exception& operator<<(const T& value) { + std::stringstream ss; + ss << value; + message_ += ss.str(); + return *this; } - operator bool() - { - return true; + virtual const char* what() const noexcept override { + return message_.c_str(); } +private: + std::string message_; }; -} +} // utils +} // effil -#define ERROR if (auto thr = utils::ExceptionThrower()) thr = std::stringstream() << __FILE__ << ":" << __LINE__ << std::endl +#define ERROR throw effil::utils::Exception() << __FILE__ << ":" << __LINE__ #define ASSERT(cond) if (!(cond)) ERROR << "In condition '" << #cond << "': " -