diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-01-19 11:20:30 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-01-19 11:20:30 -0200 |
commit | 4ac58853dc820127a11a14ed8bde1fae9458369e (patch) | |
tree | e8179692c97e935ba921c8ebd17abf9c8510d89e /ltm.c | |
parent | f2c451d7455aad3496f32dfa2bfca7f7e8b5376d (diff) | |
download | lua-4ac58853dc820127a11a14ed8bde1fae9458369e.tar.gz lua-4ac58853dc820127a11a14ed8bde1fae9458369e.tar.bz2 lua-4ac58853dc820127a11a14ed8bde1fae9458369e.zip |
thead-specific state separated from "global" state
Diffstat (limited to 'ltm.c')
-rw-r--r-- | ltm.c | 34 |
1 files changed, 17 insertions, 17 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.c,v 1.59 2000/12/28 12:55:41 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 1.60 2001/01/18 15:59:09 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 | */ |
@@ -68,36 +68,36 @@ int luaT_validevent (int t, int e) { /* ORDER LUA_T */ | |||
68 | static void init_entry (lua_State *L, int tag) { | 68 | static void init_entry (lua_State *L, int tag) { |
69 | int i; | 69 | int i; |
70 | for (i=0; i<TM_N; i++) | 70 | for (i=0; i<TM_N; i++) |
71 | luaT_gettm(L, tag, i) = NULL; | 71 | luaT_gettm(G(L), tag, i) = NULL; |
72 | L->TMtable[tag].collected = NULL; | 72 | G(L)->TMtable[tag].collected = NULL; |
73 | } | 73 | } |
74 | 74 | ||
75 | 75 | ||
76 | void luaT_init (lua_State *L) { | 76 | void luaT_init (lua_State *L) { |
77 | int t; | 77 | int t; |
78 | L->TMtable = luaM_newvector(L, NUM_TAGS+2, struct TM); | 78 | G(L)->TMtable = luaM_newvector(L, NUM_TAGS+2, struct TM); |
79 | L->sizeTM = NUM_TAGS+2; | 79 | G(L)->sizeTM = NUM_TAGS+2; |
80 | L->ntag = NUM_TAGS; | 80 | G(L)->ntag = NUM_TAGS; |
81 | for (t=0; t<L->ntag; t++) | 81 | for (t=0; t<G(L)->ntag; t++) |
82 | init_entry(L, t); | 82 | init_entry(L, t); |
83 | } | 83 | } |
84 | 84 | ||
85 | 85 | ||
86 | LUA_API int lua_newtag (lua_State *L) { | 86 | LUA_API int lua_newtag (lua_State *L) { |
87 | luaM_growvector(L, L->TMtable, L->ntag, L->sizeTM, struct TM, | 87 | luaM_growvector(L, G(L)->TMtable, G(L)->ntag, G(L)->sizeTM, struct TM, |
88 | MAX_INT, "tag table overflow"); | 88 | MAX_INT, "tag table overflow"); |
89 | init_entry(L, L->ntag); | 89 | init_entry(L, G(L)->ntag); |
90 | return L->ntag++; | 90 | return G(L)->ntag++; |
91 | } | 91 | } |
92 | 92 | ||
93 | 93 | ||
94 | static void checktag (lua_State *L, int tag) { | 94 | static void checktag (lua_State *L, int tag) { |
95 | if (!(0 <= tag && tag < L->ntag)) | 95 | if (!(0 <= tag && tag < G(L)->ntag)) |
96 | luaO_verror(L, "%d is not a valid tag", tag); | 96 | luaO_verror(L, "%d is not a valid tag", tag); |
97 | } | 97 | } |
98 | 98 | ||
99 | void luaT_realtag (lua_State *L, int tag) { | 99 | void luaT_realtag (lua_State *L, int tag) { |
100 | if (!validtag(tag)) | 100 | if (!validtag(G(L), tag)) |
101 | luaO_verror(L, "tag %d was not created by `newtag'", tag); | 101 | luaO_verror(L, "tag %d was not created by `newtag'", tag); |
102 | } | 102 | } |
103 | 103 | ||
@@ -108,7 +108,7 @@ LUA_API int lua_copytagmethods (lua_State *L, int tagto, int tagfrom) { | |||
108 | checktag(L, tagfrom); | 108 | checktag(L, tagfrom); |
109 | for (e=0; e<TM_N; e++) { | 109 | for (e=0; e<TM_N; e++) { |
110 | if (luaT_validevent(tagto, e)) | 110 | if (luaT_validevent(tagto, e)) |
111 | luaT_gettm(L, tagto, e) = luaT_gettm(L, tagfrom, e); | 111 | luaT_gettm(G(L), tagto, e) = luaT_gettm(G(L), tagfrom, e); |
112 | } | 112 | } |
113 | return tagto; | 113 | return tagto; |
114 | } | 114 | } |
@@ -128,8 +128,8 @@ LUA_API void lua_gettagmethod (lua_State *L, int t, const char *event) { | |||
128 | int e; | 128 | int e; |
129 | e = luaI_checkevent(L, event, t); | 129 | e = luaI_checkevent(L, event, t); |
130 | checktag(L, t); | 130 | checktag(L, t); |
131 | if (luaT_validevent(t, e) && luaT_gettm(L, t, e)) { | 131 | if (luaT_validevent(t, e) && luaT_gettm(G(L), t, e)) { |
132 | setclvalue(L->top, luaT_gettm(L, t, e)); | 132 | setclvalue(L->top, luaT_gettm(G(L), t, e)); |
133 | } | 133 | } |
134 | else | 134 | else |
135 | setnilvalue(L->top); | 135 | setnilvalue(L->top); |
@@ -147,10 +147,10 @@ LUA_API void lua_settagmethod (lua_State *L, int t, const char *event) { | |||
147 | " with default tag" : ""); | 147 | " with default tag" : ""); |
148 | switch (ttype(L->top - 1)) { | 148 | switch (ttype(L->top - 1)) { |
149 | case LUA_TNIL: | 149 | case LUA_TNIL: |
150 | luaT_gettm(L, t, e) = NULL; | 150 | luaT_gettm(G(L), t, e) = NULL; |
151 | break; | 151 | break; |
152 | case LUA_TFUNCTION: | 152 | case LUA_TFUNCTION: |
153 | luaT_gettm(L, t, e) = clvalue(L->top - 1); | 153 | luaT_gettm(G(L), t, e) = clvalue(L->top - 1); |
154 | break; | 154 | break; |
155 | default: | 155 | default: |
156 | lua_error(L, "tag method must be a function (or nil)"); | 156 | lua_error(L, "tag method must be a function (or nil)"); |