diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-04-04 17:49:32 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-04-04 17:49:32 -0300 |
commit | 9f734094f9bbb34216ef555edf08019d5feea13b (patch) | |
tree | 263a7f995b51b2e0f2e91e2e4125278c84e09b2d | |
parent | 4e7e9e8de5b9e50694e161653ef03b5c15a53054 (diff) | |
download | lua-9f734094f9bbb34216ef555edf08019d5feea13b.tar.gz lua-9f734094f9bbb34216ef555edf08019d5feea13b.tar.bz2 lua-9f734094f9bbb34216ef555edf08019d5feea13b.zip |
`nil' is optional for next and nextvar (and is not for tonumber & tag).
-rw-r--r-- | lbuiltin.c | 20 |
1 files changed, 9 insertions, 11 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbuiltin.c,v 1.100 2000/03/29 20:19:20 roberto Exp roberto $ | 2 | ** $Id: lbuiltin.c,v 1.101 2000/04/03 13:20:33 roberto Exp roberto $ |
3 | ** Built-in functions | 3 | ** Built-in functions |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -156,7 +156,7 @@ void luaB_print (lua_State *L) { | |||
156 | void luaB_tonumber (lua_State *L) { | 156 | void luaB_tonumber (lua_State *L) { |
157 | int base = luaL_opt_int(L, 2, 10); | 157 | int base = luaL_opt_int(L, 2, 10); |
158 | if (base == 10) { /* standard conversion */ | 158 | if (base == 10) { /* standard conversion */ |
159 | lua_Object o = lua_getparam(L, 1); | 159 | lua_Object o = luaL_nonnullarg(L, 1); |
160 | if (lua_isnumber(L, o)) lua_pushnumber(L, lua_getnumber(L, o)); | 160 | if (lua_isnumber(L, o)) lua_pushnumber(L, lua_getnumber(L, o)); |
161 | else lua_pushnil(L); /* not a number */ | 161 | else lua_pushnil(L); /* not a number */ |
162 | } | 162 | } |
@@ -201,7 +201,7 @@ void luaB_rawgetglobal (lua_State *L) { | |||
201 | } | 201 | } |
202 | 202 | ||
203 | void luaB_tag (lua_State *L) { | 203 | void luaB_tag (lua_State *L) { |
204 | lua_pushnumber(L, lua_tag(L, lua_getparam(L, 1))); | 204 | lua_pushnumber(L, lua_tag(L, luaL_nonnullarg(L, 1))); |
205 | } | 205 | } |
206 | 206 | ||
207 | void luaB_settag (lua_State *L) { | 207 | void luaB_settag (lua_State *L) { |
@@ -342,9 +342,9 @@ void luaB_call (lua_State *L) { | |||
342 | 342 | ||
343 | 343 | ||
344 | void luaB_nextvar (lua_State *L) { | 344 | void luaB_nextvar (lua_State *L) { |
345 | lua_Object o = luaL_nonnullarg(L, 1); | 345 | lua_Object o = lua_getparam(L, 1); |
346 | TString *name; | 346 | TString *name; |
347 | if (ttype(o) == TAG_NIL) | 347 | if (o == LUA_NOOBJECT || ttype(o) == TAG_NIL) |
348 | name = NULL; | 348 | name = NULL; |
349 | else { | 349 | else { |
350 | luaL_arg_check(L, ttype(o) == TAG_STRING, 1, "variable name expected"); | 350 | luaL_arg_check(L, ttype(o) == TAG_STRING, 1, "variable name expected"); |
@@ -357,9 +357,9 @@ void luaB_nextvar (lua_State *L) { | |||
357 | 357 | ||
358 | void luaB_next (lua_State *L) { | 358 | void luaB_next (lua_State *L) { |
359 | const Hash *a = gettable(L, 1); | 359 | const Hash *a = gettable(L, 1); |
360 | lua_Object k = luaL_nonnullarg(L, 2); | 360 | lua_Object k = lua_getparam(L, 2); |
361 | int i; /* `luaA_next' gets first element after `i' */ | 361 | int i; /* `luaA_next' gets first element after `i' */ |
362 | if (ttype(k) == TAG_NIL) | 362 | if (k == LUA_NOOBJECT || ttype(k) == TAG_NIL) |
363 | i = 0; /* get first */ | 363 | i = 0; /* get first */ |
364 | else { | 364 | else { |
365 | i = luaH_pos(L, a, k)+1; | 365 | i = luaH_pos(L, a, k)+1; |
@@ -414,8 +414,8 @@ void luaB_tostring (lua_State *L) { | |||
414 | */ | 414 | */ |
415 | 415 | ||
416 | void luaB_assert (lua_State *L) { | 416 | void luaB_assert (lua_State *L) { |
417 | lua_Object p = lua_getparam(L, 1); | 417 | lua_Object p = luaL_nonnullarg(L, 1); |
418 | if (p == LUA_NOOBJECT || lua_isnil(L, p)) | 418 | if (lua_isnil(L, p)) |
419 | luaL_verror(L, "assertion failed! %.90s", luaL_opt_string(L, 2, "")); | 419 | luaL_verror(L, "assertion failed! %.90s", luaL_opt_string(L, 2, "")); |
420 | } | 420 | } |
421 | 421 | ||
@@ -590,7 +590,6 @@ static void auxsort (lua_State *L, Hash *a, int l, int u, lua_Object f) { | |||
590 | } | 590 | } |
591 | 591 | ||
592 | void luaB_sort (lua_State *L) { | 592 | void luaB_sort (lua_State *L) { |
593 | lua_Object t = lua_getparam(L, 1); | ||
594 | Hash *a = gettable(L, 1); | 593 | Hash *a = gettable(L, 1); |
595 | int n = (int)getnarg(L, a); | 594 | int n = (int)getnarg(L, a); |
596 | lua_Object func = lua_getparam(L, 2); | 595 | lua_Object func = lua_getparam(L, 2); |
@@ -598,7 +597,6 @@ void luaB_sort (lua_State *L) { | |||
598 | "function expected"); | 597 | "function expected"); |
599 | luaD_checkstack(L, 4); /* for pivot, f, a, b (sort_comp) */ | 598 | luaD_checkstack(L, 4); /* for pivot, f, a, b (sort_comp) */ |
600 | auxsort(L, a, 1, n, func); | 599 | auxsort(L, a, 1, n, func); |
601 | lua_pushobject(L, t); | ||
602 | } | 600 | } |
603 | 601 | ||
604 | /* }====================================================== */ | 602 | /* }====================================================== */ |