aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWaldemar Celes <celes@tecgraf.puc-rio.br>1993-12-17 16:41:19 -0200
committerWaldemar Celes <celes@tecgraf.puc-rio.br>1993-12-17 16:41:19 -0200
commit4478f0ce92861e526b35e8889a8ce2706fc78fd1 (patch)
tree2a93db6b7628caa91c222d04448c40cae6252077
parent64097041c48070deb2e9d88c55efb41ba77cdd9b (diff)
downloadlua-4478f0ce92861e526b35e8889a8ce2706fc78fd1.tar.gz
lua-4478f0ce92861e526b35e8889a8ce2706fc78fd1.tar.bz2
lua-4478f0ce92861e526b35e8889a8ce2706fc78fd1.zip
Module to control static tables
-rw-r--r--table.c77
-rw-r--r--table.h4
2 files changed, 60 insertions, 21 deletions
diff --git a/table.c b/table.c
index 3bae7ebd..8b425e2f 100644
--- a/table.c
+++ b/table.c
@@ -1,10 +1,10 @@
1/* 1/*
2** table.c 2** table.c
3** Module to control static tables 3** Module to control static tables
4** TeCGraf - PUC-Rio
5** 11 May 93
6*/ 4*/
7 5
6char *rcs_table="$Id: $";
7
8#include <stdlib.h> 8#include <stdlib.h>
9#include <string.h> 9#include <string.h>
10 10
@@ -14,7 +14,7 @@
14#include "table.h" 14#include "table.h"
15#include "lua.h" 15#include "lua.h"
16 16
17#define streq(s1,s2) (strcmp(s1,s2)==0) 17#define streq(s1,s2) (s1[0]==s2[0]&&strcmp(s1+1,s2+1)==0)
18 18
19#ifndef MAXSYMBOL 19#ifndef MAXSYMBOL
20#define MAXSYMBOL 512 20#define MAXSYMBOL 512
@@ -24,10 +24,27 @@ static Symbol tablebuffer[MAXSYMBOL] = {
24 {"tonumber",{T_CFUNCTION,{lua_obj2number}}}, 24 {"tonumber",{T_CFUNCTION,{lua_obj2number}}},
25 {"next",{T_CFUNCTION,{lua_next}}}, 25 {"next",{T_CFUNCTION,{lua_next}}},
26 {"nextvar",{T_CFUNCTION,{lua_nextvar}}}, 26 {"nextvar",{T_CFUNCTION,{lua_nextvar}}},
27 {"print",{T_CFUNCTION,{lua_print}}} 27 {"print",{T_CFUNCTION,{lua_print}}},
28 {"dofile",{T_CFUNCTION,{lua_internaldofile}}},
29 {"dostring",{T_CFUNCTION,{lua_internaldostring}}}
28 }; 30 };
29Symbol *lua_table=tablebuffer; 31Symbol *lua_table=tablebuffer;
30Word lua_ntable=5; 32Word lua_ntable=7;
33
34struct List
35{
36 Symbol *s;
37 struct List *next;
38};
39
40static struct List o6={ tablebuffer+6, 0};
41static struct List o5={ tablebuffer+5, &o6 };
42static struct List o4={ tablebuffer+4, &o5 };
43static struct List o3={ tablebuffer+3, &o4 };
44static struct List o2={ tablebuffer+2, &o3 };
45static struct List o1={ tablebuffer+1, &o2 };
46static struct List o0={ tablebuffer+0, &o1 };
47static struct List *searchlist=&o0;
31 48
32#ifndef MAXCONSTANT 49#ifndef MAXCONSTANT
33#define MAXCONSTANT 256 50#define MAXCONSTANT 256
@@ -65,10 +82,19 @@ int lua_nfile;
65*/ 82*/
66int lua_findsymbol (char *s) 83int lua_findsymbol (char *s)
67{ 84{
68 int i; 85 struct List *l, *p;
69 for (i=0; i<lua_ntable; i++) 86 for (p=NULL, l=searchlist; l!=NULL; p=l, l=l->next)
70 if (streq(s,s_name(i))) 87 if (streq(s,l->s->name))
71 return i; 88 {
89 if (p!=NULL)
90 {
91 p->next = l->next;
92 l->next = searchlist;
93 searchlist = l;
94 }
95 return (l->s-lua_table);
96 }
97
72 if (lua_ntable >= MAXSYMBOL-1) 98 if (lua_ntable >= MAXSYMBOL-1)
73 { 99 {
74 lua_error ("symbol table overflow"); 100 lua_error ("symbol table overflow");
@@ -80,9 +106,13 @@ int lua_findsymbol (char *s)
80 lua_error ("not enough memory"); 106 lua_error ("not enough memory");
81 return -1; 107 return -1;
82 } 108 }
83 s_tag(lua_ntable++) = T_NIL; 109 s_tag(lua_ntable) = T_NIL;
84 110 p = malloc(sizeof(*p));
85 return (lua_ntable-1); 111 p->s = lua_table+lua_ntable;
112 p->next = searchlist;
113 searchlist = p;
114
115 return lua_ntable++;
86} 116}
87 117
88/* 118/*
@@ -108,12 +138,12 @@ int lua_findenclosedconstant (char *s)
108 { 138 {
109 if (s[i] == '\\') 139 if (s[i] == '\\')
110 { 140 {
111 switch (s[++i]) 141 switch (s[i+1])
112 { 142 {
113 case 'n': c[j++] = '\n'; break; 143 case 'n': c[j++] = '\n'; i++; break;
114 case 't': c[j++] = '\t'; break; 144 case 't': c[j++] = '\t'; i++; break;
115 case 'r': c[j++] = '\r'; break; 145 case 'r': c[j++] = '\r'; i++; break;
116 default : c[j++] = '\\'; c[j++] = c[i]; break; 146 default : c[j++] = '\\'; break;
117 } 147 }
118 } 148 }
119 else 149 else
@@ -295,6 +325,15 @@ int lua_addfile (char *fn)
295} 325}
296 326
297/* 327/*
328** Delete a file from file stack
329*/
330int lua_delfile (void)
331{
332 lua_nfile--;
333 return 1;
334}
335
336/*
298** Return the last file name set. 337** Return the last file name set.
299*/ 338*/
300char *lua_filename (void) 339char *lua_filename (void)
@@ -332,9 +371,9 @@ void lua_nextvar (void)
332 return; 371 return;
333 } 372 }
334 index++; 373 index++;
335 while (index < lua_ntable-1 && tag(&s_object(index)) == T_NIL) index++; 374 while (index < lua_ntable && tag(&s_object(index)) == T_NIL) index++;
336 375
337 if (index == lua_ntable-1) 376 if (index == lua_ntable)
338 { 377 {
339 lua_pushnil(); 378 lua_pushnil();
340 lua_pushnil(); 379 lua_pushnil();
diff --git a/table.h b/table.h
index 8406ee22..1941fb28 100644
--- a/table.h
+++ b/table.h
@@ -1,8 +1,7 @@
1/* 1/*
2** table.c
3** Module to control static tables 2** Module to control static tables
4** TeCGraf - PUC-Rio 3** TeCGraf - PUC-Rio
5** 11 May 93 4** $Id: $
6*/ 5*/
7 6
8#ifndef table_h 7#ifndef table_h
@@ -33,6 +32,7 @@ void lua_markobject (Object *o);
33char *lua_createstring (char *s); 32char *lua_createstring (char *s);
34void *lua_createarray (void *a); 33void *lua_createarray (void *a);
35int lua_addfile (char *fn); 34int lua_addfile (char *fn);
35int lua_delfile (void);
36char *lua_filename (void); 36char *lua_filename (void);
37void lua_nextvar (void); 37void lua_nextvar (void);
38 38