aboutsummaryrefslogtreecommitdiff
path: root/lbuiltin.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-12-02 14:24:45 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-12-02 14:24:45 -0200
commit8223ff473f3ffe782629fb1ba9ce1f96efeb7fd4 (patch)
tree94d59b8fcc1845002f8972f46069140cee7079c0 /lbuiltin.c
parentfe237ad8085f34e89fcd3610a9771215af63f03f (diff)
downloadlua-8223ff473f3ffe782629fb1ba9ce1f96efeb7fd4.tar.gz
lua-8223ff473f3ffe782629fb1ba9ce1f96efeb7fd4.tar.bz2
lua-8223ff473f3ffe782629fb1ba9ce1f96efeb7fd4.zip
lua_Object is a pointer to the stack (because now the stack doen't move)
Diffstat (limited to 'lbuiltin.c')
-rw-r--r--lbuiltin.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/lbuiltin.c b/lbuiltin.c
index 28b64270..21a9430b 100644
--- a/lbuiltin.c
+++ b/lbuiltin.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbuiltin.c,v 1.78 1999/11/30 13:06:50 roberto Exp roberto $ 2** $Id: lbuiltin.c,v 1.79 1999/12/01 19:50:08 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*/
@@ -70,7 +70,7 @@ static real getnarg (lua_State *L, const Hash *a) {
70 70
71 71
72static Hash *gettable (lua_State *L, int arg) { 72static Hash *gettable (lua_State *L, int arg) {
73 return avalue(luaA_Address(L, luaL_tablearg(L, arg))); 73 return avalue(luaL_tablearg(L, arg));
74} 74}
75 75
76/* }====================================================== */ 76/* }====================================================== */
@@ -329,7 +329,7 @@ static void luaB_call (lua_State *L) {
329 329
330 330
331static void luaB_nextvar (lua_State *L) { 331static void luaB_nextvar (lua_State *L) {
332 const TObject *o = luaA_Address(L, luaL_nonnullarg(L, 1)); 332 lua_Object o = luaL_nonnullarg(L, 1);
333 TaggedString *g; 333 TaggedString *g;
334 if (ttype(o) == LUA_T_NIL) 334 if (ttype(o) == LUA_T_NIL)
335 g = NULL; 335 g = NULL;
@@ -344,7 +344,7 @@ static void luaB_nextvar (lua_State *L) {
344 344
345static void luaB_next (lua_State *L) { 345static void luaB_next (lua_State *L) {
346 const Hash *a = gettable(L, 1); 346 const Hash *a = gettable(L, 1);
347 const TObject *k = luaA_Address(L, luaL_nonnullarg(L, 2)); 347 lua_Object k = luaL_nonnullarg(L, 2);
348 int i; /* will get first element after `i' */ 348 int i; /* will get first element after `i' */
349 if (ttype(k) == LUA_T_NIL) 349 if (ttype(k) == LUA_T_NIL)
350 i = 0; /* get first */ 350 i = 0; /* get first */
@@ -358,15 +358,14 @@ static void luaB_next (lua_State *L) {
358 358
359 359
360static void luaB_tostring (lua_State *L) { 360static void luaB_tostring (lua_State *L) {
361 lua_Object obj = lua_getparam(L, 1); 361 lua_Object o = lua_getparam(L, 1);
362 const TObject *o = luaA_Address(L, obj);
363 char buff[64]; 362 char buff[64];
364 switch (ttype(o)) { 363 switch (ttype(o)) {
365 case LUA_T_NUMBER: 364 case LUA_T_NUMBER:
366 lua_pushstring(L, lua_getstring(L, obj)); 365 lua_pushstring(L, lua_getstring(L, o));
367 return; 366 return;
368 case LUA_T_STRING: 367 case LUA_T_STRING:
369 lua_pushobject(L, obj); 368 lua_pushobject(L, o);
370 return; 369 return;
371 case LUA_T_ARRAY: 370 case LUA_T_ARRAY:
372 sprintf(buff, "table: %p", o->value.a); 371 sprintf(buff, "table: %p", o->value.a);
@@ -417,7 +416,7 @@ static void luaB_foreachi (lua_State *L) {
417 const Hash *t = gettable(L, 1); 416 const Hash *t = gettable(L, 1);
418 int n = (int)getnarg(L, t); 417 int n = (int)getnarg(L, t);
419 int i; 418 int i;
420 StkId f = luaA_Address(L, luaL_functionarg(L, 2)); 419 lua_Object f = luaL_functionarg(L, 2);
421 luaD_checkstack(L, 3); /* for f, key, and val */ 420 luaD_checkstack(L, 3); /* for f, key, and val */
422 for (i=1; i<=n; i++) { 421 for (i=1; i<=n; i++) {
423 *(L->top++) = *f; 422 *(L->top++) = *f;
@@ -433,7 +432,7 @@ static void luaB_foreachi (lua_State *L) {
433 432
434static void luaB_foreach (lua_State *L) { 433static void luaB_foreach (lua_State *L) {
435 const Hash *a = gettable(L, 1); 434 const Hash *a = gettable(L, 1);
436 StkId f = luaA_Address(L, luaL_functionarg(L, 2)); 435 lua_Object f = luaL_functionarg(L, 2);
437 int i; 436 int i;
438 luaD_checkstack(L, 3); /* for f, key, and val */ 437 luaD_checkstack(L, 3); /* for f, key, and val */
439 for (i=0; i<a->size; i++) { 438 for (i=0; i<a->size; i++) {
@@ -452,7 +451,7 @@ static void luaB_foreach (lua_State *L) {
452 451
453 452
454static void luaB_foreachvar (lua_State *L) { 453static void luaB_foreachvar (lua_State *L) {
455 StkId f = luaA_Address(L, luaL_functionarg(L, 1)); 454 lua_Object f = luaL_functionarg(L, 1);
456 GlobalVar *gv; 455 GlobalVar *gv;
457 luaD_checkstack(L, 4); /* for extra var name, f, var name, and globalval */ 456 luaD_checkstack(L, 4); /* for extra var name, f, var name, and globalval */
458 for (gv = L->rootglobal; gv; gv = gv->next) { 457 for (gv = L->rootglobal; gv; gv = gv->next) {
@@ -492,7 +491,7 @@ static void luaB_tinsert (lua_State *L) {
492 luaV_setn(L, a, n+1); /* a.n = n+1 */ 491 luaV_setn(L, a, n+1); /* a.n = n+1 */
493 for ( ;n>=pos; n--) 492 for ( ;n>=pos; n--)
494 luaH_move(L, a, n, n+1); /* a[n+1] = a[n] */ 493 luaH_move(L, a, n, n+1); /* a[n+1] = a[n] */
495 luaH_setint(L, a, pos, luaA_Address(L, v)); /* a[pos] = v */ 494 luaH_setint(L, a, pos, v); /* a[pos] = v */
496} 495}
497 496
498 497
@@ -525,7 +524,7 @@ static int sort_comp (lua_State *L, lua_Object f, const TObject *a,
525 const TObject *b) { 524 const TObject *b) {
526 /* notice: the caller (auxsort) must check stack space */ 525 /* notice: the caller (auxsort) must check stack space */
527 if (f != LUA_NOOBJECT) { 526 if (f != LUA_NOOBJECT) {
528 *(L->top) = *luaA_Address(L, f); 527 *(L->top) = *f;
529 *(L->top+1) = *a; 528 *(L->top+1) = *a;
530 *(L->top+2) = *b; 529 *(L->top+2) = *b;
531 L->top += 3; 530 L->top += 3;
@@ -618,20 +617,20 @@ static void mem_query (lua_State *L) {
618 617
619 618
620static void hash_query (lua_State *L) { 619static void hash_query (lua_State *L) {
621 const TObject *o = luaA_Address(L, luaL_nonnullarg(L, 1)); 620 lua_Object o = luaL_nonnullarg(L, 1);
622 if (lua_getparam(L, 2) == LUA_NOOBJECT) { 621 if (lua_getparam(L, 2) == LUA_NOOBJECT) {
623 luaL_arg_check(L, ttype(o) == LUA_T_STRING, 1, "string expected"); 622 luaL_arg_check(L, ttype(o) == LUA_T_STRING, 1, "string expected");
624 lua_pushnumber(L, tsvalue(o)->hash); 623 lua_pushnumber(L, tsvalue(o)->hash);
625 } 624 }
626 else { 625 else {
627 const Hash *t = avalue(luaA_Address(L, luaL_tablearg(L, 2))); 626 const Hash *t = avalue(luaL_tablearg(L, 2));
628 lua_pushnumber(L, luaH_mainposition(L, t, o) - t->node); 627 lua_pushnumber(L, luaH_mainposition(L, t, o) - t->node);
629 } 628 }
630} 629}
631 630
632 631
633static void table_query (lua_State *L) { 632static void table_query (lua_State *L) {
634 const Hash *t = avalue(luaA_Address(L, luaL_tablearg(L, 1))); 633 const Hash *t = avalue(luaL_tablearg(L, 1));
635 int i = luaL_opt_int(L, 2, -1); 634 int i = luaL_opt_int(L, 2, -1);
636 if (i == -1) { 635 if (i == -1) {
637 lua_pushnumber(L, t->size); 636 lua_pushnumber(L, t->size);