diff options
| author | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1994-08-03 11:15:46 -0300 |
|---|---|---|
| committer | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1994-08-03 11:15:46 -0300 |
| commit | b1e9b37883ebc3f9926f6693350a73d6cbb94b6e (patch) | |
| tree | 600f3e33d0dd976b0c2d6c86489f22ebcd129301 | |
| parent | 467288e5b35d6f264bdded9b4d09dbaa0597f967 (diff) | |
| download | lua-b1e9b37883ebc3f9926f6693350a73d6cbb94b6e.tar.gz lua-b1e9b37883ebc3f9926f6693350a73d6cbb94b6e.tar.bz2 lua-b1e9b37883ebc3f9926f6693350a73d6cbb94b6e.zip | |
Implementacao de funcoes para tratar Lua function em C e
correcoes de bugs nas tabelas dinamicas.
| -rw-r--r-- | lua.h | 4 | ||||
| -rw-r--r-- | lua.stx | 14 | ||||
| -rw-r--r-- | opcode.c | 28 | ||||
| -rw-r--r-- | table.c | 6 |
4 files changed, 42 insertions, 10 deletions
| @@ -2,7 +2,7 @@ | |||
| 2 | ** LUA - Linguagem para Usuarios de Aplicacao | 2 | ** LUA - Linguagem para Usuarios de Aplicacao |
| 3 | ** Grupo de Tecnologia em Computacao Grafica | 3 | ** Grupo de Tecnologia em Computacao Grafica |
| 4 | ** TeCGraf - PUC-Rio | 4 | ** TeCGraf - PUC-Rio |
| 5 | ** $Id: $ | 5 | ** $Id: lua.h,v 1.1 1993/12/17 18:41:19 celes Exp celes $ |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | 8 | ||
| @@ -20,6 +20,7 @@ void lua_error (char *s); | |||
| 20 | int lua_dofile (char *filename); | 20 | int lua_dofile (char *filename); |
| 21 | int lua_dostring (char *string); | 21 | int lua_dostring (char *string); |
| 22 | int lua_call (char *functionname, int nparam); | 22 | int lua_call (char *functionname, int nparam); |
| 23 | int lua_callfunction (lua_Object function, int nparam); | ||
| 23 | 24 | ||
| 24 | lua_Object lua_getparam (int number); | 25 | lua_Object lua_getparam (int number); |
| 25 | float lua_getnumber (lua_Object object); | 26 | float lua_getnumber (lua_Object object); |
| @@ -48,6 +49,7 @@ int lua_isnil (lua_Object object); | |||
| 48 | int lua_isnumber (lua_Object object); | 49 | int lua_isnumber (lua_Object object); |
| 49 | int lua_isstring (lua_Object object); | 50 | int lua_isstring (lua_Object object); |
| 50 | int lua_istable (lua_Object object); | 51 | int lua_istable (lua_Object object); |
| 52 | int lua_isfunction (lua_Object object); | ||
| 51 | int lua_iscfunction (lua_Object object); | 53 | int lua_iscfunction (lua_Object object); |
| 52 | int lua_isuserdata (lua_Object object); | 54 | int lua_isuserdata (lua_Object object); |
| 53 | 55 | ||
| @@ -1,6 +1,6 @@ | |||
| 1 | %{ | 1 | %{ |
| 2 | 2 | ||
| 3 | char *rcs_luastx = "$Id: lua.stx,v 2.4 1994/04/20 16:22:21 celes Exp celes $"; | 3 | char *rcs_luastx = "$Id: lua.stx,v 2.5 1994/07/19 21:27:18 celes Exp $"; |
| 4 | 4 | ||
| 5 | #include <stdio.h> | 5 | #include <stdio.h> |
| 6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
| @@ -113,10 +113,16 @@ static void flush_list (int m, int n) | |||
| 113 | if (m == 0) | 113 | if (m == 0) |
| 114 | code_byte(STORELIST0); | 114 | code_byte(STORELIST0); |
| 115 | else | 115 | else |
| 116 | if (m < 255) | ||
| 116 | { | 117 | { |
| 117 | code_byte(STORELIST); | 118 | code_byte(STORELIST); |
| 118 | code_byte(m); | 119 | code_byte(m); |
| 119 | } | 120 | } |
| 121 | else | ||
| 122 | { | ||
| 123 | lua_error ("list constructor too long"); | ||
| 124 | err = 1; | ||
| 125 | } | ||
| 120 | code_byte(n); | 126 | code_byte(n); |
| 121 | ntemp-=n; | 127 | ntemp-=n; |
| 122 | } | 128 | } |
| @@ -459,14 +465,14 @@ expr : '(' expr ')' { $$ = $2; } | |||
| 459 | 465 | ||
| 460 | typeconstructor: '@' | 466 | typeconstructor: '@' |
| 461 | { | 467 | { |
| 462 | code_byte(PUSHBYTE); | 468 | code_byte(PUSHWORD); |
| 463 | $<vLong>$ = pc; code_byte(0); | 469 | $<vLong>$ = pc; code_word(0); |
| 464 | incr_ntemp(); | 470 | incr_ntemp(); |
| 465 | code_byte(CREATEARRAY); | 471 | code_byte(CREATEARRAY); |
| 466 | } | 472 | } |
| 467 | objectname fieldlist | 473 | objectname fieldlist |
| 468 | { | 474 | { |
| 469 | basepc[$<vLong>2] = $4; | 475 | code_word_at(basepc+$<vLong>2, $4); |
| 470 | if ($3 < 0) /* there is no function to be called */ | 476 | if ($3 < 0) /* there is no function to be called */ |
| 471 | { | 477 | { |
| 472 | $$ = 1; | 478 | $$ = 1; |
| @@ -3,7 +3,7 @@ | |||
| 3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_opcode="$Id: opcode.c,v 2.1 1994/04/20 22:07:57 celes Exp celes $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 2.2 1994/07/19 21:27:18 celes Exp celes $"; |
| 7 | 7 | ||
| 8 | #include <stdio.h> | 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
| @@ -26,7 +26,7 @@ char *rcs_opcode="$Id: opcode.c,v 2.1 1994/04/20 22:07:57 celes Exp celes $"; | |||
| 26 | 26 | ||
| 27 | #define STACK_BUFFER (STACKGAP+128) | 27 | #define STACK_BUFFER (STACKGAP+128) |
| 28 | 28 | ||
| 29 | static Word maxstack; | 29 | static Long maxstack; |
| 30 | static Object *stack=NULL; | 30 | static Object *stack=NULL; |
| 31 | static Object *top, *base; | 31 | static Object *top, *base; |
| 32 | 32 | ||
| @@ -684,6 +684,22 @@ int lua_call (char *functionname, int nparam) | |||
| 684 | } | 684 | } |
| 685 | 685 | ||
| 686 | /* | 686 | /* |
| 687 | ** Execute the given lua function. Return 0 on success or 1 on error. | ||
| 688 | */ | ||
| 689 | int lua_callfunction (Object *function, int nparam) | ||
| 690 | { | ||
| 691 | static Byte startcode[] = {CALLFUNC, HALT}; | ||
| 692 | int i; | ||
| 693 | if (tag(function) != T_FUNCTION) return 1; | ||
| 694 | for (i=1; i<=nparam; i++) | ||
| 695 | *(top-i+2) = *(top-i); | ||
| 696 | top += 2; | ||
| 697 | tag(top-nparam-1) = T_MARK; | ||
| 698 | *(top-nparam-2) = *function; | ||
| 699 | return (lua_execute (startcode)); | ||
| 700 | } | ||
| 701 | |||
| 702 | /* | ||
| 687 | ** Get a parameter, returning the object handle or NULL on error. | 703 | ** Get a parameter, returning the object handle or NULL on error. |
| 688 | ** 'number' must be 1 to get the first parameter. | 704 | ** 'number' must be 1 to get the first parameter. |
| 689 | */ | 705 | */ |
| @@ -954,6 +970,14 @@ int lua_istable (Object *object) | |||
| 954 | } | 970 | } |
| 955 | 971 | ||
| 956 | /* | 972 | /* |
| 973 | ** Given an object handle, return if it is a lua function. | ||
| 974 | */ | ||
| 975 | int lua_isfunction (Object *object) | ||
| 976 | { | ||
| 977 | return (object != NULL && tag(object) == T_FUNCTION); | ||
| 978 | } | ||
| 979 | |||
| 980 | /* | ||
| 957 | ** Given an object handle, return if it is a cfunction one. | 981 | ** Given an object handle, return if it is a cfunction one. |
| 958 | */ | 982 | */ |
| 959 | int lua_iscfunction (Object *object) | 983 | int lua_iscfunction (Object *object) |
| @@ -3,7 +3,7 @@ | |||
| 3 | ** Module to control static tables | 3 | ** Module to control static tables |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_table="$Id: table.c,v 2.1 1994/04/20 22:07:57 celes Exp celes $"; | 6 | char *rcs_table="$Id: table.c,v 2.2 1994/07/19 21:27:18 celes Exp celes $"; |
| 7 | 7 | ||
| 8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
| 9 | #include <string.h> | 9 | #include <string.h> |
| @@ -23,11 +23,11 @@ char *rcs_table="$Id: table.c,v 2.1 1994/04/20 22:07:57 celes Exp celes $"; | |||
| 23 | 23 | ||
| 24 | Symbol *lua_table; | 24 | Symbol *lua_table; |
| 25 | static Word lua_ntable = 0; | 25 | static Word lua_ntable = 0; |
| 26 | static Word lua_maxsymbol = 0; | 26 | static Long lua_maxsymbol = 0; |
| 27 | 27 | ||
| 28 | char **lua_constant; | 28 | char **lua_constant; |
| 29 | static Word lua_nconstant = 0; | 29 | static Word lua_nconstant = 0; |
| 30 | static Word lua_maxconstant = 0; | 30 | static Long lua_maxconstant = 0; |
| 31 | 31 | ||
| 32 | 32 | ||
| 33 | 33 | ||
