aboutsummaryrefslogtreecommitdiff
path: root/fallback.c
diff options
context:
space:
mode:
Diffstat (limited to 'fallback.c')
-rw-r--r--fallback.c59
1 files changed, 18 insertions, 41 deletions
diff --git a/fallback.c b/fallback.c
index 2e40f973..c86d04cd 100644
--- a/fallback.c
+++ b/fallback.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_fallback="$Id: fallback.c,v 1.35 1997/03/31 14:17:09 roberto Exp roberto $"; 6char *rcs_fallback="$Id: fallback.c,v 1.36 1997/03/31 20:59:09 roberto Exp roberto $";
7 7
8#include <stdio.h> 8#include <stdio.h>
9#include <string.h> 9#include <string.h>
@@ -18,21 +18,6 @@ char *rcs_fallback="$Id: fallback.c,v 1.35 1997/03/31 14:17:09 roberto Exp rober
18#include "hash.h" 18#include "hash.h"
19 19
20 20
21static char *typenames[] = { /* ORDER LUA_T */
22 "userdata", "line", "cmark", "mark", "function",
23 "function", "table", "string", "number", "nil",
24 NULL
25};
26
27
28void luaI_type (void)
29{
30 lua_Object o = lua_getparam(1);
31 luaL_arg_check(o != LUA_NOOBJECT, "type", 1, "no argument");
32 lua_pushstring(typenames[-ttype(luaI_Address(o))]);
33 lua_pushnumber(lua_tag(o));
34}
35
36 21
37/* ------------------------------------------- 22/* -------------------------------------------
38** Reference routines 23** Reference routines
@@ -136,7 +121,6 @@ static int luaI_checkevent (char *name, char *list[])
136 121
137 122
138static struct IM { 123static struct IM {
139 lua_Type tp;
140 TObject int_method[IM_N]; 124 TObject int_method[IM_N];
141} *luaI_IMtable = NULL; 125} *luaI_IMtable = NULL;
142 126
@@ -157,7 +141,7 @@ static char validevents[NUM_TYPES][IM_N] = { /* ORDER LUA_T, ORDER IM */
157}; 141};
158 142
159static int validevent (lua_Type t, int e) 143static int validevent (lua_Type t, int e)
160{ 144{ /* ORDER LUA_T */
161 return (t < LUA_T_NIL) ? 1 : validevents[-t][e]; 145 return (t < LUA_T_NIL) ? 1 : validevents[-t][e];
162} 146}
163 147
@@ -175,27 +159,19 @@ void luaI_initfallbacks (void)
175 int i; 159 int i;
176 IMtable_size = NUM_TYPES+10; 160 IMtable_size = NUM_TYPES+10;
177 luaI_IMtable = newvector(IMtable_size, struct IM); 161 luaI_IMtable = newvector(IMtable_size, struct IM);
178 for (i=LUA_T_NIL; i<=LUA_T_USERDATA; i++) { 162 for (i=LUA_T_NIL; i<=LUA_T_USERDATA; i++)
179 luaI_IMtable[-i].tp = (lua_Type)i;
180 init_entry(i); 163 init_entry(i);
181 }
182 } 164 }
183} 165}
184 166
185int lua_newtag (char *t) 167int lua_newtag (void)
186{ 168{
187 int tp;
188 --last_tag; 169 --last_tag;
189 if ((-last_tag) >= IMtable_size) { 170 if ((-last_tag) >= IMtable_size) {
190 luaI_initfallbacks(); 171 luaI_initfallbacks();
191 IMtable_size = growvector(&luaI_IMtable, IMtable_size, 172 IMtable_size = growvector(&luaI_IMtable, IMtable_size,
192 struct IM, memEM, MAX_INT); 173 struct IM, memEM, MAX_INT);
193 } 174 }
194 tp = -findstring(t, typenames);
195 if (tp == LUA_T_ARRAY || tp == LUA_T_USERDATA)
196 luaI_IMtable[-last_tag].tp = tp;
197 else
198 lua_error("invalid type for new tag");
199 init_entry(last_tag); 175 init_entry(last_tag);
200 return last_tag; 176 return last_tag;
201} 177}
@@ -203,27 +179,28 @@ int lua_newtag (char *t)
203 179
204static void checktag (int tag) 180static void checktag (int tag)
205{ 181{
206 if (!(last_tag <= (tag) && (tag) <= 0)) 182 if (!(last_tag <= tag && tag <= 0))
207 lua_error("invalid tag"); 183 lua_error("invalid tag");
208} 184}
209 185
210lua_Type luaI_typetag (int tag) 186int luaI_userdatatag (int tag)
211{ 187{
212 if (tag >= 0) return LUA_T_USERDATA; 188 return (tag >= 0 || (last_tag <= tag && tag < LUA_T_NIL));
213 else {
214 checktag(tag);
215 return luaI_IMtable[-tag].tp;
216 }
217} 189}
218 190
191
219void luaI_settag (int tag, TObject *o) 192void luaI_settag (int tag, TObject *o)
220{ 193{
221 if (ttype(o) != luaI_typetag(tag)) 194 switch (ttype(o)) {
222 lua_error("Tag is not compatible with this type"); 195 case LUA_T_ARRAY:
223 if (o->ttype == LUA_T_ARRAY) 196 o->value.a->htag = tag;
224 o->value.a->htag = tag; 197 break;
225 else /* must be userdata */ 198 case LUA_T_USERDATA:
226 o->value.ts->tag = tag; 199 o->value.ts->tag = tag;
200 break;
201 default:
202 lua_error("settag: cannot change tag of given object");
203 }
227} 204}
228 205
229 206