Added LuaInstance::CheckBoolean
Former-commit-id: 2468e458001641cfc6741e271f848afeaad4ea2a
This commit is contained in:
parent
afdb4d2a99
commit
8228d1799c
|
|
@ -30,6 +30,8 @@ class NAZARA_API NzLuaInstance : NzNonCopyable
|
||||||
~NzLuaInstance();
|
~NzLuaInstance();
|
||||||
|
|
||||||
void CheckAny(int index) const;
|
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) const;
|
||||||
int CheckInteger(int index, int defValue) const;
|
int CheckInteger(int index, int defValue) const;
|
||||||
double CheckNumber(int index) const;
|
double CheckNumber(int index) const;
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,26 @@ void NzLuaInstance::CheckAny(int index) const
|
||||||
luaL_checkany(m_state, index);
|
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
|
int NzLuaInstance::CheckInteger(int index) const
|
||||||
{
|
{
|
||||||
return luaL_checkint(m_state, index);
|
return luaL_checkint(m_state, index);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue