Skip to content

Commit

Permalink
construct a LuaException from a LuaResult
Browse files Browse the repository at this point in the history
  • Loading branch information
rpatters1 committed Mar 17, 2024
1 parent 56023d9 commit a8c40be
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Source/LuaBridge/detail/Invoke.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ class LuaResult

return LuaRef(m_L);
}

/**
* @brief Get the Lua state for this result.
*/
lua_State * state() const { return m_L; }

#if LUABRIDGE_HAS_EXCEPTIONS
/**
Expand Down Expand Up @@ -177,6 +182,13 @@ class LuaResult
std::variant<std::vector<LuaRef>, std::string> m_data;
};

inline LuaException::LuaException(const LuaResult& result)
: m_L(result.state())
, m_code(result.errorCode())
, m_what(result.errorMessage())
{
}

//=================================================================================================
/**
* @brief Safely call Lua code.
Expand Down
7 changes: 7 additions & 0 deletions Source/LuaBridge/detail/LuaException.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

namespace luabridge {

class LuaResult;

//================================================================================================
class LuaException : public std::exception
{
Expand All @@ -32,6 +34,11 @@ class LuaException : public std::exception
, m_code(code)
{
}

/**
* @brief Construct a LuaException from a LuaResult.
*/
LuaException(const LuaResult& result);

~LuaException() noexcept override
{
Expand Down

0 comments on commit a8c40be

Please sign in to comment.