aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWaldemar Celes <celes@tecgraf.puc-rio.br>1994-08-03 11:15:46 -0300
committerWaldemar Celes <celes@tecgraf.puc-rio.br>1994-08-03 11:15:46 -0300
commitb1e9b37883ebc3f9926f6693350a73d6cbb94b6e (patch)
tree600f3e33d0dd976b0c2d6c86489f22ebcd129301
parent467288e5b35d6f264bdded9b4d09dbaa0597f967 (diff)
downloadlua-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.h4
-rw-r--r--lua.stx14
-rw-r--r--opcode.c28
-rw-r--r--table.c6
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 @@
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);
20int lua_dofile (char *filename); 20int lua_dofile (char *filename);
21int lua_dostring (char *string); 21int lua_dostring (char *string);
22int lua_call (char *functionname, int nparam); 22int lua_call (char *functionname, int nparam);
23int lua_callfunction (lua_Object function, int nparam);
23 24
24lua_Object lua_getparam (int number); 25lua_Object lua_getparam (int number);
25float lua_getnumber (lua_Object object); 26float lua_getnumber (lua_Object object);
@@ -48,6 +49,7 @@ int lua_isnil (lua_Object object);
48int lua_isnumber (lua_Object object); 49int lua_isnumber (lua_Object object);
49int lua_isstring (lua_Object object); 50int lua_isstring (lua_Object object);
50int lua_istable (lua_Object object); 51int lua_istable (lua_Object object);
52int lua_isfunction (lua_Object object);
51int lua_iscfunction (lua_Object object); 53int lua_iscfunction (lua_Object object);
52int lua_isuserdata (lua_Object object); 54int lua_isuserdata (lua_Object object);
53 55
diff --git a/lua.stx b/lua.stx
index 6c7c9791..f3d6776b 100644
--- a/lua.stx
+++ b/lua.stx
@@ -1,6 +1,6 @@
1%{ 1%{
2 2
3char *rcs_luastx = "$Id: lua.stx,v 2.4 1994/04/20 16:22:21 celes Exp celes $"; 3char *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
460typeconstructor: '@' 466typeconstructor: '@'
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;
diff --git a/opcode.c b/opcode.c
index 2309bed1..b2f5cb41 100644
--- a/opcode.c
+++ b/opcode.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_opcode="$Id: opcode.c,v 2.1 1994/04/20 22:07:57 celes Exp celes $"; 6char *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
29static Word maxstack; 29static Long maxstack;
30static Object *stack=NULL; 30static Object *stack=NULL;
31static Object *top, *base; 31static 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*/
689int 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*/
975int 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*/
959int lua_iscfunction (Object *object) 983int lua_iscfunction (Object *object)
diff --git a/table.c b/table.c
index 2fbcdc07..9ea24226 100644
--- a/table.c
+++ b/table.c
@@ -3,7 +3,7 @@
3** Module to control static tables 3** Module to control static tables
4*/ 4*/
5 5
6char *rcs_table="$Id: table.c,v 2.1 1994/04/20 22:07:57 celes Exp celes $"; 6char *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
24Symbol *lua_table; 24Symbol *lua_table;
25static Word lua_ntable = 0; 25static Word lua_ntable = 0;
26static Word lua_maxsymbol = 0; 26static Long lua_maxsymbol = 0;
27 27
28char **lua_constant; 28char **lua_constant;
29static Word lua_nconstant = 0; 29static Word lua_nconstant = 0;
30static Word lua_maxconstant = 0; 30static Long lua_maxconstant = 0;
31 31
32 32
33 33