Skip to content

Commit

Permalink
feat: add ThrowLuaError in LuaVM
Browse files Browse the repository at this point in the history
Allow to throw an error in LuaVM using 'luaL_error'.
  • Loading branch information
poirierlouis committed Jan 20, 2024
1 parent 103c8db commit 0e8c701
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/scripting/LuaVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ bool LuaVM::ExecuteLua(const std::string& acCommand) const
return m_scripting.ExecuteLua(acCommand);
}

int LuaVM::ThrowLuaError(const std::string& acMessage) const
{
lua_State* state = m_scripting.GetLockedState().Get().lua_state();

return luaL_error(state, "%s", acMessage.c_str());
}

void LuaVM::Update(float aDeltaTime)
{
if (!m_initialized)
Expand Down
1 change: 1 addition & 0 deletions src/scripting/LuaVM.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct LuaVM
[[nodiscard]] const TiltedPhoques::Map<std::string, std::reference_wrapper<const TiltedPhoques::Vector<VKBind>>>& GetAllBinds() const;

bool ExecuteLua(const std::string& acCommand) const;
int ThrowLuaError(const std::string& acMessage) const;

void Update(float aDeltaTime);
void Draw() const;
Expand Down

0 comments on commit 0e8c701

Please sign in to comment.