diff --git a/include/Nazara/Lua/LuaInstance.hpp b/include/Nazara/Lua/LuaInstance.hpp index f4eb7074d..573f135cf 100644 --- a/include/Nazara/Lua/LuaInstance.hpp +++ b/include/Nazara/Lua/LuaInstance.hpp @@ -30,6 +30,8 @@ class NAZARA_API NzLuaInstance : NzNonCopyable ~NzLuaInstance(); void CheckAny(int index) const; + bool CheckBoolean(int index) const; + bool CheckBoolean(int index, bool defValue) const; int CheckInteger(int index) const; int CheckInteger(int index, int defValue) const; double CheckNumber(int index) const; diff --git a/src/Nazara/Lua/LuaInstance.cpp b/src/Nazara/Lua/LuaInstance.cpp index 2903d7bb0..eb0aa9c7b 100644 --- a/src/Nazara/Lua/LuaInstance.cpp +++ b/src/Nazara/Lua/LuaInstance.cpp @@ -97,6 +97,26 @@ void NzLuaInstance::CheckAny(int index) const luaL_checkany(m_state, index); } +bool NzLuaInstance::CheckBoolean(int index) const +{ + if (lua_isnoneornil(m_state, index)) + { + const char* msg = lua_pushfstring(m_state, "%s expected, got %s", lua_typename(m_state, LUA_TBOOLEAN), luaL_typename(m_state, index)); + luaL_argerror(m_state, index, msg); // Lance une exception + return false; + } + + return lua_toboolean(m_state, index); +} + +bool NzLuaInstance::CheckBoolean(int index, bool defValue) const +{ + if (lua_isnoneornil(m_state, index)) + return defValue; + + return lua_toboolean(m_state, index); +} + int NzLuaInstance::CheckInteger(int index) const { return luaL_checkint(m_state, index);