diff options
Diffstat (limited to 'lbuiltin.c')
-rw-r--r-- | lbuiltin.c | 33 |
1 files changed, 20 insertions, 13 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbuiltin.c,v 1.67 1999/10/14 19:13:31 roberto Exp roberto $ | 2 | ** $Id: lbuiltin.c,v 1.68 1999/10/19 13:33:22 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 | */ |
@@ -68,7 +68,7 @@ static real getnarg (const Hash *a) { | |||
68 | } | 68 | } |
69 | 69 | ||
70 | 70 | ||
71 | static Hash *gethash (int arg) { | 71 | static Hash *gettable (int arg) { |
72 | return avalue(luaA_Address(luaL_tablearg(arg))); | 72 | return avalue(luaA_Address(luaL_tablearg(arg))); |
73 | } | 73 | } |
74 | 74 | ||
@@ -285,7 +285,7 @@ static void luaB_dofile (void) { | |||
285 | 285 | ||
286 | static void luaB_call (void) { | 286 | static void luaB_call (void) { |
287 | lua_Object f = luaL_nonnullarg(1); | 287 | lua_Object f = luaL_nonnullarg(1); |
288 | const Hash *arg = gethash(2); | 288 | const Hash *arg = gettable(2); |
289 | const char *options = luaL_opt_string(3, ""); | 289 | const char *options = luaL_opt_string(3, ""); |
290 | lua_Object err = lua_getparam(4); | 290 | lua_Object err = lua_getparam(4); |
291 | int narg = (int)getnarg(arg); | 291 | int narg = (int)getnarg(arg); |
@@ -335,7 +335,7 @@ static void luaB_nextvar (void) { | |||
335 | 335 | ||
336 | 336 | ||
337 | static void luaB_next (void) { | 337 | static void luaB_next (void) { |
338 | const Hash *a = gethash(1); | 338 | const Hash *a = gettable(1); |
339 | const TObject *k = luaA_Address(luaL_nonnullarg(2)); | 339 | const TObject *k = luaA_Address(luaL_nonnullarg(2)); |
340 | int i; /* will get first element after `i' */ | 340 | int i; /* will get first element after `i' */ |
341 | if (ttype(k) == LUA_T_NIL) | 341 | if (ttype(k) == LUA_T_NIL) |
@@ -406,7 +406,7 @@ static void luaB_assert (void) { | |||
406 | 406 | ||
407 | 407 | ||
408 | static void luaB_foreachi (void) { | 408 | static void luaB_foreachi (void) { |
409 | const Hash *t = gethash(1); | 409 | const Hash *t = gettable(1); |
410 | int i; | 410 | int i; |
411 | int n = (int)getnarg(t); | 411 | int n = (int)getnarg(t); |
412 | TObject f; | 412 | TObject f; |
@@ -428,7 +428,7 @@ static void luaB_foreachi (void) { | |||
428 | 428 | ||
429 | 429 | ||
430 | static void luaB_foreach (void) { | 430 | static void luaB_foreach (void) { |
431 | const Hash *a = gethash(1); | 431 | const Hash *a = gettable(1); |
432 | int i; | 432 | int i; |
433 | TObject f; /* see comment in 'foreachi' */ | 433 | TObject f; /* see comment in 'foreachi' */ |
434 | f = *luaA_Address(luaL_functionarg(2)); | 434 | f = *luaA_Address(luaL_functionarg(2)); |
@@ -472,12 +472,12 @@ static void luaB_foreachvar (void) { | |||
472 | 472 | ||
473 | 473 | ||
474 | static void luaB_getn (void) { | 474 | static void luaB_getn (void) { |
475 | lua_pushnumber(getnarg(gethash(1))); | 475 | lua_pushnumber(getnarg(gettable(1))); |
476 | } | 476 | } |
477 | 477 | ||
478 | 478 | ||
479 | static void luaB_tinsert (void) { | 479 | static void luaB_tinsert (void) { |
480 | Hash *a = gethash(1); | 480 | Hash *a = gettable(1); |
481 | lua_Object v = lua_getparam(3); | 481 | lua_Object v = lua_getparam(3); |
482 | int n = (int)getnarg(a); | 482 | int n = (int)getnarg(a); |
483 | int pos; | 483 | int pos; |
@@ -495,7 +495,7 @@ static void luaB_tinsert (void) { | |||
495 | 495 | ||
496 | 496 | ||
497 | static void luaB_tremove (void) { | 497 | static void luaB_tremove (void) { |
498 | Hash *a = gethash(1); | 498 | Hash *a = gettable(1); |
499 | int n = (int)getnarg(a); | 499 | int n = (int)getnarg(a); |
500 | int pos = luaL_opt_int(2, n); | 500 | int pos = luaL_opt_int(2, n); |
501 | if (n <= 0) return; /* table is "empty" */ | 501 | if (n <= 0) return; /* table is "empty" */ |
@@ -583,7 +583,7 @@ static void auxsort (Hash *a, int l, int u, lua_Object f) { | |||
583 | 583 | ||
584 | static void luaB_sort (void) { | 584 | static void luaB_sort (void) { |
585 | lua_Object t = lua_getparam(1); | 585 | lua_Object t = lua_getparam(1); |
586 | Hash *a = gethash(1); | 586 | Hash *a = gettable(1); |
587 | int n = (int)getnarg(a); | 587 | int n = (int)getnarg(a); |
588 | lua_Object func = lua_getparam(2); | 588 | lua_Object func = lua_getparam(2); |
589 | luaL_arg_check(func == LUA_NOOBJECT || lua_isfunction(func), 2, | 589 | luaL_arg_check(func == LUA_NOOBJECT || lua_isfunction(func), 2, |
@@ -616,8 +616,14 @@ static void mem_query (void) { | |||
616 | 616 | ||
617 | static void hash_query (void) { | 617 | static void hash_query (void) { |
618 | const TObject *o = luaA_Address(luaL_nonnullarg(1)); | 618 | const TObject *o = luaA_Address(luaL_nonnullarg(1)); |
619 | luaL_arg_check(ttype(o) == LUA_T_STRING, 1, "string expected"); | 619 | if (lua_getparam(2) == LUA_NOOBJECT) { |
620 | lua_pushnumber(tsvalue(o)->hash); | 620 | luaL_arg_check(ttype(o) == LUA_T_STRING, 1, "string expected"); |
621 | lua_pushnumber(tsvalue(o)->hash); | ||
622 | } | ||
623 | else { | ||
624 | const Hash *t = avalue(luaA_Address(luaL_tablearg(2))); | ||
625 | lua_pushnumber(luaH_mainposition(t, o) - t->node); | ||
626 | } | ||
621 | } | 627 | } |
622 | 628 | ||
623 | 629 | ||
@@ -631,7 +637,8 @@ static void table_query (void) { | |||
631 | else if (i < t->size) { | 637 | else if (i < t->size) { |
632 | luaA_pushobject(&t->node[i].key); | 638 | luaA_pushobject(&t->node[i].key); |
633 | luaA_pushobject(&t->node[i].val); | 639 | luaA_pushobject(&t->node[i].val); |
634 | lua_pushnumber(t->node[i].next == NULL ? 0 : t->node[i].next - t->node); | 640 | if (t->node[i].next) |
641 | lua_pushnumber(t->node[i].next - t->node); | ||
635 | } | 642 | } |
636 | } | 643 | } |
637 | 644 | ||