From b1e9b37883ebc3f9926f6693350a73d6cbb94b6e Mon Sep 17 00:00:00 2001 From: Waldemar Celes Date: Wed, 3 Aug 1994 11:15:46 -0300 Subject: Implementacao de funcoes para tratar Lua function em C e correcoes de bugs nas tabelas dinamicas. --- lua.h | 4 +++- lua.stx | 14 ++++++++++---- opcode.c | 28 ++++++++++++++++++++++++++-- table.c | 6 +++--- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/lua.h b/lua.h index b0bd7811..56adb3b3 100644 --- a/lua.h +++ b/lua.h @@ -2,7 +2,7 @@ ** LUA - Linguagem para Usuarios de Aplicacao ** Grupo de Tecnologia em Computacao Grafica ** TeCGraf - PUC-Rio -** $Id: $ +** $Id: lua.h,v 1.1 1993/12/17 18:41:19 celes Exp celes $ */ @@ -20,6 +20,7 @@ void lua_error (char *s); int lua_dofile (char *filename); int lua_dostring (char *string); int lua_call (char *functionname, int nparam); +int lua_callfunction (lua_Object function, int nparam); lua_Object lua_getparam (int number); float lua_getnumber (lua_Object object); @@ -48,6 +49,7 @@ int lua_isnil (lua_Object object); int lua_isnumber (lua_Object object); int lua_isstring (lua_Object object); int lua_istable (lua_Object object); +int lua_isfunction (lua_Object object); int lua_iscfunction (lua_Object object); int lua_isuserdata (lua_Object object); diff --git a/lua.stx b/lua.stx index 6c7c9791..f3d6776b 100644 --- a/lua.stx +++ b/lua.stx @@ -1,6 +1,6 @@ %{ -char *rcs_luastx = "$Id: lua.stx,v 2.4 1994/04/20 16:22:21 celes Exp celes $"; +char *rcs_luastx = "$Id: lua.stx,v 2.5 1994/07/19 21:27:18 celes Exp $"; #include #include @@ -113,10 +113,16 @@ static void flush_list (int m, int n) if (m == 0) code_byte(STORELIST0); else + if (m < 255) { code_byte(STORELIST); code_byte(m); } + else + { + lua_error ("list constructor too long"); + err = 1; + } code_byte(n); ntemp-=n; } @@ -459,14 +465,14 @@ expr : '(' expr ')' { $$ = $2; } typeconstructor: '@' { - code_byte(PUSHBYTE); - $$ = pc; code_byte(0); + code_byte(PUSHWORD); + $$ = pc; code_word(0); incr_ntemp(); code_byte(CREATEARRAY); } objectname fieldlist { - basepc[$2] = $4; + code_word_at(basepc+$2, $4); if ($3 < 0) /* there is no function to be called */ { $$ = 1; diff --git a/opcode.c b/opcode.c index 2309bed1..b2f5cb41 100644 --- a/opcode.c +++ b/opcode.c @@ -3,7 +3,7 @@ ** TecCGraf - PUC-Rio */ -char *rcs_opcode="$Id: opcode.c,v 2.1 1994/04/20 22:07:57 celes Exp celes $"; +char *rcs_opcode="$Id: opcode.c,v 2.2 1994/07/19 21:27:18 celes Exp celes $"; #include #include @@ -26,7 +26,7 @@ char *rcs_opcode="$Id: opcode.c,v 2.1 1994/04/20 22:07:57 celes Exp celes $"; #define STACK_BUFFER (STACKGAP+128) -static Word maxstack; +static Long maxstack; static Object *stack=NULL; static Object *top, *base; @@ -683,6 +683,22 @@ int lua_call (char *functionname, int nparam) return (lua_execute (startcode)); } +/* +** Execute the given lua function. Return 0 on success or 1 on error. +*/ +int lua_callfunction (Object *function, int nparam) +{ + static Byte startcode[] = {CALLFUNC, HALT}; + int i; + if (tag(function) != T_FUNCTION) return 1; + for (i=1; i<=nparam; i++) + *(top-i+2) = *(top-i); + top += 2; + tag(top-nparam-1) = T_MARK; + *(top-nparam-2) = *function; + return (lua_execute (startcode)); +} + /* ** Get a parameter, returning the object handle or NULL on error. ** 'number' must be 1 to get the first parameter. @@ -953,6 +969,14 @@ int lua_istable (Object *object) return (object != NULL && tag(object) == T_ARRAY); } +/* +** Given an object handle, return if it is a lua function. +*/ +int lua_isfunction (Object *object) +{ + return (object != NULL && tag(object) == T_FUNCTION); +} + /* ** Given an object handle, return if it is a cfunction one. */ diff --git a/table.c b/table.c index 2fbcdc07..9ea24226 100644 --- a/table.c +++ b/table.c @@ -3,7 +3,7 @@ ** Module to control static tables */ -char *rcs_table="$Id: table.c,v 2.1 1994/04/20 22:07:57 celes Exp celes $"; +char *rcs_table="$Id: table.c,v 2.2 1994/07/19 21:27:18 celes Exp celes $"; #include #include @@ -23,11 +23,11 @@ char *rcs_table="$Id: table.c,v 2.1 1994/04/20 22:07:57 celes Exp celes $"; Symbol *lua_table; static Word lua_ntable = 0; -static Word lua_maxsymbol = 0; +static Long lua_maxsymbol = 0; char **lua_constant; static Word lua_nconstant = 0; -static Word lua_maxconstant = 0; +static Long lua_maxconstant = 0; -- cgit v1.2.3-55-g6feb