aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lapi.c11
-rw-r--r--lbaselib.c4
-rw-r--r--lstrlib.c4
-rw-r--r--lua.h7
4 files changed, 10 insertions, 16 deletions
diff --git a/lapi.c b/lapi.c
index d39afe86..bed22426 100644
--- a/lapi.c
+++ b/lapi.c
@@ -185,12 +185,6 @@ LUA_API int lua_isnumber (lua_State *L, int index) {
185} 185}
186 186
187 187
188LUA_API int lua_istrue (lua_State *L, int index) {
189 TObject *o = luaA_indexAcceptable(L, index);
190 return (o != NULL && !l_isfalse(o));
191}
192
193
194LUA_API int lua_isstring (lua_State *L, int index) { 188LUA_API int lua_isstring (lua_State *L, int index) {
195 int t = lua_type(L, index); 189 int t = lua_type(L, index);
196 return (t == LUA_TSTRING || t == LUA_TNUMBER); 190 return (t == LUA_TSTRING || t == LUA_TNUMBER);
@@ -231,10 +225,7 @@ LUA_API lua_Number lua_tonumber (lua_State *L, int index) {
231 225
232LUA_API int lua_toboolean (lua_State *L, int index) { 226LUA_API int lua_toboolean (lua_State *L, int index) {
233 const TObject *o = luaA_indexAcceptable(L, index); 227 const TObject *o = luaA_indexAcceptable(L, index);
234 if (o != NULL && (ttype(o) == LUA_TBOOLEAN)) 228 return (o != NULL) && !l_isfalse(o);
235 return bvalue(o);
236 else
237 return -1;
238} 229}
239 230
240 231
diff --git a/lbaselib.c b/lbaselib.c
index f1a7b5ab..b561a52c 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -264,7 +264,7 @@ static int luaB_loadfile (lua_State *L) {
264 264
265static int luaB_assert (lua_State *L) { 265static int luaB_assert (lua_State *L) {
266 luaL_check_any(L, 1); 266 luaL_check_any(L, 1);
267 if (!lua_istrue(L, 1)) 267 if (!lua_toboolean(L, 1))
268 luaL_verror(L, "assertion failed! %.90s", luaL_opt_string(L, 2, "")); 268 luaL_verror(L, "assertion failed! %.90s", luaL_opt_string(L, 2, ""));
269 lua_settop(L, 1); 269 lua_settop(L, 1);
270 return 1; 270 return 1;
@@ -569,7 +569,7 @@ static int sort_comp (lua_State *L, int a, int b) {
569 lua_pushvalue(L, a-1); /* -1 to compensate function */ 569 lua_pushvalue(L, a-1); /* -1 to compensate function */
570 lua_pushvalue(L, b-2); /* -2 to compensate function and `a' */ 570 lua_pushvalue(L, b-2); /* -2 to compensate function and `a' */
571 lua_rawcall(L, 2, 1); 571 lua_rawcall(L, 2, 1);
572 res = lua_istrue(L, -1); 572 res = lua_toboolean(L, -1);
573 lua_pop(L, 1); 573 lua_pop(L, 1);
574 return res; 574 return res;
575 } 575 }
diff --git a/lstrlib.c b/lstrlib.c
index f2582cfe..d1f5dcfb 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -154,12 +154,12 @@ static int str_char (lua_State *L) {
154typedef struct MatchState { 154typedef struct MatchState {
155 const char *src_init; /* init of source string */ 155 const char *src_init; /* init of source string */
156 const char *src_end; /* end (`\0') of source string */ 156 const char *src_end; /* end (`\0') of source string */
157 lua_State *L;
157 int level; /* total number of captures (finished or unfinished) */ 158 int level; /* total number of captures (finished or unfinished) */
158 struct { 159 struct {
159 const char *init; 160 const char *init;
160 sint32 len; 161 sint32 len;
161 } capture[MAX_CAPTURES]; 162 } capture[MAX_CAPTURES];
162 lua_State *L;
163} MatchState; 163} MatchState;
164 164
165 165
@@ -449,7 +449,7 @@ static int str_find (lua_State *L) {
449 const char *p = luaL_check_lstr(L, 2, &l2); 449 const char *p = luaL_check_lstr(L, 2, &l2);
450 sint32 init = posrelat(luaL_opt_long(L, 3, 1), l1) - 1; 450 sint32 init = posrelat(luaL_opt_long(L, 3, 1), l1) - 1;
451 luaL_arg_check(L, 0 <= init && (size_t)(init) <= l1, 3, "out of range"); 451 luaL_arg_check(L, 0 <= init && (size_t)(init) <= l1, 3, "out of range");
452 if (lua_istrue(L, 4) || /* explicit request? */ 452 if (lua_toboolean(L, 4) || /* explicit request? */
453 strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */ 453 strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */
454 /* do a plain search */ 454 /* do a plain search */
455 const char *s2 = lmemfind(s+init, l1-init, p, l2); 455 const char *s2 = lmemfind(s+init, l1-init, p, l2);
diff --git a/lua.h b/lua.h
index ac0a2f96..a3fb1df5 100644
--- a/lua.h
+++ b/lua.h
@@ -117,7 +117,6 @@ LUA_API int lua_stackspace (lua_State *L);
117*/ 117*/
118 118
119LUA_API int lua_isnumber (lua_State *L, int index); 119LUA_API int lua_isnumber (lua_State *L, int index);
120LUA_API int lua_istrue (lua_State *L, int index);
121LUA_API int lua_isstring (lua_State *L, int index); 120LUA_API int lua_isstring (lua_State *L, int index);
122LUA_API int lua_iscfunction (lua_State *L, int index); 121LUA_API int lua_iscfunction (lua_State *L, int index);
123LUA_API int lua_type (lua_State *L, int index); 122LUA_API int lua_type (lua_State *L, int index);
@@ -217,7 +216,11 @@ LUA_API void lua_newuserdatabox (lua_State *L, void *u);
217 216
218#define lua_pop(L,n) lua_settop(L, -(n)-1) 217#define lua_pop(L,n) lua_settop(L, -(n)-1)
219 218
220#define lua_register(L,n,f) (lua_pushcfunction(L, f), lua_setglobal(L, n)) 219#define lua_register(L,n,f) \
220 (lua_pushstring(L, n), \
221 lua_pushcfunction(L, f), \
222 lua_settable(L, LUA_GLOBALSINDEX))
223
221#define lua_pushcfunction(L,f) lua_pushcclosure(L, f, 0) 224#define lua_pushcfunction(L,f) lua_pushcclosure(L, f, 0)
222 225
223#define lua_isfunction(L,n) (lua_type(L,n) == LUA_TFUNCTION) 226#define lua_isfunction(L,n) (lua_type(L,n) == LUA_TFUNCTION)