commit 87b0e3d477a8d4af32a2a200a2d8cb2c3aaa05a1
parent cb50fcf42d9ab2d04f6f28a30a0ca5cc6e58054c
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Fri, 8 Feb 2002 20:39:14 -0200
no more `lua_istrue' function
Diffstat:
4 files changed, 10 insertions(+), 16 deletions(-)
diff --git a/lapi.c b/lapi.c
@@ -185,12 +185,6 @@ 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);
@@ -231,10 +225,7 @@ 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;
+ return (o != NULL) && !l_isfalse(o);
}
diff --git a/lbaselib.c b/lbaselib.c
@@ -264,7 +264,7 @@ static int luaB_loadfile (lua_State *L) {
static int luaB_assert (lua_State *L) {
luaL_check_any(L, 1);
- if (!lua_istrue(L, 1))
+ if (!lua_toboolean(L, 1))
luaL_verror(L, "assertion failed! %.90s", luaL_opt_string(L, 2, ""));
lua_settop(L, 1);
return 1;
@@ -569,7 +569,7 @@ static int sort_comp (lua_State *L, int a, int b) {
lua_pushvalue(L, a-1); /* -1 to compensate function */
lua_pushvalue(L, b-2); /* -2 to compensate function and `a' */
lua_rawcall(L, 2, 1);
- res = lua_istrue(L, -1);
+ res = lua_toboolean(L, -1);
lua_pop(L, 1);
return res;
}
diff --git a/lstrlib.c b/lstrlib.c
@@ -154,12 +154,12 @@ static int str_char (lua_State *L) {
typedef struct MatchState {
const char *src_init; /* init of source string */
const char *src_end; /* end (`\0') of source string */
+ lua_State *L;
int level; /* total number of captures (finished or unfinished) */
struct {
const char *init;
sint32 len;
} capture[MAX_CAPTURES];
- lua_State *L;
} MatchState;
@@ -449,7 +449,7 @@ static int str_find (lua_State *L) {
const char *p = luaL_check_lstr(L, 2, &l2);
sint32 init = posrelat(luaL_opt_long(L, 3, 1), l1) - 1;
luaL_arg_check(L, 0 <= init && (size_t)(init) <= l1, 3, "out of range");
- if (lua_istrue(L, 4) || /* explicit request? */
+ if (lua_toboolean(L, 4) || /* explicit request? */
strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */
/* do a plain search */
const char *s2 = lmemfind(s+init, l1-init, p, l2);
diff --git a/lua.h b/lua.h
@@ -117,7 +117,6 @@ LUA_API int lua_stackspace (lua_State *L);
*/
LUA_API int lua_isnumber (lua_State *L, int index);
-LUA_API int lua_istrue (lua_State *L, int index);
LUA_API int lua_isstring (lua_State *L, int index);
LUA_API int lua_iscfunction (lua_State *L, int index);
LUA_API int lua_type (lua_State *L, int index);
@@ -217,7 +216,11 @@ LUA_API void lua_newuserdatabox (lua_State *L, void *u);
#define lua_pop(L,n) lua_settop(L, -(n)-1)
-#define lua_register(L,n,f) (lua_pushcfunction(L, f), lua_setglobal(L, n))
+#define lua_register(L,n,f) \
+ (lua_pushstring(L, n), \
+ lua_pushcfunction(L, f), \
+ lua_settable(L, LUA_GLOBALSINDEX))
+
#define lua_pushcfunction(L,f) lua_pushcclosure(L, f, 0)
#define lua_isfunction(L,n) (lua_type(L,n) == LUA_TFUNCTION)