aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-03-24 14:13:22 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-03-24 14:13:22 -0300
commit03d917f229107d788df93c940d87b5908194248a (patch)
tree6662f817a9314b0b7668687c7a721cbf7c62a81d
parentc3488f51152ea2705ef6a256de7756cbeaf044f6 (diff)
downloadlua-03d917f229107d788df93c940d87b5908194248a.tar.gz
lua-03d917f229107d788df93c940d87b5908194248a.tar.bz2
lua-03d917f229107d788df93c940d87b5908194248a.zip
some corrections, improvements;
-rw-r--r--fallback.c38
-rw-r--r--fallback.h4
2 files changed, 22 insertions, 20 deletions
diff --git a/fallback.c b/fallback.c
index d3c2745e..3e4d6c3b 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.31 1997/03/20 20:36:19 roberto Exp roberto $"; 6char *rcs_fallback="$Id: fallback.c,v 1.32 1997/03/21 18:37:28 roberto Exp roberto $";
7 7
8#include <stdio.h> 8#include <stdio.h>
9#include <string.h> 9#include <string.h>
@@ -28,6 +28,7 @@ static char *typenames[] = { /* ORDER LUA_T */
28void luaI_type (void) 28void luaI_type (void)
29{ 29{
30 lua_Object o = lua_getparam(1); 30 lua_Object o = lua_getparam(1);
31 luaL_arg_check(o != LUA_NOOBJECT, "type", 1, "no argument");
31 lua_pushstring(typenames[-ttype(luaI_Address(o))]); 32 lua_pushstring(typenames[-ttype(luaI_Address(o))]);
32 lua_pushnumber(lua_tag(o)); 33 lua_pushnumber(lua_tag(o));
33} 34}
@@ -125,15 +126,14 @@ static int findstring (char *name, char *list[])
125 for (i=0; list[i]; i++) 126 for (i=0; list[i]; i++)
126 if (strcmp(list[i], name) == 0) 127 if (strcmp(list[i], name) == 0)
127 return i; 128 return i;
128 /* name not found */ 129 return -1; /* name not found */
129 return -1;
130} 130}
131 131
132static int luaI_checkevent (char *name, char *list[]) 132static int luaI_checkevent (char *name, char *list[])
133{ 133{
134 int e = findstring(name, list); 134 int e = findstring(name, list);
135 if (e < 0) 135 if (e < 0)
136 lua_error("invalid event name"); 136 luaL_verror("invalid event name `%s'", name);
137 return e; 137 return e;
138} 138}
139 139
@@ -144,7 +144,7 @@ static struct IM {
144} *luaI_IMtable = NULL; 144} *luaI_IMtable = NULL;
145 145
146static int IMtable_size = 0; 146static int IMtable_size = 0;
147static int last_tag = LUA_T_NIL; 147static int last_tag = LUA_T_NIL; /* ORDER LUA_T */
148 148
149static char validevents[NUM_TYPES][IM_N] = { /* ORDER LUA_T, ORDER IM */ 149static char validevents[NUM_TYPES][IM_N] = { /* ORDER LUA_T, ORDER IM */
150{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* LUA_T_USERDATA */ 150{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* LUA_T_USERDATA */
@@ -204,12 +204,9 @@ int lua_newtag (char *t)
204} 204}
205 205
206 206
207#define validtag(tag) (last_tag <= (tag) && (tag) <= 0)
208
209
210static void checktag (int tag) 207static void checktag (int tag)
211{ 208{
212 if (!validtag(tag)) 209 if (!(last_tag <= (tag) && (tag) <= 0))
213 lua_error("invalid tag"); 210 lua_error("invalid tag");
214} 211}
215 212
@@ -232,6 +229,7 @@ void luaI_settag (int tag, Object *o)
232 o->value.ts->tag = tag; 229 o->value.ts->tag = tag;
233} 230}
234 231
232
235int luaI_tag (Object *o) 233int luaI_tag (Object *o)
236{ 234{
237 lua_Type t = ttype(o); 235 lua_Type t = ttype(o);
@@ -242,6 +240,7 @@ int luaI_tag (Object *o)
242 else return t; 240 else return t;
243} 241}
244 242
243
245Object *luaI_getim (int tag, IMS event) 244Object *luaI_getim (int tag, IMS event)
246{ 245{
247 if (tag > LUA_T_USERDATA) 246 if (tag > LUA_T_USERDATA)
@@ -249,10 +248,6 @@ Object *luaI_getim (int tag, IMS event)
249 return &luaI_IMtable[-tag].int_method[event]; 248 return &luaI_IMtable[-tag].int_method[event];
250} 249}
251 250
252Object *luaI_getimbyObj (Object *o, IMS event)
253{
254 return luaI_getim(luaI_tag(o), event);
255}
256 251
257void luaI_setintmethod (void) 252void luaI_setintmethod (void)
258{ 253{
@@ -288,11 +283,18 @@ void luaI_setglobalmethod (void)
288} 283}
289 284
290char *luaI_travfallbacks (int (*fn)(Object *)) 285char *luaI_travfallbacks (int (*fn)(Object *))
291{ /* ?????????? 286{
292 int i; 287 int e;
293 for (i=0; i<N_FB; i++) 288 for (e=GIM_ERROR; e<=GIM_SETGLOBAL; e++) { /* ORDER GIM */
294 if (fn(&luaI_fallBacks[i].function)) 289 if (fn(&gmethod[e]))
295 return luaI_fallBacks[i].kind; */ 290 return geventname[e];
291 }
292 for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) { /* ORDER IM */
293 int t;
294 for (t=0; t>=last_tag; t--)
295 if (fn(&luaI_IMtable[-t].int_method[e]))
296 return luaI_eventname[e];
297 }
296 return NULL; 298 return NULL;
297} 299}
298 300
diff --git a/fallback.h b/fallback.h
index ea071191..6442680a 100644
--- a/fallback.h
+++ b/fallback.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: fallback.h,v 1.15 1997/03/19 19:41:10 roberto Exp roberto $ 2** $Id: fallback.h,v 1.16 1997/03/20 19:20:43 roberto Exp roberto $
3*/ 3*/
4 4
5#ifndef fallback_h 5#ifndef fallback_h
@@ -59,8 +59,8 @@ void luaI_type (void);
59void luaI_settag (int tag, Object *o); 59void luaI_settag (int tag, Object *o);
60lua_Type luaI_typetag (int tag); 60lua_Type luaI_typetag (int tag);
61Object *luaI_getim (int tag, IMS event); 61Object *luaI_getim (int tag, IMS event);
62#define luaI_getimbyObj(o,e) (luaI_getim(luaI_tag(o),(e)))
62Object *luaI_getgim (IMGS event); 63Object *luaI_getgim (IMGS event);
63Object *luaI_getimbyObj (Object *o, IMS event);
64int luaI_tag (Object *o); 64int luaI_tag (Object *o);
65void luaI_setintmethod (void); 65void luaI_setintmethod (void);
66void luaI_setglobalmethod (void); 66void luaI_setglobalmethod (void);