From 9aff171f3bf0125314a29a5ca952470b2d83708e Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy <roberto@inf.puc-rio.br> Date: Tue, 11 Dec 2001 20:48:44 -0200 Subject: new type `boolean' --- lapi.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lapi.c') diff --git a/lapi.c b/lapi.c index af151636..50578513 100644 --- a/lapi.c +++ b/lapi.c @@ -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) -- cgit v1.2.3-55-g6feb