Added LuaInstance::CheckBoolean

Former-commit-id: 2468e458001641cfc6741e271f848afeaad4ea2a
This commit is contained in:
Lynix 2014-03-20 20:33:26 +01:00
parent afdb4d2a99
commit 8228d1799c
2 changed files with 22 additions and 0 deletions

View File

@ -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;

View File

@ -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);