new type `boolean'

This commit is contained in:
Roberto Ierusalimschy
2001-12-11 20:48:44 -02:00
parent ed9be5e1f0
commit 9aff171f3b
18 changed files with 166 additions and 121 deletions

23
lapi.c
View File

@@ -174,6 +174,12 @@ LUA_API int lua_isnumber (lua_State *L, int index) {
}
LUA_API int lua_istrue (lua_State *L, int index) {
TObject *o = luaA_indexAcceptable(L, index);
return (o != NULL && !l_isfalse(o));
}
LUA_API int lua_isstring (lua_State *L, int index) {
int t = lua_type(L, index);
return (t == LUA_TSTRING || t == LUA_TNUMBER);
@@ -213,6 +219,15 @@ LUA_API lua_Number lua_tonumber (lua_State *L, int index) {
}
LUA_API int lua_toboolean (lua_State *L, int index) {
const TObject *o = luaA_indexAcceptable(L, index);
if (o != NULL && (ttype(o) == LUA_TBOOLEAN))
return bvalue(o);
else
return -1;
}
LUA_API const char *lua_tostring (lua_State *L, int index) {
StkId o = luaA_indexAcceptable(L, index);
if (o == NULL)
@@ -323,6 +338,14 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
}
LUA_API void lua_pushboolean (lua_State *L, int b) {
lua_lock(L);
setbvalue(L->top, b);
api_incr_top(L);
lua_unlock(L);
}
/*
** get functions (Lua -> stack)