diff options
Diffstat (limited to 'lbaselib.c')
-rw-r--r-- | lbaselib.c | 59 |
1 files changed, 30 insertions, 29 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.43 2001/10/11 21:41:21 roberto Exp $ | 2 | ** $Id: lbaselib.c,v 1.44 2001/10/17 21:12:57 roberto Exp $ |
3 | ** Basic library | 3 | ** Basic library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -42,7 +42,7 @@ static int luaB__ALERT (lua_State *L) { | |||
42 | ** The library `liolib' redefines _ERRORMESSAGE for better error information. | 42 | ** The library `liolib' redefines _ERRORMESSAGE for better error information. |
43 | */ | 43 | */ |
44 | static int luaB__ERRORMESSAGE (lua_State *L) { | 44 | static int luaB__ERRORMESSAGE (lua_State *L) { |
45 | luaL_checktype(L, 1, LUA_TSTRING); | 45 | luaL_check_rawtype(L, 1, LUA_TSTRING); |
46 | lua_getglobal(L, l_s(LUA_ALERT)); | 46 | lua_getglobal(L, l_s(LUA_ALERT)); |
47 | if (lua_isfunction(L, -1)) { /* avoid error loop if _ALERT is not defined */ | 47 | if (lua_isfunction(L, -1)) { /* avoid error loop if _ALERT is not defined */ |
48 | lua_Debug ar; | 48 | lua_Debug ar; |
@@ -95,7 +95,7 @@ static int luaB_print (lua_State *L) { | |||
95 | static int luaB_tonumber (lua_State *L) { | 95 | static int luaB_tonumber (lua_State *L) { |
96 | int base = luaL_opt_int(L, 2, 10); | 96 | int base = luaL_opt_int(L, 2, 10); |
97 | if (base == 10) { /* standard conversion */ | 97 | if (base == 10) { /* standard conversion */ |
98 | luaL_checkany(L, 1); | 98 | luaL_check_any(L, 1); |
99 | if (lua_isnumber(L, 1)) { | 99 | if (lua_isnumber(L, 1)) { |
100 | lua_pushnumber(L, lua_tonumber(L, 1)); | 100 | lua_pushnumber(L, lua_tonumber(L, 1)); |
101 | return 1; | 101 | return 1; |
@@ -126,7 +126,7 @@ static int luaB_error (lua_State *L) { | |||
126 | } | 126 | } |
127 | 127 | ||
128 | static int luaB_setglobal (lua_State *L) { | 128 | static int luaB_setglobal (lua_State *L) { |
129 | luaL_checkany(L, 2); | 129 | luaL_check_any(L, 2); |
130 | lua_setglobal(L, luaL_check_string(L, 1)); | 130 | lua_setglobal(L, luaL_check_string(L, 1)); |
131 | return 0; | 131 | return 0; |
132 | } | 132 | } |
@@ -157,13 +157,13 @@ static int gettag (lua_State *L, int narg) { | |||
157 | 157 | ||
158 | 158 | ||
159 | static int luaB_tag (lua_State *L) { | 159 | static int luaB_tag (lua_State *L) { |
160 | luaL_checkany(L, 1); | 160 | luaL_check_any(L, 1); |
161 | lua_pushnumber(L, lua_tag(L, 1)); | 161 | lua_pushnumber(L, lua_tag(L, 1)); |
162 | return 1; | 162 | return 1; |
163 | } | 163 | } |
164 | 164 | ||
165 | static int luaB_settype (lua_State *L) { | 165 | static int luaB_settype (lua_State *L) { |
166 | luaL_checktype(L, 1, LUA_TTABLE); | 166 | luaL_check_rawtype(L, 1, LUA_TTABLE); |
167 | lua_pushvalue(L, 1); /* push table */ | 167 | lua_pushvalue(L, 1); /* push table */ |
168 | lua_settag(L, gettag(L, 2)); | 168 | lua_settag(L, gettag(L, 2)); |
169 | return 1; /* return table */ | 169 | return 1; /* return table */ |
@@ -171,7 +171,7 @@ static int luaB_settype (lua_State *L) { | |||
171 | 171 | ||
172 | static int luaB_weakmode (lua_State *L) { | 172 | static int luaB_weakmode (lua_State *L) { |
173 | const l_char *mode = luaL_check_string(L, 2); | 173 | const l_char *mode = luaL_check_string(L, 2); |
174 | luaL_checktype(L, 1, LUA_TTABLE); | 174 | luaL_check_rawtype(L, 1, LUA_TTABLE); |
175 | if (*mode == l_c('?')) { | 175 | if (*mode == l_c('?')) { |
176 | l_char buff[3]; | 176 | l_char buff[3]; |
177 | l_char *s = buff; | 177 | l_char *s = buff; |
@@ -202,7 +202,7 @@ static int luaB_newtype (lua_State *L) { | |||
202 | static int luaB_globals (lua_State *L) { | 202 | static int luaB_globals (lua_State *L) { |
203 | lua_getglobals(L); /* value to be returned */ | 203 | lua_getglobals(L); /* value to be returned */ |
204 | if (!lua_isnull(L, 1)) { | 204 | if (!lua_isnull(L, 1)) { |
205 | luaL_checktype(L, 1, LUA_TTABLE); | 205 | luaL_check_rawtype(L, 1, LUA_TTABLE); |
206 | lua_pushvalue(L, 1); /* new table of globals */ | 206 | lua_pushvalue(L, 1); /* new table of globals */ |
207 | lua_setglobals(L); | 207 | lua_setglobals(L); |
208 | } | 208 | } |
@@ -210,16 +210,16 @@ static int luaB_globals (lua_State *L) { | |||
210 | } | 210 | } |
211 | 211 | ||
212 | static int luaB_rawget (lua_State *L) { | 212 | static int luaB_rawget (lua_State *L) { |
213 | luaL_checktype(L, 1, LUA_TTABLE); | 213 | luaL_check_rawtype(L, 1, LUA_TTABLE); |
214 | luaL_checkany(L, 2); | 214 | luaL_check_any(L, 2); |
215 | lua_rawget(L, -2); | 215 | lua_rawget(L, -2); |
216 | return 1; | 216 | return 1; |
217 | } | 217 | } |
218 | 218 | ||
219 | static int luaB_rawset (lua_State *L) { | 219 | static int luaB_rawset (lua_State *L) { |
220 | luaL_checktype(L, 1, LUA_TTABLE); | 220 | luaL_check_rawtype(L, 1, LUA_TTABLE); |
221 | luaL_checkany(L, 2); | 221 | luaL_check_any(L, 2); |
222 | luaL_checkany(L, 3); | 222 | luaL_check_any(L, 3); |
223 | lua_rawset(L, -3); | 223 | lua_rawset(L, -3); |
224 | return 1; | 224 | return 1; |
225 | } | 225 | } |
@@ -262,21 +262,21 @@ static int luaB_collectgarbage (lua_State *L) { | |||
262 | 262 | ||
263 | 263 | ||
264 | static int luaB_type (lua_State *L) { | 264 | static int luaB_type (lua_State *L) { |
265 | luaL_checkany(L, 1); | 265 | luaL_check_any(L, 1); |
266 | lua_pushstring(L, lua_type(L, 1)); | 266 | lua_pushstring(L, lua_type(L, 1)); |
267 | return 1; | 267 | return 1; |
268 | } | 268 | } |
269 | 269 | ||
270 | 270 | ||
271 | static int luaB_rawtype (lua_State *L) { | 271 | static int luaB_rawtype (lua_State *L) { |
272 | luaL_checkany(L, 1); | 272 | luaL_check_any(L, 1); |
273 | lua_pushstring(L, lua_tag2name(L, lua_rawtag(L, 1))); | 273 | lua_pushstring(L, lua_tag2name(L, lua_rawtag(L, 1))); |
274 | return 1; | 274 | return 1; |
275 | } | 275 | } |
276 | 276 | ||
277 | 277 | ||
278 | static int luaB_next (lua_State *L) { | 278 | static int luaB_next (lua_State *L) { |
279 | luaL_checktype(L, 1, LUA_TTABLE); | 279 | luaL_check_rawtype(L, 1, LUA_TTABLE); |
280 | lua_settop(L, 2); /* create a 2nd argument if there isn't one */ | 280 | lua_settop(L, 2); /* create a 2nd argument if there isn't one */ |
281 | if (lua_next(L, 1)) | 281 | if (lua_next(L, 1)) |
282 | return 2; | 282 | return 2; |
@@ -394,9 +394,9 @@ static int luaB_require (lua_State *L) { | |||
394 | 394 | ||
395 | static int aux_unpack (lua_State *L, int arg) { | 395 | static int aux_unpack (lua_State *L, int arg) { |
396 | int n, i; | 396 | int n, i; |
397 | luaL_checktype(L, arg, LUA_TTABLE); | 397 | luaL_check_rawtype(L, arg, LUA_TTABLE); |
398 | n = lua_getn(L, arg); | 398 | n = lua_getn(L, arg); |
399 | luaL_checkstack(L, n, l_s("table too big to unpack")); | 399 | luaL_check_stack(L, n, l_s("table too big to unpack")); |
400 | for (i=1; i<=n; i++) /* push arg[1...n] */ | 400 | for (i=1; i<=n; i++) /* push arg[1...n] */ |
401 | lua_rawgeti(L, arg, i); | 401 | lua_rawgeti(L, arg, i); |
402 | return n; | 402 | return n; |
@@ -479,8 +479,8 @@ static int luaB_tostring (lua_State *L) { | |||
479 | 479 | ||
480 | static int luaB_foreachi (lua_State *L) { | 480 | static int luaB_foreachi (lua_State *L) { |
481 | int n, i; | 481 | int n, i; |
482 | luaL_checktype(L, 1, LUA_TTABLE); | 482 | luaL_check_rawtype(L, 1, LUA_TTABLE); |
483 | luaL_checktype(L, 2, LUA_TFUNCTION); | 483 | luaL_check_rawtype(L, 2, LUA_TFUNCTION); |
484 | n = lua_getn(L, 1); | 484 | n = lua_getn(L, 1); |
485 | for (i=1; i<=n; i++) { | 485 | for (i=1; i<=n; i++) { |
486 | lua_pushvalue(L, 2); /* function */ | 486 | lua_pushvalue(L, 2); /* function */ |
@@ -496,8 +496,8 @@ static int luaB_foreachi (lua_State *L) { | |||
496 | 496 | ||
497 | 497 | ||
498 | static int luaB_foreach (lua_State *L) { | 498 | static int luaB_foreach (lua_State *L) { |
499 | luaL_checktype(L, 1, LUA_TTABLE); | 499 | luaL_check_rawtype(L, 1, LUA_TTABLE); |
500 | luaL_checktype(L, 2, LUA_TFUNCTION); | 500 | luaL_check_rawtype(L, 2, LUA_TFUNCTION); |
501 | lua_pushnil(L); /* first index */ | 501 | lua_pushnil(L); /* first index */ |
502 | for (;;) { | 502 | for (;;) { |
503 | if (lua_next(L, 1) == 0) | 503 | if (lua_next(L, 1) == 0) |
@@ -514,16 +514,17 @@ static int luaB_foreach (lua_State *L) { | |||
514 | 514 | ||
515 | 515 | ||
516 | static int luaB_assert (lua_State *L) { | 516 | static int luaB_assert (lua_State *L) { |
517 | luaL_checkany(L, 1); | 517 | luaL_check_any(L, 1); |
518 | if (lua_isnil(L, 1)) | 518 | if (lua_isnil(L, 1)) |
519 | luaL_verror(L, l_s("assertion failed! %.90s"), luaL_opt_string(L, 2, l_s(""))); | 519 | luaL_verror(L, l_s("assertion failed! %.90s"), |
520 | luaL_opt_string(L, 2, l_s(""))); | ||
520 | lua_settop(L, 1); | 521 | lua_settop(L, 1); |
521 | return 1; | 522 | return 1; |
522 | } | 523 | } |
523 | 524 | ||
524 | 525 | ||
525 | static int luaB_getn (lua_State *L) { | 526 | static int luaB_getn (lua_State *L) { |
526 | luaL_checktype(L, 1, LUA_TTABLE); | 527 | luaL_check_rawtype(L, 1, LUA_TTABLE); |
527 | lua_pushnumber(L, lua_getn(L, 1)); | 528 | lua_pushnumber(L, lua_getn(L, 1)); |
528 | return 1; | 529 | return 1; |
529 | } | 530 | } |
@@ -532,7 +533,7 @@ static int luaB_getn (lua_State *L) { | |||
532 | static int luaB_tinsert (lua_State *L) { | 533 | static int luaB_tinsert (lua_State *L) { |
533 | int v = lua_gettop(L); /* number of arguments */ | 534 | int v = lua_gettop(L); /* number of arguments */ |
534 | int n, pos; | 535 | int n, pos; |
535 | luaL_checktype(L, 1, LUA_TTABLE); | 536 | luaL_check_rawtype(L, 1, LUA_TTABLE); |
536 | n = lua_getn(L, 1); | 537 | n = lua_getn(L, 1); |
537 | if (v == 2) /* called with only 2 arguments */ | 538 | if (v == 2) /* called with only 2 arguments */ |
538 | pos = n+1; | 539 | pos = n+1; |
@@ -553,7 +554,7 @@ static int luaB_tinsert (lua_State *L) { | |||
553 | 554 | ||
554 | static int luaB_tremove (lua_State *L) { | 555 | static int luaB_tremove (lua_State *L) { |
555 | int pos, n; | 556 | int pos, n; |
556 | luaL_checktype(L, 1, LUA_TTABLE); | 557 | luaL_check_rawtype(L, 1, LUA_TTABLE); |
557 | n = lua_getn(L, 1); | 558 | n = lua_getn(L, 1); |
558 | pos = luaL_opt_int(L, 2, n); | 559 | pos = luaL_opt_int(L, 2, n); |
559 | if (n <= 0) return 0; /* table is `empty' */ | 560 | if (n <= 0) return 0; /* table is `empty' */ |
@@ -665,10 +666,10 @@ static void auxsort (lua_State *L, int l, int u) { | |||
665 | 666 | ||
666 | static int luaB_sort (lua_State *L) { | 667 | static int luaB_sort (lua_State *L) { |
667 | int n; | 668 | int n; |
668 | luaL_checktype(L, 1, LUA_TTABLE); | 669 | luaL_check_rawtype(L, 1, LUA_TTABLE); |
669 | n = lua_getn(L, 1); | 670 | n = lua_getn(L, 1); |
670 | if (!lua_isnull(L, 2)) /* is there a 2nd argument? */ | 671 | if (!lua_isnull(L, 2)) /* is there a 2nd argument? */ |
671 | luaL_checktype(L, 2, LUA_TFUNCTION); | 672 | luaL_check_rawtype(L, 2, LUA_TFUNCTION); |
672 | lua_settop(L, 2); /* make sure there is two arguments */ | 673 | lua_settop(L, 2); /* make sure there is two arguments */ |
673 | auxsort(L, 1, n); | 674 | auxsort(L, 1, n); |
674 | return 0; | 675 | return 0; |