summaryrefslogtreecommitdiff
path: root/ltm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-01-15 11:11:57 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-01-15 11:11:57 -0200
commit3fecf187ffda02ff7a18cfb8b0d340e2c0e77310 (patch)
tree32baa09deeed673549982b6499effd2ab44a980b /ltm.c
parent54840fb25696ab30e11d2d80f3c18af6d1f01481 (diff)
downloadlua-3fecf187ffda02ff7a18cfb8b0d340e2c0e77310.tar.gz
lua-3fecf187ffda02ff7a18cfb8b0d340e2c0e77310.tar.bz2
lua-3fecf187ffda02ff7a18cfb8b0d340e2c0e77310.zip
names...
Diffstat (limited to 'ltm.c')
-rw-r--r--ltm.c56
1 files changed, 21 insertions, 35 deletions
diff --git a/ltm.c b/ltm.c
index f061e56c..fdb8f024 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 1.18 1998/12/22 18:10:50 roberto Exp roberto $ 2** $Id: ltm.c,v 1.19 1999/01/13 19:08:10 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -22,8 +22,7 @@ char *luaT_eventname[] = { /* ORDER IM */
22}; 22};
23 23
24 24
25static int luaI_checkevent (char *name, char *list[]) 25static int luaI_checkevent (char *name, char *list[]) {
26{
27 int e = luaL_findstring(name, list); 26 int e = luaL_findstring(name, list);
28 if (e < 0) 27 if (e < 0)
29 luaL_verror("`%.50s' is not a valid event name", name); 28 luaL_verror("`%.50s' is not a valid event name", name);
@@ -35,7 +34,7 @@ static int luaI_checkevent (char *name, char *list[])
35/* events in LUA_T_NIL are all allowed, since this is used as a 34/* events in LUA_T_NIL are all allowed, since this is used as a
36* 'placeholder' for "default" fallbacks 35* 'placeholder' for "default" fallbacks
37*/ 36*/
38static char validevents[NUM_TAGS][IM_N] = { /* ORDER LUA_T, ORDER IM */ 37static char luaT_validevents[NUM_TAGS][IM_N] = { /* ORDER LUA_T, ORDER IM */
39{1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_T_USERDATA */ 38{1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_T_USERDATA */
40{1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_NUMBER */ 39{1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_NUMBER */
41{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_STRING */ 40{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_T_STRING */
@@ -45,22 +44,19 @@ static char validevents[NUM_TAGS][IM_N] = { /* ORDER LUA_T, ORDER IM */
45{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} /* LUA_T_NIL */ 44{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} /* LUA_T_NIL */
46}; 45};
47 46
48 47static int luaT_validevent (int t, int e) { /* ORDER LUA_T */
49static int validevent (int t, int e) { /* ORDER LUA_T */ 48 return (t < LUA_T_NIL) ? 1 : luaT_validevents[-t][e];
50 return (t < LUA_T_NIL) ? 1 : validevents[-t][e];
51} 49}
52 50
53 51
54static void init_entry (int tag) 52static void init_entry (int tag) {
55{
56 int i; 53 int i;
57 for (i=0; i<IM_N; i++) 54 for (i=0; i<IM_N; i++)
58 ttype(luaT_getim(tag, i)) = LUA_T_NIL; 55 ttype(luaT_getim(tag, i)) = LUA_T_NIL;
59} 56}
60 57
61 58
62void luaT_init (void) 59void luaT_init (void) {
63{
64 int t; 60 int t;
65 L->IMtable_size = NUM_TAGS*2; 61 L->IMtable_size = NUM_TAGS*2;
66 L->last_tag = -(NUM_TAGS-1); 62 L->last_tag = -(NUM_TAGS-1);
@@ -70,8 +66,7 @@ void luaT_init (void)
70} 66}
71 67
72 68
73int lua_newtag (void) 69int lua_newtag (void) {
74{
75 --L->last_tag; 70 --L->last_tag;
76 if ((-L->last_tag) >= L->IMtable_size) 71 if ((-L->last_tag) >= L->IMtable_size)
77 L->IMtable_size = luaM_growvector(&L->IMtable, L->IMtable_size, 72 L->IMtable_size = luaM_growvector(&L->IMtable, L->IMtable_size,
@@ -81,34 +76,30 @@ int lua_newtag (void)
81} 76}
82 77
83 78
84static void checktag (int tag) 79static void checktag (int tag) {
85{
86 if (!(L->last_tag <= tag && tag <= 0)) 80 if (!(L->last_tag <= tag && tag <= 0))
87 luaL_verror("%d is not a valid tag", tag); 81 luaL_verror("%d is not a valid tag", tag);
88} 82}
89 83
90void luaT_realtag (int tag) 84void luaT_realtag (int tag) {
91{
92 if (!(L->last_tag <= tag && tag < LUA_T_NIL)) 85 if (!(L->last_tag <= tag && tag < LUA_T_NIL))
93 luaL_verror("tag %d is not result of `newtag'", tag); 86 luaL_verror("tag %d is not result of `newtag'", tag);
94} 87}
95 88
96 89
97int lua_copytagmethods (int tagto, int tagfrom) 90int lua_copytagmethods (int tagto, int tagfrom) {
98{
99 int e; 91 int e;
100 checktag(tagto); 92 checktag(tagto);
101 checktag(tagfrom); 93 checktag(tagfrom);
102 for (e=0; e<IM_N; e++) { 94 for (e=0; e<IM_N; e++) {
103 if (validevent(tagto, e)) 95 if (luaT_validevent(tagto, e))
104 *luaT_getim(tagto, e) = *luaT_getim(tagfrom, e); 96 *luaT_getim(tagto, e) = *luaT_getim(tagfrom, e);
105 } 97 }
106 return tagto; 98 return tagto;
107} 99}
108 100
109 101
110int luaT_efectivetag (TObject *o) 102int luaT_effectivetag (TObject *o) {
111{
112 int t; 103 int t;
113 switch (t = ttype(o)) { 104 switch (t = ttype(o)) {
114 case LUA_T_ARRAY: 105 case LUA_T_ARRAY:
@@ -130,23 +121,21 @@ int luaT_efectivetag (TObject *o)
130} 121}
131 122
132 123
133TObject *luaT_gettagmethod (int t, char *event) 124TObject *luaT_gettagmethod (int t, char *event) {
134{
135 int e = luaI_checkevent(event, luaT_eventname); 125 int e = luaI_checkevent(event, luaT_eventname);
136 checktag(t); 126 checktag(t);
137 if (validevent(t, e)) 127 if (luaT_validevent(t, e))
138 return luaT_getim(t,e); 128 return luaT_getim(t,e);
139 else 129 else
140 return &luaO_nilobject; 130 return &luaO_nilobject;
141} 131}
142 132
143 133
144void luaT_settagmethod (int t, char *event, TObject *func) 134void luaT_settagmethod (int t, char *event, TObject *func) {
145{
146 TObject temp = *func; 135 TObject temp = *func;
147 int e = luaI_checkevent(event, luaT_eventname); 136 int e = luaI_checkevent(event, luaT_eventname);
148 checktag(t); 137 checktag(t);
149 if (!validevent(t, e)) 138 if (!luaT_validevent(t, e))
150 luaL_verror("cannot change tag method `%.20s' for type `%.20s'%.20s", 139 luaL_verror("cannot change tag method `%.20s' for type `%.20s'%.20s",
151 luaT_eventname[e], luaO_typenames[-t], 140 luaT_eventname[e], luaO_typenames[-t],
152 (t == LUA_T_ARRAY || t == LUA_T_USERDATA) ? " with default tag" 141 (t == LUA_T_ARRAY || t == LUA_T_USERDATA) ? " with default tag"
@@ -189,23 +178,20 @@ static void errorFB (void)
189static void nilFB (void) { } 178static void nilFB (void) { }
190 179
191 180
192static void typeFB (void) 181static void typeFB (void) {
193{
194 lua_error("unexpected type"); 182 lua_error("unexpected type");
195} 183}
196 184
197 185
198static void fillvalids (IMS e, TObject *func) 186static void fillvalids (IMS e, TObject *func) {
199{
200 int t; 187 int t;
201 for (t=LUA_T_NIL; t<=LUA_T_USERDATA; t++) 188 for (t=LUA_T_NIL; t<=LUA_T_USERDATA; t++)
202 if (validevent(t, e)) 189 if (luaT_validevent(t, e))
203 *luaT_getim(t, e) = *func; 190 *luaT_getim(t, e) = *func;
204} 191}
205 192
206 193
207void luaT_setfallback (void) 194void luaT_setfallback (void) {
208{
209 static char *oldnames [] = {"error", "getglobal", "arith", "order", NULL}; 195 static char *oldnames [] = {"error", "getglobal", "arith", "order", NULL};
210 TObject oldfunc; 196 TObject oldfunc;
211 lua_CFunction replace; 197 lua_CFunction replace;