diff options
Diffstat (limited to 'opcode.c')
-rw-r--r-- | opcode.c | 37 |
1 files changed, 34 insertions, 3 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_opcode="$Id: opcode.c,v 3.53 1996/01/23 18:43:07 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 3.54 1996/01/30 15:25:23 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
@@ -441,6 +441,38 @@ int lua_currentline (lua_Object func) | |||
441 | } | 441 | } |
442 | 442 | ||
443 | 443 | ||
444 | lua_Object lua_getlocal (lua_Object func, int local_number, char **name) | ||
445 | { | ||
446 | Object *f = luaI_Address(func); | ||
447 | *name = luaI_getlocalname(f->value.tf, local_number, lua_currentline(func)); | ||
448 | if (*name) | ||
449 | { | ||
450 | /* if "*name", there must be a LUA_T_LINE */ | ||
451 | /* therefore, f+2 points to function base */ | ||
452 | return Ref((f+2)+(local_number-1)); | ||
453 | } | ||
454 | else | ||
455 | return LUA_NOOBJECT; | ||
456 | } | ||
457 | |||
458 | int lua_setlocal (lua_Object func, int local_number) | ||
459 | { | ||
460 | Object *f = Address(func); | ||
461 | char *name = luaI_getlocalname(f->value.tf, local_number, lua_currentline(func)); | ||
462 | adjustC(1); | ||
463 | --top; | ||
464 | if (name) | ||
465 | { | ||
466 | /* if "name", there must be a LUA_T_LINE */ | ||
467 | /* therefore, f+2 points to function base */ | ||
468 | *((f+2)+(local_number-1)) = *top; | ||
469 | return 1; | ||
470 | } | ||
471 | else | ||
472 | return 0; | ||
473 | } | ||
474 | |||
475 | |||
444 | /* | 476 | /* |
445 | ** Execute a protected call. Assumes that function is at CBase and | 477 | ** Execute a protected call. Assumes that function is at CBase and |
446 | ** parameters are on top of it. Leave nResults on the stack. | 478 | ** parameters are on top of it. Leave nResults on the stack. |
@@ -480,9 +512,8 @@ static int do_protectedmain (void) | |||
480 | adjustC(1); /* one slot for the pseudo-function */ | 512 | adjustC(1); /* one slot for the pseudo-function */ |
481 | stack[CBase].tag = LUA_T_FUNCTION; | 513 | stack[CBase].tag = LUA_T_FUNCTION; |
482 | stack[CBase].value.tf = &tf; | 514 | stack[CBase].value.tf = &tf; |
483 | tf.lineDefined = 0; | 515 | luaI_initTFunc(&tf); |
484 | tf.fileName = lua_parsedfile; | 516 | tf.fileName = lua_parsedfile; |
485 | tf.code = NULL; | ||
486 | if (setjmp(myErrorJmp) == 0) | 517 | if (setjmp(myErrorJmp) == 0) |
487 | { | 518 | { |
488 | lua_parse(&tf); | 519 | lua_parse(&tf); |