mirror of
https://github.com/luau-lang/luau.git
synced 2024-11-15 14:25:44 +08:00
Add luaL_checkboolean and luaL_optboolean (#221)
Co-authored-by: Arseny Kapoulkine <arseny.kapoulkine@gmail.com>
This commit is contained in:
parent
cecd50fb06
commit
a5bb3ee2af
@ -25,6 +25,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 int luaL_checkboolean(lua_State* L, int narg);
|
||||
LUALIB_API int luaL_optboolean(lua_State* L, int narg, int def);
|
||||
|
||||
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,22 @@ LUALIB_API double luaL_optnumber(lua_State* L, int narg, double def)
|
||||
return luaL_opt(L, luaL_checknumber, narg, def);
|
||||
}
|
||||
|
||||
LUALIB_API int 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.
|
||||
if (!lua_isboolean(L, narg))
|
||||
tag_error(L, narg, LUA_TBOOLEAN);
|
||||
return lua_toboolean(L, narg);
|
||||
}
|
||||
|
||||
LUALIB_API int luaL_optboolean(lua_State* L, int narg, int def)
|
||||
{
|
||||
return luaL_opt(L, luaL_checkboolean, narg, def);
|
||||
}
|
||||
|
||||
LUALIB_API int luaL_checkinteger(lua_State* L, int narg)
|
||||
{
|
||||
int isnum;
|
||||
|
@ -524,7 +524,7 @@ TEST_CASE("Debugger")
|
||||
L,
|
||||
[](lua_State* L) -> int {
|
||||
int line = luaL_checkinteger(L, 1);
|
||||
bool enabled = lua_isboolean(L, 2) ? lua_toboolean(L, 2) : true;
|
||||
bool enabled = luaL_optboolean(L, 2, true);
|
||||
|
||||
lua_Debug ar = {};
|
||||
lua_getinfo(L, 1, "f", &ar);
|
||||
|
Loading…
Reference in New Issue
Block a user