diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-04-02 19:52:42 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-04-02 19:52:42 -0300 |
commit | 27d95f18803aded238eaa8adaf7f2a3ee6966fd3 (patch) | |
tree | 7b20dbfac6b14aa2ca112bee48aac22c47db78dc | |
parent | f0d523887d28c569e931eacbe1078599750cd5b7 (diff) | |
download | lua-27d95f18803aded238eaa8adaf7f2a3ee6966fd3.tar.gz lua-27d95f18803aded238eaa8adaf7f2a3ee6966fd3.tar.bz2 lua-27d95f18803aded238eaa8adaf7f2a3ee6966fd3.zip |
"newtag" does not need a type name.
-rw-r--r-- | fallback.c | 59 | ||||
-rw-r--r-- | fallback.h | 5 | ||||
-rw-r--r-- | lua.h | 4 | ||||
-rw-r--r-- | opcode.c | 6 |
4 files changed, 25 insertions, 49 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_fallback="$Id: fallback.c,v 1.35 1997/03/31 14:17:09 roberto Exp roberto $"; | 6 | char *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 | ||
21 | static char *typenames[] = { /* ORDER LUA_T */ | ||
22 | "userdata", "line", "cmark", "mark", "function", | ||
23 | "function", "table", "string", "number", "nil", | ||
24 | NULL | ||
25 | }; | ||
26 | |||
27 | |||
28 | void 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 | ||
138 | static struct IM { | 123 | static 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 | ||
159 | static int validevent (lua_Type t, int e) | 143 | static 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 | ||
185 | int lua_newtag (char *t) | 167 | int 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 | ||
204 | static void checktag (int tag) | 180 | static 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 | ||
210 | lua_Type luaI_typetag (int tag) | 186 | int 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 | |||
219 | void luaI_settag (int tag, TObject *o) | 192 | void 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 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: fallback.h,v 1.18 1997/03/31 14:02:58 roberto Exp roberto $ | 2 | ** $Id: fallback.h,v 1.19 1997/03/31 20:59:09 roberto Exp roberto $ |
3 | */ | 3 | */ |
4 | 4 | ||
5 | #ifndef fallback_h | 5 | #ifndef fallback_h |
@@ -45,9 +45,8 @@ void luaI_travlock (int (*fn)(TObject *)); | |||
45 | void luaI_invalidaterefs (void); | 45 | void luaI_invalidaterefs (void); |
46 | char *luaI_travfallbacks (int (*fn)(TObject *)); | 46 | char *luaI_travfallbacks (int (*fn)(TObject *)); |
47 | 47 | ||
48 | void luaI_type (void); | ||
49 | void luaI_settag (int tag, TObject *o); | 48 | void luaI_settag (int tag, TObject *o); |
50 | lua_Type luaI_typetag (int tag); | 49 | int luaI_userdatatag (int tag); |
51 | TObject *luaI_getim (int tag, IMS event); | 50 | TObject *luaI_getim (int tag, IMS event); |
52 | #define luaI_getimbyObj(o,e) (luaI_getim(luaI_tag(o),(e))) | 51 | #define luaI_getimbyObj(o,e) (luaI_getim(luaI_tag(o),(e))) |
53 | TObject *luaI_geterrorim (void); | 52 | TObject *luaI_geterrorim (void); |
@@ -2,7 +2,7 @@ | |||
2 | ** LUA - Linguagem para Usuarios de Aplicacao | 2 | ** LUA - Linguagem para Usuarios de Aplicacao |
3 | ** Grupo de Tecnologia em Computacao Grafica | 3 | ** Grupo de Tecnologia em Computacao Grafica |
4 | ** TeCGraf - PUC-Rio | 4 | ** TeCGraf - PUC-Rio |
5 | ** $Id: lua.h,v 3.39 1997/04/01 19:02:43 roberto Exp roberto $ | 5 | ** $Id: lua.h,v 3.40 1997/04/02 17:44:18 roberto Exp roberto $ |
6 | */ | 6 | */ |
7 | 7 | ||
8 | 8 | ||
@@ -23,7 +23,7 @@ lua_Object lua_setfallback (char *event, lua_CFunction fallback); | |||
23 | void lua_setintmethod (int tag, char *event, lua_CFunction method); | 23 | void lua_setintmethod (int tag, char *event, lua_CFunction method); |
24 | void lua_seterrormethod (lua_CFunction method); | 24 | void lua_seterrormethod (lua_CFunction method); |
25 | 25 | ||
26 | int lua_newtag (char *t); | 26 | int lua_newtag (void); |
27 | void lua_settag (int tag); /* In: object */ | 27 | void lua_settag (int tag); /* In: object */ |
28 | 28 | ||
29 | void lua_error (char *s); | 29 | void lua_error (char *s); |
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_opcode="$Id: opcode.c,v 3.90 1997/04/01 19:02:43 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 3.91 1997/04/02 17:44:18 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
9 | #include <stdio.h> | 9 | #include <stdio.h> |
@@ -987,6 +987,8 @@ void lua_pushbinarydata (void *buff, int size, int tag) | |||
987 | if (buff == NULL) | 987 | if (buff == NULL) |
988 | ttype(top) = LUA_T_NIL; | 988 | ttype(top) = LUA_T_NIL; |
989 | else { | 989 | else { |
990 | if (!luaI_userdatatag(tag)) | ||
991 | lua_error("invalid tag for userdata"); | ||
990 | tsvalue(top) = luaI_createuserdata(buff, size, tag); | 992 | tsvalue(top) = luaI_createuserdata(buff, size, tag); |
991 | ttype(top) = LUA_T_USERDATA; | 993 | ttype(top) = LUA_T_USERDATA; |
992 | } | 994 | } |
@@ -998,8 +1000,6 @@ void lua_pushbinarydata (void *buff, int size, int tag) | |||
998 | */ | 1000 | */ |
999 | void lua_pushusertag (void *u, int tag) | 1001 | void lua_pushusertag (void *u, int tag) |
1000 | { | 1002 | { |
1001 | if (luaI_typetag(tag) != LUA_T_USERDATA) | ||
1002 | lua_error("invalid tag in `lua_pushusertag'"); | ||
1003 | lua_pushbinarydata(&u, sizeof(void *), tag); | 1003 | lua_pushbinarydata(&u, sizeof(void *), tag); |
1004 | } | 1004 | } |
1005 | 1005 | ||