diff options
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 30 |
1 files changed, 18 insertions, 12 deletions
| @@ -1,11 +1,10 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 1.49 1999/09/20 14:57:29 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.50 1999/09/21 16:10:13 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | #include <stdlib.h> | ||
| 9 | #include <string.h> | 8 | #include <string.h> |
| 10 | 9 | ||
| 11 | #include "lapi.h" | 10 | #include "lapi.h" |
| @@ -15,6 +14,7 @@ | |||
| 15 | #include "lgc.h" | 14 | #include "lgc.h" |
| 16 | #include "lmem.h" | 15 | #include "lmem.h" |
| 17 | #include "lobject.h" | 16 | #include "lobject.h" |
| 17 | #include "lref.h" | ||
| 18 | #include "lstate.h" | 18 | #include "lstate.h" |
| 19 | #include "lstring.h" | 19 | #include "lstring.h" |
| 20 | #include "ltable.h" | 20 | #include "ltable.h" |
| @@ -387,14 +387,14 @@ void lua_settag (int tag) { | |||
| 387 | 387 | ||
| 388 | TaggedString *luaA_nextvar (TaggedString *g) { | 388 | TaggedString *luaA_nextvar (TaggedString *g) { |
| 389 | if (g == NULL) | 389 | if (g == NULL) |
| 390 | g = (TaggedString *)L->rootglobal.next; /* first variable */ | 390 | g = L->rootglobal; /* first variable */ |
| 391 | else { | 391 | else { |
| 392 | /* check whether name is in global var list */ | 392 | /* check whether name is in global var list */ |
| 393 | luaL_arg_check((GCnode *)g != g->head.next, 1, "variable name expected"); | 393 | luaL_arg_check(g != g->next, 1, "variable name expected"); |
| 394 | g = (TaggedString *)g->head.next; /* get next */ | 394 | g = g->next; /* get next */ |
| 395 | } | 395 | } |
| 396 | while (g && g->u.s.globalval.ttype == LUA_T_NIL) /* skip globals with nil */ | 396 | while (g && g->u.s.globalval.ttype == LUA_T_NIL) /* skip globals with nil */ |
| 397 | g = (TaggedString *)g->head.next; | 397 | g = g->next; |
| 398 | if (g) { | 398 | if (g) { |
| 399 | ttype(L->stack.top) = LUA_T_STRING; tsvalue(L->stack.top) = g; | 399 | ttype(L->stack.top) = LUA_T_STRING; tsvalue(L->stack.top) = g; |
| 400 | incr_top; | 400 | incr_top; |
| @@ -574,12 +574,18 @@ static int checkfunc (TObject *o) { | |||
| 574 | 574 | ||
| 575 | const char *lua_getobjname (lua_Object o, const char **name) { | 575 | const char *lua_getobjname (lua_Object o, const char **name) { |
| 576 | /* try to find a name for given function */ | 576 | /* try to find a name for given function */ |
| 577 | TaggedString *g; | ||
| 577 | set_normalized(L->stack.top, Address(o)); /* to be accessed by "checkfunc" */ | 578 | set_normalized(L->stack.top, Address(o)); /* to be accessed by "checkfunc" */ |
| 578 | if ((*name = luaS_travsymbol(checkfunc)) != NULL) | 579 | for (g=L->rootglobal; g; g=g->next) { |
| 579 | return "global"; | 580 | if (checkfunc(&g->u.s.globalval)) { |
| 580 | else if ((*name = luaT_travtagmethods(checkfunc)) != NULL) | 581 | *name = g->str; |
| 582 | return "global"; | ||
| 583 | } | ||
| 584 | } | ||
| 585 | /* not found: try tag methods */ | ||
| 586 | if ((*name = luaT_travtagmethods(checkfunc)) != NULL) | ||
| 581 | return "tag-method"; | 587 | return "tag-method"; |
| 582 | else return ""; | 588 | else return ""; /* not found at all */ |
| 583 | } | 589 | } |
| 584 | 590 | ||
| 585 | /* }====================================================== */ | 591 | /* }====================================================== */ |
| @@ -615,7 +621,7 @@ void lua_endblock (void) { | |||
| 615 | int lua_ref (int lock) { | 621 | int lua_ref (int lock) { |
| 616 | int ref; | 622 | int ref; |
| 617 | checkCparams(1); | 623 | checkCparams(1); |
| 618 | ref = luaC_ref(L->stack.top-1, lock); | 624 | ref = luaR_ref(L->stack.top-1, lock); |
| 619 | L->stack.top--; | 625 | L->stack.top--; |
| 620 | return ref; | 626 | return ref; |
| 621 | } | 627 | } |
| @@ -623,7 +629,7 @@ int lua_ref (int lock) { | |||
| 623 | 629 | ||
| 624 | 630 | ||
| 625 | lua_Object lua_getref (int ref) { | 631 | lua_Object lua_getref (int ref) { |
| 626 | const TObject *o = luaC_getref(ref); | 632 | const TObject *o = luaR_getref(ref); |
| 627 | return (o ? put_luaObject(o) : LUA_NOOBJECT); | 633 | return (o ? put_luaObject(o) : LUA_NOOBJECT); |
| 628 | } | 634 | } |
| 629 | 635 | ||
