diff options
| -rw-r--r-- | lapi.c | 52 | ||||
| -rw-r--r-- | lgc.c | 10 | ||||
| -rw-r--r-- | lstate.c | 4 | ||||
| -rw-r--r-- | ltm.c | 8 | ||||
| -rw-r--r-- | lua.c | 4 |
5 files changed, 50 insertions, 28 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 1.11 1997/11/28 16:56:05 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.12 1997/12/09 13:35:19 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 | */ |
| @@ -35,6 +35,25 @@ TObject *luaA_Address (lua_Object o) | |||
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | 37 | ||
| 38 | static int normalized_type (TObject *o) | ||
| 39 | { | ||
| 40 | int t = ttype(o); | ||
| 41 | switch (t) { | ||
| 42 | case LUA_T_MARK: | ||
| 43 | return LUA_T_FUNCTION; | ||
| 44 | default: | ||
| 45 | return t; | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | |||
| 50 | static void set_normalized (TObject *d, TObject *s) | ||
| 51 | { | ||
| 52 | d->value = s->value; | ||
| 53 | d->ttype = normalized_type(s); | ||
| 54 | } | ||
| 55 | |||
| 56 | |||
| 38 | void luaA_packresults (void) | 57 | void luaA_packresults (void) |
| 39 | { | 58 | { |
| 40 | luaV_pack(L->Cstack.lua2C, L->Cstack.num, L->stack.top); | 59 | luaV_pack(L->Cstack.lua2C, L->Cstack.num, L->stack.top); |
| @@ -101,7 +120,7 @@ int lua_callfunction (lua_Object function) | |||
| 101 | return 1; | 120 | return 1; |
| 102 | else { | 121 | else { |
| 103 | luaD_openstack((L->stack.top-L->stack.stack)-L->Cstack.base); | 122 | luaD_openstack((L->stack.top-L->stack.stack)-L->Cstack.base); |
| 104 | L->stack.stack[L->Cstack.base] = *Address(function); | 123 | set_normalized(L->stack.stack+L->Cstack.base, Address(function)); |
| 105 | return luaD_protectedrun(MULT_RET); | 124 | return luaD_protectedrun(MULT_RET); |
| 106 | } | 125 | } |
| 107 | } | 126 | } |
| @@ -244,8 +263,7 @@ int lua_isstring (lua_Object o) | |||
| 244 | 263 | ||
| 245 | int lua_isfunction (lua_Object o) | 264 | int lua_isfunction (lua_Object o) |
| 246 | { | 265 | { |
| 247 | return (o != LUA_NOOBJECT) && ((ttype(Address(o)) == LUA_T_FUNCTION) || | 266 | return (o != LUA_NOOBJECT) && (normalized_type(Address(o)) == LUA_T_FUNCTION); |
| 248 | (ttype(Address(o)) == LUA_T_MARK)); | ||
| 249 | } | 267 | } |
| 250 | 268 | ||
| 251 | 269 | ||
| @@ -334,10 +352,10 @@ void lua_pushobject (lua_Object o) | |||
| 334 | { | 352 | { |
| 335 | if (o == LUA_NOOBJECT) | 353 | if (o == LUA_NOOBJECT) |
| 336 | lua_error("API error - attempt to push a NOOBJECT"); | 354 | lua_error("API error - attempt to push a NOOBJECT"); |
| 337 | *L->stack.top = *Address(o); | 355 | else { |
| 338 | if (ttype(L->stack.top) == LUA_T_MARK) | 356 | set_normalized(L->stack.top, Address(o)); |
| 339 | ttype(L->stack.top) = LUA_T_FUNCTION; | 357 | incr_top; |
| 340 | incr_top; | 358 | } |
| 341 | } | 359 | } |
| 342 | 360 | ||
| 343 | 361 | ||
| @@ -406,11 +424,11 @@ int lua_currentline (lua_Function func) | |||
| 406 | 424 | ||
| 407 | lua_Object lua_getlocal (lua_Function func, int local_number, char **name) | 425 | lua_Object lua_getlocal (lua_Function func, int local_number, char **name) |
| 408 | { | 426 | { |
| 409 | TObject *f = luaA_Address(func); | 427 | /* check whether func is a function */ |
| 410 | /* check whether func is a Lua function */ | 428 | if (!lua_isfunction(func)) |
| 411 | if (!(f->ttype == LUA_T_MARK || f->ttype == LUA_T_FUNCTION)) | ||
| 412 | return LUA_NOOBJECT; | 429 | return LUA_NOOBJECT; |
| 413 | else { | 430 | else { |
| 431 | TObject *f = luaA_Address(func); | ||
| 414 | TProtoFunc *fp = protovalue(f)->value.tf; | 432 | TProtoFunc *fp = protovalue(f)->value.tf; |
| 415 | *name = luaF_getlocalname(fp, local_number, lua_currentline(func)); | 433 | *name = luaF_getlocalname(fp, local_number, lua_currentline(func)); |
| 416 | if (*name) { | 434 | if (*name) { |
| @@ -444,11 +462,10 @@ int lua_setlocal (lua_Function func, int local_number) | |||
| 444 | 462 | ||
| 445 | void lua_funcinfo (lua_Object func, char **filename, int *linedefined) | 463 | void lua_funcinfo (lua_Object func, char **filename, int *linedefined) |
| 446 | { | 464 | { |
| 447 | TObject *f = Address(func); | 465 | if (!lua_isfunction(func)) |
| 448 | if (!(ttype(f) == LUA_T_MARK || ttype(f) == LUA_T_FUNCTION)) | ||
| 449 | lua_error("API - `funcinfo' called with a non-function value"); | 466 | lua_error("API - `funcinfo' called with a non-function value"); |
| 450 | else { | 467 | else { |
| 451 | f = protovalue(f); | 468 | TObject *f = protovalue(Address(func)); |
| 452 | if (ttype(f) == LUA_T_PROTO) { | 469 | if (ttype(f) == LUA_T_PROTO) { |
| 453 | *filename = tfvalue(f)->fileName->str; | 470 | *filename = tfvalue(f)->fileName->str; |
| 454 | *linedefined = tfvalue(f)->lineDefined; | 471 | *linedefined = tfvalue(f)->lineDefined; |
| @@ -463,16 +480,13 @@ void lua_funcinfo (lua_Object func, char **filename, int *linedefined) | |||
| 463 | 480 | ||
| 464 | static int checkfunc (TObject *o) | 481 | static int checkfunc (TObject *o) |
| 465 | { | 482 | { |
| 466 | return o->ttype == LUA_T_FUNCTION && | 483 | return luaO_equalObj(o, L->stack.top); |
| 467 | (ttype(L->stack.top) == LUA_T_FUNCTION || | ||
| 468 | ttype(L->stack.top) == LUA_T_MARK) && | ||
| 469 | clvalue(L->stack.top) == o->value.cl; | ||
| 470 | } | 484 | } |
| 471 | 485 | ||
| 472 | 486 | ||
| 473 | char *lua_getobjname (lua_Object o, char **name) | 487 | char *lua_getobjname (lua_Object o, char **name) |
| 474 | { /* try to find a name for given function */ | 488 | { /* try to find a name for given function */ |
| 475 | *(L->stack.top) = *Address(o); /* to be accessed by "checkfunc */ | 489 | set_normalized(L->stack.top, Address(o)); /* to be accessed by "checkfunc */ |
| 476 | if ((*name = luaT_travtagmethods(checkfunc)) != NULL) | 490 | if ((*name = luaT_travtagmethods(checkfunc)) != NULL) |
| 477 | return "tag-method"; | 491 | return "tag-method"; |
| 478 | else if ((*name = luaS_travsymbol(checkfunc)) != NULL) | 492 | else if ((*name = luaS_travsymbol(checkfunc)) != NULL) |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.c,v 1.10 1997/12/01 20:31:25 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.11 1997/12/09 13:35:19 roberto Exp roberto $ |
| 3 | ** Garbage Collector | 3 | ** Garbage Collector |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -83,15 +83,19 @@ static void travlock (void) | |||
| 83 | 83 | ||
| 84 | static int ismarked (TObject *o) | 84 | static int ismarked (TObject *o) |
| 85 | { | 85 | { |
| 86 | /* valid only for locked objects */ | ||
| 86 | switch (o->ttype) { | 87 | switch (o->ttype) { |
| 87 | case LUA_T_STRING: case LUA_T_USERDATA: | 88 | case LUA_T_STRING: case LUA_T_USERDATA: |
| 88 | return o->value.ts->head.marked; | 89 | return o->value.ts->head.marked; |
| 89 | case LUA_T_FUNCTION: | 90 | case LUA_T_FUNCTION: |
| 90 | return o->value.cl->head.marked; | 91 | return o->value.cl->head.marked; |
| 91 | case LUA_T_PROTO: | ||
| 92 | return o->value.tf->head.marked; | ||
| 93 | case LUA_T_ARRAY: | 92 | case LUA_T_ARRAY: |
| 94 | return o->value.a->head.marked; | 93 | return o->value.a->head.marked; |
| 94 | #ifdef DEBUG | ||
| 95 | case LUA_T_LINE: case LUA_T_MARK: | ||
| 96 | case LUA_T_PROTO: case LUA_T_CPROTO: | ||
| 97 | lua_error("internal error"); | ||
| 98 | #endif | ||
| 95 | default: /* nil, number or cproto */ | 99 | default: /* nil, number or cproto */ |
| 96 | return 1; | 100 | return 1; |
| 97 | } | 101 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.c,v 1.2 1997/11/27 15:59:25 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 1.3 1997/12/01 20:31:25 roberto Exp roberto $ |
| 3 | ** Global State | 3 | ** Global State |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -69,7 +69,7 @@ void lua_close (void) | |||
| 69 | luaM_free(L->Mbuffer); | 69 | luaM_free(L->Mbuffer); |
| 70 | luaM_free(L); | 70 | luaM_free(L); |
| 71 | L = NULL; | 71 | L = NULL; |
| 72 | #if DEBUG | 72 | #ifdef DEBUG |
| 73 | printf("total de blocos: %ld\n", numblocks); | 73 | printf("total de blocos: %ld\n", numblocks); |
| 74 | printf("total de memoria: %ld\n", totalmem); | 74 | printf("total de memoria: %ld\n", totalmem); |
| 75 | #endif | 75 | #endif |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.c,v 1.8 1997/11/19 17:29:23 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 1.9 1997/11/19 18:16:33 roberto Exp roberto $ |
| 3 | ** Tag methods | 3 | ** Tag methods |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -106,8 +106,12 @@ int luaT_efectivetag (TObject *o) | |||
| 106 | } | 106 | } |
| 107 | case LUA_T_ARRAY: | 107 | case LUA_T_ARRAY: |
| 108 | return o->value.a->htag; | 108 | return o->value.a->htag; |
| 109 | case LUA_T_FUNCTION: case LUA_T_MARK: | 109 | case LUA_T_FUNCTION: case LUA_T_MARK: |
| 110 | return o->value.cl->consts[0].ttype; | 110 | return o->value.cl->consts[0].ttype; |
| 111 | #ifdef DEBUG | ||
| 112 | case LUA_T_LINE: case LUA_T_PROTO: case LUA_T_CPROTO: | ||
| 113 | lua_error("internal error"); | ||
| 114 | #endif | ||
| 111 | default: | 115 | default: |
| 112 | return t; | 116 | return t; |
| 113 | } | 117 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.c,v 1.6 1997/12/01 20:31:25 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.7 1997/12/03 19:57:54 roberto Exp roberto $ |
| 3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -100,7 +100,7 @@ int main (int argc, char *argv[]) | |||
| 100 | } | 100 | } |
| 101 | } | 101 | } |
| 102 | } | 102 | } |
| 103 | #if DEBUG | 103 | #ifdef DEBUG |
| 104 | lua_close(); | 104 | lua_close(); |
| 105 | #endif | 105 | #endif |
| 106 | return 0; | 106 | return 0; |
