aboutsummaryrefslogtreecommitdiff
path: root/ltm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-11-22 11:12:07 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-11-22 11:12:07 -0200
commit29ede6aa13144ff7b69c57a87be1ee93f57ae896 (patch)
treeadcfb5dcff7db55481cd675349e23dec0e63c939 /ltm.c
parent951897c09319ae5474a4b86bb7d615136577caa0 (diff)
downloadlua-29ede6aa13144ff7b69c57a87be1ee93f57ae896.tar.gz
lua-29ede6aa13144ff7b69c57a87be1ee93f57ae896.tar.bz2
lua-29ede6aa13144ff7b69c57a87be1ee93f57ae896.zip
first implementation of multiple states (reentrant code).
Diffstat (limited to 'ltm.c')
-rw-r--r--ltm.c66
1 files changed, 34 insertions, 32 deletions
diff --git a/ltm.c b/ltm.c
index 37ef9fef..63d9f578 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 1.27 1999/09/20 14:57:29 roberto Exp roberto $ 2** $Id: ltm.c,v 1.28 1999/10/04 17:51:04 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*/
@@ -8,6 +8,8 @@
8#include <stdio.h> 8#include <stdio.h>
9#include <string.h> 9#include <string.h>
10 10
11#define LUA_REENTRANT
12
11#include "lauxlib.h" 13#include "lauxlib.h"
12#include "lmem.h" 14#include "lmem.h"
13#include "lobject.h" 15#include "lobject.h"
@@ -22,10 +24,10 @@ const char *const luaT_eventname[] = { /* ORDER IM */
22}; 24};
23 25
24 26
25static int luaI_checkevent (const char *name, const char *const list[]) { 27static int luaI_checkevent (lua_State *L, const char *name, const char *const list[]) {
26 int e = luaL_findstring(name, list); 28 int e = luaL_findstring(name, list);
27 if (e < 0) 29 if (e < 0)
28 luaL_verror("`%.50s' is not a valid event name", name); 30 luaL_verror(L, "`%.50s' is not a valid event name", name);
29 return e; 31 return e;
30} 32}
31 33
@@ -54,48 +56,48 @@ int luaT_validevent (int t, int e) { /* ORDER LUA_T */
54} 56}
55 57
56 58
57static void init_entry (int tag) { 59static void init_entry (lua_State *L, int tag) {
58 int i; 60 int i;
59 for (i=0; i<IM_N; i++) 61 for (i=0; i<IM_N; i++)
60 ttype(luaT_getim(tag, i)) = LUA_T_NIL; 62 ttype(luaT_getim(L, tag, i)) = LUA_T_NIL;
61} 63}
62 64
63 65
64void luaT_init (void) { 66void luaT_init (lua_State *L) {
65 int t; 67 int t;
66 L->last_tag = -(NUM_TAGS-1); 68 L->last_tag = -(NUM_TAGS-1);
67 luaM_growvector(L->IMtable, 0, NUM_TAGS, struct IM, arrEM, MAX_INT); 69 luaM_growvector(L, L->IMtable, 0, NUM_TAGS, struct IM, arrEM, MAX_INT);
68 for (t=L->last_tag; t<=0; t++) 70 for (t=L->last_tag; t<=0; t++)
69 init_entry(t); 71 init_entry(L, t);
70} 72}
71 73
72 74
73int lua_newtag (void) { 75int lua_newtag (lua_State *L) {
74 --L->last_tag; 76 --L->last_tag;
75 luaM_growvector(L->IMtable, -(L->last_tag), 1, struct IM, arrEM, MAX_INT); 77 luaM_growvector(L, L->IMtable, -(L->last_tag), 1, struct IM, arrEM, MAX_INT);
76 init_entry(L->last_tag); 78 init_entry(L, L->last_tag);
77 return L->last_tag; 79 return L->last_tag;
78} 80}
79 81
80 82
81static void checktag (int tag) { 83static void checktag (lua_State *L, int tag) {
82 if (!(L->last_tag <= tag && tag <= 0)) 84 if (!(L->last_tag <= tag && tag <= 0))
83 luaL_verror("%d is not a valid tag", tag); 85 luaL_verror(L, "%d is not a valid tag", tag);
84} 86}
85 87
86void luaT_realtag (int tag) { 88void luaT_realtag (lua_State *L, int tag) {
87 if (!(L->last_tag <= tag && tag < LUA_T_NIL)) 89 if (!(L->last_tag <= tag && tag < LUA_T_NIL))
88 luaL_verror("tag %d was not created by `newtag'", tag); 90 luaL_verror(L, "tag %d was not created by `newtag'", tag);
89} 91}
90 92
91 93
92int lua_copytagmethods (int tagto, int tagfrom) { 94int lua_copytagmethods (lua_State *L, int tagto, int tagfrom) {
93 int e; 95 int e;
94 checktag(tagto); 96 checktag(L, tagto);
95 checktag(tagfrom); 97 checktag(L, tagfrom);
96 for (e=0; e<IM_N; e++) { 98 for (e=0; e<IM_N; e++) {
97 if (luaT_validevent(tagto, e)) 99 if (luaT_validevent(tagto, e))
98 *luaT_getim(tagto, e) = *luaT_getim(tagfrom, e); 100 *luaT_getim(L, tagto, e) = *luaT_getim(L, tagfrom, e);
99 } 101 }
100 return tagto; 102 return tagto;
101} 103}
@@ -115,7 +117,7 @@ int luaT_effectivetag (const TObject *o) {
115#ifdef DEBUG 117#ifdef DEBUG
116 case LUA_T_PMARK: case LUA_T_CMARK: 118 case LUA_T_PMARK: case LUA_T_CMARK:
117 case LUA_T_CLMARK: case LUA_T_LINE: 119 case LUA_T_CLMARK: case LUA_T_LINE:
118 LUA_INTERNALERROR("invalid type"); 120 LUA_INTERNALERROR(L, "invalid type");
119#endif 121#endif
120 default: 122 default:
121 return t; 123 return t;
@@ -123,37 +125,37 @@ int luaT_effectivetag (const TObject *o) {
123} 125}
124 126
125 127
126const TObject *luaT_gettagmethod (int t, const char *event) { 128const TObject *luaT_gettagmethod (lua_State *L, int t, const char *event) {
127 int e = luaI_checkevent(event, luaT_eventname); 129 int e = luaI_checkevent(L, event, luaT_eventname);
128 checktag(t); 130 checktag(L, t);
129 if (luaT_validevent(t, e)) 131 if (luaT_validevent(t, e))
130 return luaT_getim(t,e); 132 return luaT_getim(L, t,e);
131 else 133 else
132 return &luaO_nilobject; 134 return &luaO_nilobject;
133} 135}
134 136
135 137
136void luaT_settagmethod (int t, const char *event, TObject *func) { 138void luaT_settagmethod (lua_State *L, int t, const char *event, TObject *func) {
137 TObject temp; 139 TObject temp;
138 int e = luaI_checkevent(event, luaT_eventname); 140 int e = luaI_checkevent(L, event, luaT_eventname);
139 checktag(t); 141 checktag(L, t);
140 if (!luaT_validevent(t, e)) 142 if (!luaT_validevent(t, e))
141 luaL_verror("cannot change tag method `%.20s' for type `%.20s'%.20s", 143 luaL_verror(L, "cannot change tag method `%.20s' for type `%.20s'%.20s",
142 luaT_eventname[e], luaO_typenames[-t], 144 luaT_eventname[e], luaO_typenames[-t],
143 (t == LUA_T_ARRAY || t == LUA_T_USERDATA) ? " with default tag" 145 (t == LUA_T_ARRAY || t == LUA_T_USERDATA) ? " with default tag"
144 : ""); 146 : "");
145 temp = *func; 147 temp = *func;
146 *func = *luaT_getim(t,e); 148 *func = *luaT_getim(L, t,e);
147 *luaT_getim(t, e) = temp; 149 *luaT_getim(L, t, e) = temp;
148} 150}
149 151
150 152
151const char *luaT_travtagmethods (int (*fn)(TObject *)) { /* ORDER IM */ 153const char *luaT_travtagmethods (lua_State *L, int (*fn)(lua_State *, TObject *)) { /* ORDER IM */
152 int e; 154 int e;
153 for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) { 155 for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) {
154 int t; 156 int t;
155 for (t=0; t>=L->last_tag; t--) 157 for (t=0; t>=L->last_tag; t--)
156 if (fn(luaT_getim(t,e))) 158 if (fn(L, luaT_getim(L, t,e)))
157 return luaT_eventname[e]; 159 return luaT_eventname[e];
158 } 160 }
159 return NULL; 161 return NULL;