aboutsummaryrefslogtreecommitdiff
path: root/ltm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-05 09:14:08 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-05 09:14:08 -0300
commit001f2bdd0e2f8803889c1b5164b57a51e44aef5b (patch)
treed200cf4d708be3c61e64640c45b47050c9c6a375 /ltm.c
parentcd2ddaded97f7f2b2af02cecfd165cf70e6f83f4 (diff)
downloadlua-001f2bdd0e2f8803889c1b5164b57a51e44aef5b.tar.gz
lua-001f2bdd0e2f8803889c1b5164b57a51e44aef5b.tar.bz2
lua-001f2bdd0e2f8803889c1b5164b57a51e44aef5b.zip
new definition for types-tags
Diffstat (limited to 'ltm.c')
-rw-r--r--ltm.c49
1 files changed, 20 insertions, 29 deletions
diff --git a/ltm.c b/ltm.c
index b009e8b4..1dfc8a72 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 1.51 2000/10/02 20:10:55 roberto Exp roberto $ 2** $Id: ltm.c,v 1.52 2000/10/03 14:27:44 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*/
@@ -38,7 +38,7 @@ static int luaI_checkevent (lua_State *L, const char *name, int t) {
38 int e = findevent(name); 38 int e = findevent(name);
39 if (e >= IM_N) 39 if (e >= IM_N)
40 luaO_verror(L, "event `%.50s' is deprecated", name); 40 luaO_verror(L, "event `%.50s' is deprecated", name);
41 if (e == IM_GC && t == TAG_TABLE) 41 if (e == IM_GC && t == LUA_TTABLE)
42 luaO_verror(L, "event `gc' for tables is deprecated"); 42 luaO_verror(L, "event `gc' for tables is deprecated");
43 if (e < 0) 43 if (e < 0)
44 luaO_verror(L, "`%.50s' is not a valid event name", name); 44 luaO_verror(L, "`%.50s' is not a valid event name", name);
@@ -47,29 +47,28 @@ static int luaI_checkevent (lua_State *L, const char *name, int t) {
47 47
48 48
49 49
50/* events in TAG_NIL are all allowed, since this is used as a 50/* events in LUA_TNIL are all allowed, since this is used as a
51* 'placeholder' for "default" fallbacks 51* 'placeholder' for "default" fallbacks
52*/ 52*/
53/* ORDER LUA_T, ORDER IM */ 53/* ORDER LUA_T, ORDER IM */
54static const char luaT_validevents[NUM_TAGS][IM_N] = { 54static const char luaT_validevents[NUM_TAGS][IM_N] = {
55 {1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* TAG_USERDATA */ 55 {1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_TUSERDATA */
56 {1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, /* TAG_NUMBER */ 56 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* LUA_TNIL */
57 {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* TAG_STRING */ 57 {1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, /* LUA_TNUMBER */
58 {0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* TAG_TABLE */ 58 {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, /* LUA_TSTRING */
59 {1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* TAG_LCLOSURE */ 59 {0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, /* LUA_TTABLE */
60 {1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* TAG_CCLOSURE */ 60 {1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0} /* LUA_TFUNCTION */
61 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} /* TAG_NIL */
62}; 61};
63 62
64int luaT_validevent (int t, int e) { /* ORDER LUA_T */ 63int luaT_validevent (int t, int e) { /* ORDER LUA_T */
65 return (t > TAG_NIL) ? 1 : luaT_validevents[t][e]; 64 return (t >= NUM_TAGS) ? 1 : luaT_validevents[t][e];
66} 65}
67 66
68 67
69static void init_entry (lua_State *L, int tag) { 68static void init_entry (lua_State *L, int tag) {
70 int i; 69 int i;
71 for (i=0; i<IM_N; i++) 70 for (i=0; i<IM_N; i++)
72 ttype(luaT_getim(L, tag, i)) = TAG_NIL; 71 ttype(luaT_getim(L, tag, i)) = LUA_TNIL;
73 L->IMtable[tag].collected = NULL; 72 L->IMtable[tag].collected = NULL;
74} 73}
75 74
@@ -100,7 +99,7 @@ static void checktag (lua_State *L, int tag) {
100} 99}
101 100
102void luaT_realtag (lua_State *L, int tag) { 101void luaT_realtag (lua_State *L, int tag) {
103 if (!(NUM_TAGS <= tag && tag <= L->last_tag)) 102 if (!validtag(tag))
104 luaO_verror(L, "tag %d was not created by `newtag'", tag); 103 luaO_verror(L, "tag %d was not created by `newtag'", tag);
105} 104}
106 105
@@ -117,20 +116,12 @@ int lua_copytagmethods (lua_State *L, int tagto, int tagfrom) {
117} 116}
118 117
119 118
120const TObject *luaT_gettagmethods (lua_State *L, const TObject *o) { 119int luaT_tag (const TObject *o) {
121 lua_Tag t = ttype(o); 120 int t = ttype(o);
122 switch (t) { 121 switch (t) {
123 case TAG_USERDATA: { 122 case LUA_TUSERDATA: return tsvalue(o)->u.d.tag;
124 int tag = tsvalue(o)->u.d.tag; 123 case LUA_TTABLE: return hvalue(o)->htag;
125 if (tag > L->last_tag) 124 default: return t;
126 return L->IMtable[TAG_USERDATA].int_method;
127 else
128 return L->IMtable[tag].int_method;
129 }
130 case TAG_TABLE:
131 return L->IMtable[hvalue(o)->htag].int_method;
132 default:
133 return L->IMtable[(int)t].int_method;;
134 } 125 }
135} 126}
136 127
@@ -142,7 +133,7 @@ void lua_gettagmethod (lua_State *L, int t, const char *event) {
142 if (luaT_validevent(t, e)) 133 if (luaT_validevent(t, e))
143 *L->top = *luaT_getim(L, t,e); 134 *L->top = *luaT_getim(L, t,e);
144 else 135 else
145 ttype(L->top) = TAG_NIL; 136 ttype(L->top) = LUA_TNIL;
146 incr_top; 137 incr_top;
147} 138}
148 139
@@ -156,8 +147,8 @@ void lua_settagmethod (lua_State *L, int t, const char *event) {
156 checktag(L, t); 147 checktag(L, t);
157 if (!luaT_validevent(t, e)) 148 if (!luaT_validevent(t, e))
158 luaO_verror(L, "cannot change `%.20s' tag method for type `%.20s'%.20s", 149 luaO_verror(L, "cannot change `%.20s' tag method for type `%.20s'%.20s",
159 luaT_eventname[e], lua_typename(L, luaO_tag2type(t)), 150 luaT_eventname[e], luaO_typenames[t],
160 (t == TAG_TABLE || t == TAG_USERDATA) ? " with default tag" 151 (t == LUA_TTABLE || t == LUA_TUSERDATA) ? " with default tag"
161 : ""); 152 : "");
162 temp = *(L->top - 1); 153 temp = *(L->top - 1);
163 *(L->top - 1) = *luaT_getim(L, t,e); 154 *(L->top - 1) = *luaT_getim(L, t,e);