aboutsummaryrefslogtreecommitdiff
path: root/table.c
diff options
context:
space:
mode:
Diffstat (limited to 'table.c')
-rw-r--r--table.c76
1 files changed, 38 insertions, 38 deletions
diff --git a/table.c b/table.c
index 29d877c2..614a5c5e 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.44 1996/01/26 18:03:19 roberto Exp $"; 6char *rcs_table="$Id: table.c,v 2.45 1996/02/12 18:32:40 roberto Exp roberto $";
7 7
8/*#include <string.h>*/ 8/*#include <string.h>*/
9 9
@@ -37,44 +37,44 @@ static void lua_nextvar (void);
37/* 37/*
38** Initialise symbol table with internal functions 38** Initialise symbol table with internal functions
39*/ 39*/
40static void lua_initsymbol (void) 40static struct {
41 char *name;
42 lua_CFunction func;
43} int_funcs[] = {
44 {"nextvar", lua_nextvar},
45 {"error", luaI_error},
46 {"tonumber", lua_obj2number},
47 {"setfallback", luaI_setfallback},
48 {"next", lua_next},
49 {"dofile", lua_internaldofile},
50 {"setglobal", luaI_setglobal},
51 {"getglobal", luaI_getglobal},
52 {"type", luaI_type},
53 {"tostring", luaI_tostring},
54 {"print", luaI_print},
55 {"dostring", lua_internaldostring},
56 {"assert", luaI_assert}
57};
58
59#define INTFUNCSIZE (sizeof(int_funcs)/sizeof(int_funcs[0]))
60
61void luaI_initsymbol (void)
41{ 62{
42 Word n; 63 int i;
43 lua_maxsymbol = BUFFER_BLOCK; 64 lua_maxsymbol = BUFFER_BLOCK;
44 lua_table = newvector(lua_maxsymbol, Symbol); 65 lua_table = newvector(lua_maxsymbol, Symbol);
45 n = luaI_findsymbolbyname("nextvar"); 66 for (i=0; i<INTFUNCSIZE; i++)
46 s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_nextvar; 67 {
47 n = luaI_findsymbolbyname("error"); 68 Word n = luaI_findsymbolbyname(int_funcs[i].name);
48 s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_error; 69 s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = int_funcs[i].func;
49 n = luaI_findsymbolbyname("tonumber"); 70 }
50 s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_obj2number;
51 n = luaI_findsymbolbyname("setfallback");
52 s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_setfallback;
53 n = luaI_findsymbolbyname("next");
54 s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_next;
55 n = luaI_findsymbolbyname("dofile");
56 s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_internaldofile;
57 n = luaI_findsymbolbyname("setglobal");
58 s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_setglobal;
59 n = luaI_findsymbolbyname("getglobal");
60 s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_getglobal;
61 n = luaI_findsymbolbyname("type");
62 s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_type;
63 n = luaI_findsymbolbyname("tostring");
64 s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_tostring;
65 n = luaI_findsymbolbyname("print");
66 s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_print;
67 n = luaI_findsymbolbyname("dostring");
68 s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_internaldostring;
69 n = luaI_findsymbolbyname("assert");
70 s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = luaI_assert;
71} 71}
72 72
73 73
74/* 74/*
75** Initialise constant table with pre-defined constants 75** Initialise constant table with pre-defined constants
76*/ 76*/
77void lua_initconstant (void) 77void luaI_initconstant (void)
78{ 78{
79 lua_maxconstant = BUFFER_BLOCK; 79 lua_maxconstant = BUFFER_BLOCK;
80 lua_constant = newvector(lua_maxconstant, TaggedString *); 80 lua_constant = newvector(lua_maxconstant, TaggedString *);
@@ -87,8 +87,6 @@ void lua_initconstant (void)
87*/ 87*/
88Word luaI_findsymbol (TaggedString *t) 88Word luaI_findsymbol (TaggedString *t)
89{ 89{
90 if (lua_table == NULL)
91 lua_initsymbol();
92 if (t->varindex == NOT_USED) 90 if (t->varindex == NOT_USED)
93 { 91 {
94 if (lua_ntable == lua_maxsymbol) 92 if (lua_ntable == lua_maxsymbol)
@@ -104,6 +102,8 @@ Word luaI_findsymbol (TaggedString *t)
104 lua_table[lua_ntable].varname = t; 102 lua_table[lua_ntable].varname = t;
105 s_tag(lua_ntable) = LUA_T_NIL; 103 s_tag(lua_ntable) = LUA_T_NIL;
106 lua_ntable++; 104 lua_ntable++;
105 if (!t->marked)
106 t->marked = 2; /* avoid GC */
107 } 107 }
108 return t->varindex; 108 return t->varindex;
109} 109}
@@ -111,7 +111,7 @@ Word luaI_findsymbol (TaggedString *t)
111 111
112Word luaI_findsymbolbyname (char *name) 112Word luaI_findsymbolbyname (char *name)
113{ 113{
114 return luaI_findsymbol(luaI_createfixedstring(name)); 114 return luaI_findsymbol(lua_createstring(name));
115} 115}
116 116
117 117
@@ -121,8 +121,6 @@ Word luaI_findsymbolbyname (char *name)
121*/ 121*/
122Word luaI_findconstant (TaggedString *t) 122Word luaI_findconstant (TaggedString *t)
123{ 123{
124 if (lua_constant == NULL)
125 lua_initconstant();
126 if (t->constindex == NOT_USED) 124 if (t->constindex == NOT_USED)
127 { 125 {
128 if (lua_nconstant == lua_maxconstant) 126 if (lua_nconstant == lua_maxconstant)
@@ -137,6 +135,8 @@ Word luaI_findconstant (TaggedString *t)
137 t->constindex = lua_nconstant; 135 t->constindex = lua_nconstant;
138 lua_constant[lua_nconstant] = t; 136 lua_constant[lua_nconstant] = t;
139 lua_nconstant++; 137 lua_nconstant++;
138 if (!t->marked)
139 t->marked = 2; /* avoid GC */
140 } 140 }
141 return t->constindex; 141 return t->constindex;
142} 142}
@@ -144,7 +144,7 @@ Word luaI_findconstant (TaggedString *t)
144 144
145Word luaI_findconstantbyname (char *name) 145Word luaI_findconstantbyname (char *name)
146{ 146{
147 return luaI_findconstant(luaI_createfixedstring(name)); 147 return luaI_findconstant(lua_createstring(name));
148} 148}
149 149
150TaggedString *lua_constcreate(char *name) 150TaggedString *lua_constcreate(char *name)