Browse Source

Implementacao de funcoes para tratar Lua function em C e
correcoes de bugs nas tabelas dinamicas.

Waldemar Celes 31 years ago
parent
commit
b1e9b37883
4 changed files with 42 additions and 10 deletions
  1. 3 1
      lua.h
  2. 10 4
      lua.stx
  3. 26 2
      opcode.c
  4. 3 3
      table.c

+ 3 - 1
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);
 

+ 10 - 4
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 <stdio.h>
 #include <stdlib.h>
@@ -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);
-      $<vLong>$ = pc; code_byte(0);
+      code_byte(PUSHWORD);
+      $<vLong>$ = pc; code_word(0);
       incr_ntemp();
       code_byte(CREATEARRAY);
      }
       objectname fieldlist 
      {
-      basepc[$<vLong>2] = $4; 
+      code_word_at(basepc+$<vLong>2, $4);
       if ($3 < 0)	/* there is no function to be called */
       {
        $$ = 1;

+ 26 - 2
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 <stdio.h>
 #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 $";
 
 #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.
 */

+ 3 - 3
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 <stdlib.h>
 #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 $";
 
 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;