[lua] Add several boolean functions

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-06-12 13:27:45 +02:00
parent 0fd1779b3a
commit 575fe8f9df
1 changed files with 23 additions and 8 deletions

31
lua.h
View File

@ -92,6 +92,20 @@ luaA_checkudata(lua_State *L, int ud, const char *tname)
return NULL; return NULL;
} }
static inline bool
luaA_checkboolean(lua_State *L, int n)
{
if(!lua_isboolean(L, n))
luaL_typerror(L, n, "boolean");
return lua_toboolean(L, n);
}
static inline bool
luaA_optboolean(lua_State *L, int idx, bool def)
{
return luaL_opt(L, luaA_checkboolean, idx, def);
}
static inline lua_Number static inline lua_Number
luaA_getopt_number(lua_State *L, int idx, const char *name, lua_Number def) luaA_getopt_number(lua_State *L, int idx, const char *name, lua_Number def)
{ {
@ -110,6 +124,15 @@ luaA_getopt_string(lua_State *L, int idx, const char *name, const char *def)
return luaL_optstring(L, -1, def); return luaL_optstring(L, -1, def);
} }
static inline bool
luaA_getopt_boolean(lua_State *L, int idx, const char *name, bool def)
{
/* assume that table is first on stack */
lua_getfield(L, idx, name);
/* return luaL_optnumber result */
return luaA_optboolean(L, -1, def);
}
static inline int static inline int
luaA_settype(lua_State *L, const char *type) luaA_settype(lua_State *L, const char *type)
{ {
@ -125,14 +148,6 @@ luaA_name_init(lua_State *L)
return a_strdup(luaL_checkstring(L, -1)); return a_strdup(luaL_checkstring(L, -1));
} }
static inline bool
luaA_checkboolean(lua_State *L, int n)
{
if(!lua_isboolean(L, n))
luaL_typerror(L, n, "boolean");
return lua_toboolean(L, n);
}
void luaA_init(void); void luaA_init(void);
bool luaA_parserc(const char *); bool luaA_parserc(const char *);
void luaA_docmd(char *); void luaA_docmd(char *);