mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Add luaL_checkboolean and luaL_optboolean
This commit is contained in:
parent
1bf0c75cfd
commit
5b6d6e6376
2 changed files with 20 additions and 0 deletions
|
@ -24,6 +24,9 @@ LUALIB_API const char* luaL_optlstring(lua_State* L, int numArg, const char* def
|
|||
LUALIB_API double luaL_checknumber(lua_State* L, int numArg);
|
||||
LUALIB_API double luaL_optnumber(lua_State* L, int nArg, double def);
|
||||
|
||||
LUALIB_API bool luaL_checkboolean(lua_State* L, int narg);
|
||||
LUALIB_API bool luaL_optboolean(lua_State* L, int narg, bool default);
|
||||
|
||||
LUALIB_API int luaL_checkinteger(lua_State* L, int numArg);
|
||||
LUALIB_API int luaL_optinteger(lua_State* L, int nArg, int def);
|
||||
LUALIB_API unsigned luaL_checkunsigned(lua_State* L, int numArg);
|
||||
|
|
|
@ -183,6 +183,23 @@ LUALIB_API double luaL_optnumber(lua_State* L, int narg, double def)
|
|||
return luaL_opt(L, luaL_checknumber, narg, def);
|
||||
}
|
||||
|
||||
LUALIB_API bool luaL_checkboolean(lua_State* L, int narg)
|
||||
{
|
||||
// This checks specifically for boolean values, ignoring
|
||||
// all other truthy/falsy values. If the desired result
|
||||
// is true if value is present then lua_toboolean should
|
||||
// directly be used instead.
|
||||
const auto val = lua_isboolean(L, narg);
|
||||
if (!val)
|
||||
tag_error(L, narg, LUA_TBOOLEAN);
|
||||
return lua_toboolean(L, narg);
|
||||
}
|
||||
|
||||
LUALIB_API bool luaL_optboolean(lua_State* L, int narg, bool def)
|
||||
{
|
||||
return luaL_opt(L, luaL_checkboolean, narg, def);
|
||||
}
|
||||
|
||||
LUALIB_API int luaL_checkinteger(lua_State* L, int narg)
|
||||
{
|
||||
int isnum;
|
||||
|
|
Loading…
Add table
Reference in a new issue