diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-12-11 12:48:46 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-12-11 12:48:46 -0200 |
commit | 034f16892eb49361ee66f8d89aec26b071c98f57 (patch) | |
tree | 04c714baf2d60ea84a0cca270aa845faff185380 /lapi.c | |
parent | c759520bc86c9504ebec58b0de655c93c5010e5f (diff) | |
download | lua-034f16892eb49361ee66f8d89aec26b071c98f57.tar.gz lua-034f16892eb49361ee66f8d89aec26b071c98f57.tar.bz2 lua-034f16892eb49361ee66f8d89aec26b071c98f57.zip |
better treatment of MARKs and DEBUG cases.
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 52 |
1 files changed, 33 insertions, 19 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) |