diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-02-02 13:13:05 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-02-02 13:13:05 -0200 |
commit | 426d3e43bdec4b1ab2b0aed1844396c27f64872f (patch) | |
tree | 659b73e1e9720fb85c66a481b476c96671eef734 | |
parent | 8823f371a2a63f634121a0c16cb1d02e5ce9f5c5 (diff) | |
download | lua-426d3e43bdec4b1ab2b0aed1844396c27f64872f.tar.gz lua-426d3e43bdec4b1ab2b0aed1844396c27f64872f.tar.bz2 lua-426d3e43bdec4b1ab2b0aed1844396c27f64872f.zip |
lock/unlock may use L + better structure for internal debug stuff
-rw-r--r-- | lapi.c | 206 | ||||
-rw-r--r-- | ldebug.c | 26 | ||||
-rw-r--r-- | ldo.c | 24 | ||||
-rw-r--r-- | lgc.c | 17 | ||||
-rw-r--r-- | lmem.h | 10 | ||||
-rw-r--r-- | lobject.c | 5 | ||||
-rw-r--r-- | lobject.h | 17 | ||||
-rw-r--r-- | lstate.c | 75 | ||||
-rw-r--r-- | lstate.h | 14 | ||||
-rw-r--r-- | ltests.c | 23 | ||||
-rw-r--r-- | ltm.c | 14 | ||||
-rw-r--r-- | lvm.c | 6 |
12 files changed, 213 insertions, 224 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.123 2001/02/01 13:56:49 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.124 2001/02/01 16:03:38 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -55,9 +55,9 @@ void luaA_pushobject (lua_State *L, const TObject *o) { | |||
55 | 55 | ||
56 | LUA_API int lua_stackspace (lua_State *L) { | 56 | LUA_API int lua_stackspace (lua_State *L) { |
57 | int i; | 57 | int i; |
58 | LUA_LOCK; | 58 | LUA_LOCK(L); |
59 | i = (L->stack_last - L->top); | 59 | i = (L->stack_last - L->top); |
60 | LUA_UNLOCK; | 60 | LUA_UNLOCK(L); |
61 | return i; | 61 | return i; |
62 | } | 62 | } |
63 | 63 | ||
@@ -70,49 +70,49 @@ LUA_API int lua_stackspace (lua_State *L) { | |||
70 | 70 | ||
71 | LUA_API int lua_gettop (lua_State *L) { | 71 | LUA_API int lua_gettop (lua_State *L) { |
72 | int i; | 72 | int i; |
73 | LUA_LOCK; | 73 | LUA_LOCK(L); |
74 | i = (L->top - L->Cbase); | 74 | i = (L->top - L->Cbase); |
75 | LUA_UNLOCK; | 75 | LUA_UNLOCK(L); |
76 | return i; | 76 | return i; |
77 | } | 77 | } |
78 | 78 | ||
79 | 79 | ||
80 | LUA_API void lua_settop (lua_State *L, int index) { | 80 | LUA_API void lua_settop (lua_State *L, int index) { |
81 | LUA_LOCK; | 81 | LUA_LOCK(L); |
82 | if (index >= 0) | 82 | if (index >= 0) |
83 | luaD_adjusttop(L, L->Cbase, index); | 83 | luaD_adjusttop(L, L->Cbase, index); |
84 | else | 84 | else |
85 | L->top = L->top+index+1; /* index is negative */ | 85 | L->top = L->top+index+1; /* index is negative */ |
86 | LUA_UNLOCK; | 86 | LUA_UNLOCK(L); |
87 | } | 87 | } |
88 | 88 | ||
89 | 89 | ||
90 | LUA_API void lua_remove (lua_State *L, int index) { | 90 | LUA_API void lua_remove (lua_State *L, int index) { |
91 | StkId p; | 91 | StkId p; |
92 | LUA_LOCK; | 92 | LUA_LOCK(L); |
93 | p = luaA_index(L, index); | 93 | p = luaA_index(L, index); |
94 | while (++p < L->top) setobj(p-1, p); | 94 | while (++p < L->top) setobj(p-1, p); |
95 | L->top--; | 95 | L->top--; |
96 | LUA_UNLOCK; | 96 | LUA_UNLOCK(L); |
97 | } | 97 | } |
98 | 98 | ||
99 | 99 | ||
100 | LUA_API void lua_insert (lua_State *L, int index) { | 100 | LUA_API void lua_insert (lua_State *L, int index) { |
101 | StkId p; | 101 | StkId p; |
102 | StkId q; | 102 | StkId q; |
103 | LUA_LOCK; | 103 | LUA_LOCK(L); |
104 | p = luaA_index(L, index); | 104 | p = luaA_index(L, index); |
105 | for (q = L->top; q>p; q--) setobj(q, q-1); | 105 | for (q = L->top; q>p; q--) setobj(q, q-1); |
106 | setobj(p, L->top); | 106 | setobj(p, L->top); |
107 | LUA_UNLOCK; | 107 | LUA_UNLOCK(L); |
108 | } | 108 | } |
109 | 109 | ||
110 | 110 | ||
111 | LUA_API void lua_pushvalue (lua_State *L, int index) { | 111 | LUA_API void lua_pushvalue (lua_State *L, int index) { |
112 | LUA_LOCK; | 112 | LUA_LOCK(L); |
113 | setobj(L->top, luaA_index(L, index)); | 113 | setobj(L->top, luaA_index(L, index)); |
114 | api_incr_top(L); | 114 | api_incr_top(L); |
115 | LUA_UNLOCK; | 115 | LUA_UNLOCK(L); |
116 | } | 116 | } |
117 | 117 | ||
118 | 118 | ||
@@ -125,19 +125,19 @@ LUA_API void lua_pushvalue (lua_State *L, int index) { | |||
125 | LUA_API int lua_type (lua_State *L, int index) { | 125 | LUA_API int lua_type (lua_State *L, int index) { |
126 | StkId o; | 126 | StkId o; |
127 | int i; | 127 | int i; |
128 | LUA_LOCK; | 128 | LUA_LOCK(L); |
129 | o = luaA_indexAcceptable(L, index); | 129 | o = luaA_indexAcceptable(L, index); |
130 | i = (o == NULL) ? LUA_TNONE : ttype(o); | 130 | i = (o == NULL) ? LUA_TNONE : ttype(o); |
131 | LUA_UNLOCK; | 131 | LUA_UNLOCK(L); |
132 | return i; | 132 | return i; |
133 | } | 133 | } |
134 | 134 | ||
135 | 135 | ||
136 | LUA_API const char *lua_typename (lua_State *L, int t) { | 136 | LUA_API const char *lua_typename (lua_State *L, int t) { |
137 | const char *s; | 137 | const char *s; |
138 | LUA_LOCK; | 138 | LUA_LOCK(L); |
139 | s = (t == LUA_TNONE) ? "no value" : basictypename(G(L), t); | 139 | s = (t == LUA_TNONE) ? "no value" : basictypename(G(L), t); |
140 | LUA_UNLOCK; | 140 | LUA_UNLOCK(L); |
141 | return s; | 141 | return s; |
142 | } | 142 | } |
143 | 143 | ||
@@ -145,10 +145,10 @@ LUA_API const char *lua_typename (lua_State *L, int t) { | |||
145 | LUA_API const char *lua_xtype (lua_State *L, int index) { | 145 | LUA_API const char *lua_xtype (lua_State *L, int index) { |
146 | StkId o; | 146 | StkId o; |
147 | const char *type; | 147 | const char *type; |
148 | LUA_LOCK; | 148 | LUA_LOCK(L); |
149 | o = luaA_indexAcceptable(L, index); | 149 | o = luaA_indexAcceptable(L, index); |
150 | type = (o == NULL) ? "no value" : luaT_typename(G(L), o); | 150 | type = (o == NULL) ? "no value" : luaT_typename(G(L), o); |
151 | LUA_UNLOCK; | 151 | LUA_UNLOCK(L); |
152 | return type; | 152 | return type; |
153 | } | 153 | } |
154 | 154 | ||
@@ -156,20 +156,20 @@ LUA_API const char *lua_xtype (lua_State *L, int index) { | |||
156 | LUA_API int lua_iscfunction (lua_State *L, int index) { | 156 | LUA_API int lua_iscfunction (lua_State *L, int index) { |
157 | StkId o; | 157 | StkId o; |
158 | int i; | 158 | int i; |
159 | LUA_LOCK; | 159 | LUA_LOCK(L); |
160 | o = luaA_indexAcceptable(L, index); | 160 | o = luaA_indexAcceptable(L, index); |
161 | i = (o == NULL) ? 0 : iscfunction(o); | 161 | i = (o == NULL) ? 0 : iscfunction(o); |
162 | LUA_UNLOCK; | 162 | LUA_UNLOCK(L); |
163 | return i; | 163 | return i; |
164 | } | 164 | } |
165 | 165 | ||
166 | LUA_API int lua_isnumber (lua_State *L, int index) { | 166 | LUA_API int lua_isnumber (lua_State *L, int index) { |
167 | TObject *o; | 167 | TObject *o; |
168 | int i; | 168 | int i; |
169 | LUA_LOCK; | 169 | LUA_LOCK(L); |
170 | o = luaA_indexAcceptable(L, index); | 170 | o = luaA_indexAcceptable(L, index); |
171 | i = (o == NULL) ? 0 : (tonumber(o) == 0); | 171 | i = (o == NULL) ? 0 : (tonumber(o) == 0); |
172 | LUA_UNLOCK; | 172 | LUA_UNLOCK(L); |
173 | return i; | 173 | return i; |
174 | } | 174 | } |
175 | 175 | ||
@@ -182,34 +182,34 @@ LUA_API int lua_isstring (lua_State *L, int index) { | |||
182 | LUA_API int lua_tag (lua_State *L, int index) { | 182 | LUA_API int lua_tag (lua_State *L, int index) { |
183 | StkId o; | 183 | StkId o; |
184 | int i; | 184 | int i; |
185 | LUA_LOCK; | 185 | LUA_LOCK(L); |
186 | o = luaA_indexAcceptable(L, index); | 186 | o = luaA_indexAcceptable(L, index); |
187 | i = (o == NULL) ? LUA_NOTAG : luaT_tag(o); | 187 | i = (o == NULL) ? LUA_NOTAG : luaT_tag(o); |
188 | LUA_UNLOCK; | 188 | LUA_UNLOCK(L); |
189 | return i; | 189 | return i; |
190 | } | 190 | } |
191 | 191 | ||
192 | LUA_API int lua_equal (lua_State *L, int index1, int index2) { | 192 | LUA_API int lua_equal (lua_State *L, int index1, int index2) { |
193 | StkId o1, o2; | 193 | StkId o1, o2; |
194 | int i; | 194 | int i; |
195 | LUA_LOCK; | 195 | LUA_LOCK(L); |
196 | o1 = luaA_indexAcceptable(L, index1); | 196 | o1 = luaA_indexAcceptable(L, index1); |
197 | o2 = luaA_indexAcceptable(L, index2); | 197 | o2 = luaA_indexAcceptable(L, index2); |
198 | i = (o1 == NULL || o2 == NULL) ? 0 /* index out-of-range */ | 198 | i = (o1 == NULL || o2 == NULL) ? 0 /* index out-of-range */ |
199 | : luaO_equalObj(o1, o2); | 199 | : luaO_equalObj(o1, o2); |
200 | LUA_UNLOCK; | 200 | LUA_UNLOCK(L); |
201 | return i; | 201 | return i; |
202 | } | 202 | } |
203 | 203 | ||
204 | LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { | 204 | LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { |
205 | StkId o1, o2; | 205 | StkId o1, o2; |
206 | int i; | 206 | int i; |
207 | LUA_LOCK; | 207 | LUA_LOCK(L); |
208 | o1 = luaA_indexAcceptable(L, index1); | 208 | o1 = luaA_indexAcceptable(L, index1); |
209 | o2 = luaA_indexAcceptable(L, index2); | 209 | o2 = luaA_indexAcceptable(L, index2); |
210 | i = (o1 == NULL || o2 == NULL) ? 0 /* index out-of-range */ | 210 | i = (o1 == NULL || o2 == NULL) ? 0 /* index out-of-range */ |
211 | : luaV_lessthan(L, o1, o2, L->top); | 211 | : luaV_lessthan(L, o1, o2, L->top); |
212 | LUA_UNLOCK; | 212 | LUA_UNLOCK(L); |
213 | return i; | 213 | return i; |
214 | } | 214 | } |
215 | 215 | ||
@@ -218,58 +218,58 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { | |||
218 | LUA_API lua_Number lua_tonumber (lua_State *L, int index) { | 218 | LUA_API lua_Number lua_tonumber (lua_State *L, int index) { |
219 | StkId o; | 219 | StkId o; |
220 | lua_Number n; | 220 | lua_Number n; |
221 | LUA_LOCK; | 221 | LUA_LOCK(L); |
222 | o = luaA_indexAcceptable(L, index); | 222 | o = luaA_indexAcceptable(L, index); |
223 | n = (o == NULL || tonumber(o)) ? 0 : nvalue(o); | 223 | n = (o == NULL || tonumber(o)) ? 0 : nvalue(o); |
224 | LUA_UNLOCK; | 224 | LUA_UNLOCK(L); |
225 | return n; | 225 | return n; |
226 | } | 226 | } |
227 | 227 | ||
228 | LUA_API const char *lua_tostring (lua_State *L, int index) { | 228 | LUA_API const char *lua_tostring (lua_State *L, int index) { |
229 | StkId o; | 229 | StkId o; |
230 | const char *s; | 230 | const char *s; |
231 | LUA_LOCK; | 231 | LUA_LOCK(L); |
232 | o = luaA_indexAcceptable(L, index); | 232 | o = luaA_indexAcceptable(L, index); |
233 | s = (o == NULL || tostring(L, o)) ? NULL : svalue(o); | 233 | s = (o == NULL || tostring(L, o)) ? NULL : svalue(o); |
234 | LUA_UNLOCK; | 234 | LUA_UNLOCK(L); |
235 | return s; | 235 | return s; |
236 | } | 236 | } |
237 | 237 | ||
238 | LUA_API size_t lua_strlen (lua_State *L, int index) { | 238 | LUA_API size_t lua_strlen (lua_State *L, int index) { |
239 | StkId o; | 239 | StkId o; |
240 | size_t l; | 240 | size_t l; |
241 | LUA_LOCK; | 241 | LUA_LOCK(L); |
242 | o = luaA_indexAcceptable(L, index); | 242 | o = luaA_indexAcceptable(L, index); |
243 | l = (o == NULL || tostring(L, o)) ? 0 : tsvalue(o)->len; | 243 | l = (o == NULL || tostring(L, o)) ? 0 : tsvalue(o)->len; |
244 | LUA_UNLOCK; | 244 | LUA_UNLOCK(L); |
245 | return l; | 245 | return l; |
246 | } | 246 | } |
247 | 247 | ||
248 | LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index) { | 248 | LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index) { |
249 | StkId o; | 249 | StkId o; |
250 | lua_CFunction f; | 250 | lua_CFunction f; |
251 | LUA_LOCK; | 251 | LUA_LOCK(L); |
252 | o = luaA_indexAcceptable(L, index); | 252 | o = luaA_indexAcceptable(L, index); |
253 | f = (o == NULL || !iscfunction(o)) ? NULL : clvalue(o)->f.c; | 253 | f = (o == NULL || !iscfunction(o)) ? NULL : clvalue(o)->f.c; |
254 | LUA_UNLOCK; | 254 | LUA_UNLOCK(L); |
255 | return f; | 255 | return f; |
256 | } | 256 | } |
257 | 257 | ||
258 | LUA_API void *lua_touserdata (lua_State *L, int index) { | 258 | LUA_API void *lua_touserdata (lua_State *L, int index) { |
259 | StkId o; | 259 | StkId o; |
260 | void *p; | 260 | void *p; |
261 | LUA_LOCK; | 261 | LUA_LOCK(L); |
262 | o = luaA_indexAcceptable(L, index); | 262 | o = luaA_indexAcceptable(L, index); |
263 | p = (o == NULL || ttype(o) != LUA_TUSERDATA) ? NULL : | 263 | p = (o == NULL || ttype(o) != LUA_TUSERDATA) ? NULL : |
264 | tsvalue(o)->u.d.value; | 264 | tsvalue(o)->u.d.value; |
265 | LUA_UNLOCK; | 265 | LUA_UNLOCK(L); |
266 | return p; | 266 | return p; |
267 | } | 267 | } |
268 | 268 | ||
269 | LUA_API const void *lua_topointer (lua_State *L, int index) { | 269 | LUA_API const void *lua_topointer (lua_State *L, int index) { |
270 | StkId o; | 270 | StkId o; |
271 | const void *p; | 271 | const void *p; |
272 | LUA_LOCK; | 272 | LUA_LOCK(L); |
273 | o = luaA_indexAcceptable(L, index); | 273 | o = luaA_indexAcceptable(L, index); |
274 | if (o == NULL) p = NULL; | 274 | if (o == NULL) p = NULL; |
275 | else { | 275 | else { |
@@ -285,7 +285,7 @@ LUA_API const void *lua_topointer (lua_State *L, int index) { | |||
285 | break; | 285 | break; |
286 | } | 286 | } |
287 | } | 287 | } |
288 | LUA_UNLOCK; | 288 | LUA_UNLOCK(L); |
289 | return p; | 289 | return p; |
290 | } | 290 | } |
291 | 291 | ||
@@ -297,26 +297,26 @@ LUA_API const void *lua_topointer (lua_State *L, int index) { | |||
297 | 297 | ||
298 | 298 | ||
299 | LUA_API void lua_pushnil (lua_State *L) { | 299 | LUA_API void lua_pushnil (lua_State *L) { |
300 | LUA_LOCK; | 300 | LUA_LOCK(L); |
301 | setnilvalue(L->top); | 301 | setnilvalue(L->top); |
302 | api_incr_top(L); | 302 | api_incr_top(L); |
303 | LUA_UNLOCK; | 303 | LUA_UNLOCK(L); |
304 | } | 304 | } |
305 | 305 | ||
306 | 306 | ||
307 | LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { | 307 | LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { |
308 | LUA_LOCK; | 308 | LUA_LOCK(L); |
309 | setnvalue(L->top, n); | 309 | setnvalue(L->top, n); |
310 | api_incr_top(L); | 310 | api_incr_top(L); |
311 | LUA_UNLOCK; | 311 | LUA_UNLOCK(L); |
312 | } | 312 | } |
313 | 313 | ||
314 | 314 | ||
315 | LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { | 315 | LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { |
316 | LUA_LOCK; | 316 | LUA_LOCK(L); |
317 | setsvalue(L->top, luaS_newlstr(L, s, len)); | 317 | setsvalue(L->top, luaS_newlstr(L, s, len)); |
318 | api_incr_top(L); | 318 | api_incr_top(L); |
319 | LUA_UNLOCK; | 319 | LUA_UNLOCK(L); |
320 | } | 320 | } |
321 | 321 | ||
322 | 322 | ||
@@ -329,20 +329,20 @@ LUA_API void lua_pushstring (lua_State *L, const char *s) { | |||
329 | 329 | ||
330 | 330 | ||
331 | LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { | 331 | LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { |
332 | LUA_LOCK; | 332 | LUA_LOCK(L); |
333 | luaV_Cclosure(L, fn, n); | 333 | luaV_Cclosure(L, fn, n); |
334 | LUA_UNLOCK; | 334 | LUA_UNLOCK(L); |
335 | } | 335 | } |
336 | 336 | ||
337 | 337 | ||
338 | LUA_API void lua_pushusertag (lua_State *L, void *u, int tag) { | 338 | LUA_API void lua_pushusertag (lua_State *L, void *u, int tag) { |
339 | LUA_LOCK; | 339 | LUA_LOCK(L); |
340 | /* ORDER LUA_T */ | 340 | /* ORDER LUA_T */ |
341 | if (!(tag == LUA_ANYTAG || tag == LUA_TUSERDATA || validtag(G(L), tag))) | 341 | if (!(tag == LUA_ANYTAG || tag == LUA_TUSERDATA || validtag(G(L), tag))) |
342 | luaO_verror(L, "invalid tag for a userdata (%d)", tag); | 342 | luaO_verror(L, "invalid tag for a userdata (%d)", tag); |
343 | setuvalue(L->top, luaS_createudata(L, u, tag)); | 343 | setuvalue(L->top, luaS_createudata(L, u, tag)); |
344 | api_incr_top(L); | 344 | api_incr_top(L); |
345 | LUA_UNLOCK; | 345 | LUA_UNLOCK(L); |
346 | } | 346 | } |
347 | 347 | ||
348 | 348 | ||
@@ -353,54 +353,54 @@ LUA_API void lua_pushusertag (lua_State *L, void *u, int tag) { | |||
353 | 353 | ||
354 | 354 | ||
355 | LUA_API void lua_getglobal (lua_State *L, const char *name) { | 355 | LUA_API void lua_getglobal (lua_State *L, const char *name) { |
356 | LUA_LOCK; | 356 | LUA_LOCK(L); |
357 | luaV_getglobal(L, luaS_new(L, name), L->top); | 357 | luaV_getglobal(L, luaS_new(L, name), L->top); |
358 | api_incr_top(L); | 358 | api_incr_top(L); |
359 | LUA_UNLOCK; | 359 | LUA_UNLOCK(L); |
360 | } | 360 | } |
361 | 361 | ||
362 | 362 | ||
363 | LUA_API void lua_gettable (lua_State *L, int index) { | 363 | LUA_API void lua_gettable (lua_State *L, int index) { |
364 | StkId t; | 364 | StkId t; |
365 | LUA_LOCK; | 365 | LUA_LOCK(L); |
366 | t = Index(L, index); | 366 | t = Index(L, index); |
367 | luaV_gettable(L, t, L->top, L->top-1); | 367 | luaV_gettable(L, t, L->top, L->top-1); |
368 | LUA_UNLOCK; | 368 | LUA_UNLOCK(L); |
369 | } | 369 | } |
370 | 370 | ||
371 | 371 | ||
372 | LUA_API void lua_rawget (lua_State *L, int index) { | 372 | LUA_API void lua_rawget (lua_State *L, int index) { |
373 | StkId t; | 373 | StkId t; |
374 | LUA_LOCK; | 374 | LUA_LOCK(L); |
375 | t = Index(L, index); | 375 | t = Index(L, index); |
376 | lua_assert(ttype(t) == LUA_TTABLE); | 376 | lua_assert(ttype(t) == LUA_TTABLE); |
377 | setobj(L->top - 1, luaH_get(hvalue(t), L->top - 1)); | 377 | setobj(L->top - 1, luaH_get(hvalue(t), L->top - 1)); |
378 | LUA_UNLOCK; | 378 | LUA_UNLOCK(L); |
379 | } | 379 | } |
380 | 380 | ||
381 | 381 | ||
382 | LUA_API void lua_rawgeti (lua_State *L, int index, int n) { | 382 | LUA_API void lua_rawgeti (lua_State *L, int index, int n) { |
383 | StkId o; | 383 | StkId o; |
384 | LUA_LOCK; | 384 | LUA_LOCK(L); |
385 | o = Index(L, index); | 385 | o = Index(L, index); |
386 | lua_assert(ttype(o) == LUA_TTABLE); | 386 | lua_assert(ttype(o) == LUA_TTABLE); |
387 | setobj(L->top, luaH_getnum(hvalue(o), n)); | 387 | setobj(L->top, luaH_getnum(hvalue(o), n)); |
388 | api_incr_top(L); | 388 | api_incr_top(L); |
389 | LUA_UNLOCK; | 389 | LUA_UNLOCK(L); |
390 | } | 390 | } |
391 | 391 | ||
392 | 392 | ||
393 | LUA_API void lua_getglobals (lua_State *L) { | 393 | LUA_API void lua_getglobals (lua_State *L) { |
394 | LUA_LOCK; | 394 | LUA_LOCK(L); |
395 | sethvalue(L->top, L->gt); | 395 | sethvalue(L->top, L->gt); |
396 | api_incr_top(L); | 396 | api_incr_top(L); |
397 | LUA_UNLOCK; | 397 | LUA_UNLOCK(L); |
398 | } | 398 | } |
399 | 399 | ||
400 | 400 | ||
401 | LUA_API int lua_getref (lua_State *L, int ref) { | 401 | LUA_API int lua_getref (lua_State *L, int ref) { |
402 | int status = 1; | 402 | int status = 1; |
403 | LUA_LOCK; | 403 | LUA_LOCK(L); |
404 | if (ref == LUA_REFNIL) { | 404 | if (ref == LUA_REFNIL) { |
405 | setnilvalue(L->top); | 405 | setnilvalue(L->top); |
406 | api_incr_top(L); | 406 | api_incr_top(L); |
@@ -412,16 +412,16 @@ LUA_API int lua_getref (lua_State *L, int ref) { | |||
412 | } | 412 | } |
413 | else | 413 | else |
414 | status = 0; | 414 | status = 0; |
415 | LUA_UNLOCK; | 415 | LUA_UNLOCK(L); |
416 | return status; | 416 | return status; |
417 | } | 417 | } |
418 | 418 | ||
419 | 419 | ||
420 | LUA_API void lua_newtable (lua_State *L) { | 420 | LUA_API void lua_newtable (lua_State *L) { |
421 | LUA_LOCK; | 421 | LUA_LOCK(L); |
422 | sethvalue(L->top, luaH_new(L, 0)); | 422 | sethvalue(L->top, luaH_new(L, 0)); |
423 | api_incr_top(L); | 423 | api_incr_top(L); |
424 | LUA_UNLOCK; | 424 | LUA_UNLOCK(L); |
425 | } | 425 | } |
426 | 426 | ||
427 | 427 | ||
@@ -432,58 +432,58 @@ LUA_API void lua_newtable (lua_State *L) { | |||
432 | 432 | ||
433 | 433 | ||
434 | LUA_API void lua_setglobal (lua_State *L, const char *name) { | 434 | LUA_API void lua_setglobal (lua_State *L, const char *name) { |
435 | LUA_LOCK; | 435 | LUA_LOCK(L); |
436 | luaV_setglobal(L, luaS_new(L, name), L->top); | 436 | luaV_setglobal(L, luaS_new(L, name), L->top); |
437 | L->top--; /* remove element from the top */ | 437 | L->top--; /* remove element from the top */ |
438 | LUA_UNLOCK; | 438 | LUA_UNLOCK(L); |
439 | } | 439 | } |
440 | 440 | ||
441 | 441 | ||
442 | LUA_API void lua_settable (lua_State *L, int index) { | 442 | LUA_API void lua_settable (lua_State *L, int index) { |
443 | StkId t; | 443 | StkId t; |
444 | LUA_LOCK; | 444 | LUA_LOCK(L); |
445 | t = Index(L, index); | 445 | t = Index(L, index); |
446 | luaV_settable(L, t, L->top - 2, L->top); | 446 | luaV_settable(L, t, L->top - 2, L->top); |
447 | L->top -= 2; /* pop index and value */ | 447 | L->top -= 2; /* pop index and value */ |
448 | LUA_UNLOCK; | 448 | LUA_UNLOCK(L); |
449 | } | 449 | } |
450 | 450 | ||
451 | 451 | ||
452 | LUA_API void lua_rawset (lua_State *L, int index) { | 452 | LUA_API void lua_rawset (lua_State *L, int index) { |
453 | StkId t; | 453 | StkId t; |
454 | LUA_LOCK; | 454 | LUA_LOCK(L); |
455 | t = Index(L, index); | 455 | t = Index(L, index); |
456 | lua_assert(ttype(t) == LUA_TTABLE); | 456 | lua_assert(ttype(t) == LUA_TTABLE); |
457 | setobj(luaH_set(L, hvalue(t), L->top-2), (L->top-1)); | 457 | setobj(luaH_set(L, hvalue(t), L->top-2), (L->top-1)); |
458 | L->top -= 2; | 458 | L->top -= 2; |
459 | LUA_UNLOCK; | 459 | LUA_UNLOCK(L); |
460 | } | 460 | } |
461 | 461 | ||
462 | 462 | ||
463 | LUA_API void lua_rawseti (lua_State *L, int index, int n) { | 463 | LUA_API void lua_rawseti (lua_State *L, int index, int n) { |
464 | StkId o; | 464 | StkId o; |
465 | LUA_LOCK; | 465 | LUA_LOCK(L); |
466 | o = Index(L, index); | 466 | o = Index(L, index); |
467 | lua_assert(ttype(o) == LUA_TTABLE); | 467 | lua_assert(ttype(o) == LUA_TTABLE); |
468 | setobj(luaH_setnum(L, hvalue(o), n), (L->top-1)); | 468 | setobj(luaH_setnum(L, hvalue(o), n), (L->top-1)); |
469 | L->top--; | 469 | L->top--; |
470 | LUA_UNLOCK; | 470 | LUA_UNLOCK(L); |
471 | } | 471 | } |
472 | 472 | ||
473 | 473 | ||
474 | LUA_API void lua_setglobals (lua_State *L) { | 474 | LUA_API void lua_setglobals (lua_State *L) { |
475 | StkId newtable; | 475 | StkId newtable; |
476 | LUA_LOCK; | 476 | LUA_LOCK(L); |
477 | newtable = --L->top; | 477 | newtable = --L->top; |
478 | lua_assert(ttype(newtable) == LUA_TTABLE); | 478 | lua_assert(ttype(newtable) == LUA_TTABLE); |
479 | L->gt = hvalue(newtable); | 479 | L->gt = hvalue(newtable); |
480 | LUA_UNLOCK; | 480 | LUA_UNLOCK(L); |
481 | } | 481 | } |
482 | 482 | ||
483 | 483 | ||
484 | LUA_API int lua_ref (lua_State *L, int lock) { | 484 | LUA_API int lua_ref (lua_State *L, int lock) { |
485 | int ref; | 485 | int ref; |
486 | LUA_LOCK; | 486 | LUA_LOCK(L); |
487 | if (ttype(L->top-1) == LUA_TNIL) | 487 | if (ttype(L->top-1) == LUA_TNIL) |
488 | ref = LUA_REFNIL; | 488 | ref = LUA_REFNIL; |
489 | else { | 489 | else { |
@@ -500,7 +500,7 @@ LUA_API int lua_ref (lua_State *L, int lock) { | |||
500 | G(L)->refArray[ref].st = lock ? LOCK : HOLD; | 500 | G(L)->refArray[ref].st = lock ? LOCK : HOLD; |
501 | } | 501 | } |
502 | L->top--; | 502 | L->top--; |
503 | LUA_UNLOCK; | 503 | LUA_UNLOCK(L); |
504 | return ref; | 504 | return ref; |
505 | } | 505 | } |
506 | 506 | ||
@@ -511,9 +511,9 @@ LUA_API int lua_ref (lua_State *L, int lock) { | |||
511 | */ | 511 | */ |
512 | 512 | ||
513 | LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults) { | 513 | LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults) { |
514 | LUA_LOCK; | 514 | LUA_LOCK(L); |
515 | luaD_call(L, L->top-(nargs+1), nresults); | 515 | luaD_call(L, L->top-(nargs+1), nresults); |
516 | LUA_UNLOCK; | 516 | LUA_UNLOCK(L); |
517 | } | 517 | } |
518 | 518 | ||
519 | 519 | ||
@@ -527,28 +527,28 @@ LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults) { | |||
527 | 527 | ||
528 | LUA_API int lua_getgcthreshold (lua_State *L) { | 528 | LUA_API int lua_getgcthreshold (lua_State *L) { |
529 | int threshold; | 529 | int threshold; |
530 | LUA_LOCK; | 530 | LUA_LOCK(L); |
531 | threshold = GCscale(G(L)->GCthreshold); | 531 | threshold = GCscale(G(L)->GCthreshold); |
532 | LUA_UNLOCK; | 532 | LUA_UNLOCK(L); |
533 | return threshold; | 533 | return threshold; |
534 | } | 534 | } |
535 | 535 | ||
536 | LUA_API int lua_getgccount (lua_State *L) { | 536 | LUA_API int lua_getgccount (lua_State *L) { |
537 | int count; | 537 | int count; |
538 | LUA_LOCK; | 538 | LUA_LOCK(L); |
539 | count = GCscale(G(L)->nblocks); | 539 | count = GCscale(G(L)->nblocks); |
540 | LUA_UNLOCK; | 540 | LUA_UNLOCK(L); |
541 | return count; | 541 | return count; |
542 | } | 542 | } |
543 | 543 | ||
544 | LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) { | 544 | LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) { |
545 | LUA_LOCK; | 545 | LUA_LOCK(L); |
546 | if (newthreshold > GCscale(ULONG_MAX)) | 546 | if (newthreshold > GCscale(ULONG_MAX)) |
547 | G(L)->GCthreshold = ULONG_MAX; | 547 | G(L)->GCthreshold = ULONG_MAX; |
548 | else | 548 | else |
549 | G(L)->GCthreshold = GCunscale(newthreshold); | 549 | G(L)->GCthreshold = GCunscale(newthreshold); |
550 | luaC_checkGC(L); | 550 | luaC_checkGC(L); |
551 | LUA_UNLOCK; | 551 | LUA_UNLOCK(L); |
552 | } | 552 | } |
553 | 553 | ||
554 | 554 | ||
@@ -558,7 +558,7 @@ LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) { | |||
558 | 558 | ||
559 | LUA_API int lua_newtype (lua_State *L, const char *name, int basictype) { | 559 | LUA_API int lua_newtype (lua_State *L, const char *name, int basictype) { |
560 | int tag; | 560 | int tag; |
561 | LUA_LOCK; | 561 | LUA_LOCK(L); |
562 | if (basictype != LUA_TNONE && | 562 | if (basictype != LUA_TNONE && |
563 | basictype != LUA_TTABLE && | 563 | basictype != LUA_TTABLE && |
564 | basictype != LUA_TUSERDATA) | 564 | basictype != LUA_TUSERDATA) |
@@ -566,7 +566,7 @@ LUA_API int lua_newtype (lua_State *L, const char *name, int basictype) { | |||
566 | tag = luaT_newtag(L, name, basictype); | 566 | tag = luaT_newtag(L, name, basictype); |
567 | if (tag == LUA_TNONE) | 567 | if (tag == LUA_TNONE) |
568 | luaO_verror(L, "type name '%.30s' already exists", name); | 568 | luaO_verror(L, "type name '%.30s' already exists", name); |
569 | LUA_UNLOCK; | 569 | LUA_UNLOCK(L); |
570 | return tag; | 570 | return tag; |
571 | } | 571 | } |
572 | 572 | ||
@@ -574,7 +574,7 @@ LUA_API int lua_newtype (lua_State *L, const char *name, int basictype) { | |||
574 | LUA_API int lua_type2tag (lua_State *L, const char *name) { | 574 | LUA_API int lua_type2tag (lua_State *L, const char *name) { |
575 | int tag; | 575 | int tag; |
576 | const TObject *v; | 576 | const TObject *v; |
577 | LUA_LOCK; | 577 | LUA_LOCK(L); |
578 | v = luaH_getstr(G(L)->type2tag, luaS_new(L, name)); | 578 | v = luaH_getstr(G(L)->type2tag, luaS_new(L, name)); |
579 | if (ttype(v) == LUA_TNIL) | 579 | if (ttype(v) == LUA_TNIL) |
580 | tag = LUA_TNONE; | 580 | tag = LUA_TNONE; |
@@ -582,14 +582,14 @@ LUA_API int lua_type2tag (lua_State *L, const char *name) { | |||
582 | lua_assert(ttype(v) == LUA_TNUMBER); | 582 | lua_assert(ttype(v) == LUA_TNUMBER); |
583 | tag = (int)nvalue(v); | 583 | tag = (int)nvalue(v); |
584 | } | 584 | } |
585 | LUA_UNLOCK; | 585 | LUA_UNLOCK(L); |
586 | return tag; | 586 | return tag; |
587 | } | 587 | } |
588 | 588 | ||
589 | 589 | ||
590 | LUA_API void lua_settag (lua_State *L, int tag) { | 590 | LUA_API void lua_settag (lua_State *L, int tag) { |
591 | int basictype; | 591 | int basictype; |
592 | LUA_LOCK; | 592 | LUA_LOCK(L); |
593 | if (tag < 0 || tag >= G(L)->ntag) | 593 | if (tag < 0 || tag >= G(L)->ntag) |
594 | luaO_verror(L, "%d is not a valid tag", tag); | 594 | luaO_verror(L, "%d is not a valid tag", tag); |
595 | basictype = G(L)->TMtable[tag].basictype; | 595 | basictype = G(L)->TMtable[tag].basictype; |
@@ -607,25 +607,25 @@ LUA_API void lua_settag (lua_State *L, int tag) { | |||
607 | luaO_verror(L, "cannot change the tag of a %.20s", | 607 | luaO_verror(L, "cannot change the tag of a %.20s", |
608 | luaT_typename(G(L), L->top-1)); | 608 | luaT_typename(G(L), L->top-1)); |
609 | } | 609 | } |
610 | LUA_UNLOCK; | 610 | LUA_UNLOCK(L); |
611 | } | 611 | } |
612 | 612 | ||
613 | 613 | ||
614 | LUA_API void lua_error (lua_State *L, const char *s) { | 614 | LUA_API void lua_error (lua_State *L, const char *s) { |
615 | LUA_LOCK; | 615 | LUA_LOCK(L); |
616 | luaD_error(L, s); | 616 | luaD_error(L, s); |
617 | LUA_UNLOCK; | 617 | LUA_UNLOCK(L); |
618 | } | 618 | } |
619 | 619 | ||
620 | 620 | ||
621 | LUA_API void lua_unref (lua_State *L, int ref) { | 621 | LUA_API void lua_unref (lua_State *L, int ref) { |
622 | LUA_LOCK; | 622 | LUA_LOCK(L); |
623 | if (ref >= 0) { | 623 | if (ref >= 0) { |
624 | lua_assert(ref < G(L)->nref && G(L)->refArray[ref].st < 0); | 624 | lua_assert(ref < G(L)->nref && G(L)->refArray[ref].st < 0); |
625 | G(L)->refArray[ref].st = G(L)->refFree; | 625 | G(L)->refArray[ref].st = G(L)->refFree; |
626 | G(L)->refFree = ref; | 626 | G(L)->refFree = ref; |
627 | } | 627 | } |
628 | LUA_UNLOCK; | 628 | LUA_UNLOCK(L); |
629 | } | 629 | } |
630 | 630 | ||
631 | 631 | ||
@@ -633,7 +633,7 @@ LUA_API int lua_next (lua_State *L, int index) { | |||
633 | StkId t; | 633 | StkId t; |
634 | Node *n; | 634 | Node *n; |
635 | int more; | 635 | int more; |
636 | LUA_LOCK; | 636 | LUA_LOCK(L); |
637 | t = luaA_index(L, index); | 637 | t = luaA_index(L, index); |
638 | lua_assert(ttype(t) == LUA_TTABLE); | 638 | lua_assert(ttype(t) == LUA_TTABLE); |
639 | n = luaH_next(L, hvalue(t), luaA_index(L, -1)); | 639 | n = luaH_next(L, hvalue(t), luaA_index(L, -1)); |
@@ -647,7 +647,7 @@ LUA_API int lua_next (lua_State *L, int index) { | |||
647 | L->top -= 1; /* remove key */ | 647 | L->top -= 1; /* remove key */ |
648 | more = 0; | 648 | more = 0; |
649 | } | 649 | } |
650 | LUA_UNLOCK; | 650 | LUA_UNLOCK(L); |
651 | return more; | 651 | return more; |
652 | } | 652 | } |
653 | 653 | ||
@@ -656,7 +656,7 @@ LUA_API int lua_getn (lua_State *L, int index) { | |||
656 | Hash *h; | 656 | Hash *h; |
657 | const TObject *value; | 657 | const TObject *value; |
658 | int n; | 658 | int n; |
659 | LUA_LOCK; | 659 | LUA_LOCK(L); |
660 | h = hvalue(luaA_index(L, index)); | 660 | h = hvalue(luaA_index(L, index)); |
661 | value = luaH_getstr(h, luaS_newliteral(L, "n")); /* = h.n */ | 661 | value = luaH_getstr(h, luaS_newliteral(L, "n")); /* = h.n */ |
662 | if (ttype(value) == LUA_TNUMBER) | 662 | if (ttype(value) == LUA_TNUMBER) |
@@ -674,32 +674,32 @@ LUA_API int lua_getn (lua_State *L, int index) { | |||
674 | } | 674 | } |
675 | n = (int)max; | 675 | n = (int)max; |
676 | } | 676 | } |
677 | LUA_UNLOCK; | 677 | LUA_UNLOCK(L); |
678 | return n; | 678 | return n; |
679 | } | 679 | } |
680 | 680 | ||
681 | 681 | ||
682 | LUA_API void lua_concat (lua_State *L, int n) { | 682 | LUA_API void lua_concat (lua_State *L, int n) { |
683 | StkId top; | 683 | StkId top; |
684 | LUA_LOCK; | 684 | LUA_LOCK(L); |
685 | top = L->top; | 685 | top = L->top; |
686 | luaV_strconc(L, n, top); | 686 | luaV_strconc(L, n, top); |
687 | L->top = top-(n-1); | 687 | L->top = top-(n-1); |
688 | luaC_checkGC(L); | 688 | luaC_checkGC(L); |
689 | LUA_UNLOCK; | 689 | LUA_UNLOCK(L); |
690 | } | 690 | } |
691 | 691 | ||
692 | 692 | ||
693 | LUA_API void *lua_newuserdata (lua_State *L, size_t size) { | 693 | LUA_API void *lua_newuserdata (lua_State *L, size_t size) { |
694 | TString *ts; | 694 | TString *ts; |
695 | void *p; | 695 | void *p; |
696 | LUA_LOCK; | 696 | LUA_LOCK(L); |
697 | if (size == 0) size = 1; | 697 | if (size == 0) size = 1; |
698 | ts = luaS_newudata(L, size, NULL); | 698 | ts = luaS_newudata(L, size, NULL); |
699 | setuvalue(L->top, ts); | 699 | setuvalue(L->top, ts); |
700 | api_incr_top(L); | 700 | api_incr_top(L); |
701 | p = ts->u.d.value; | 701 | p = ts->u.d.value; |
702 | LUA_UNLOCK; | 702 | LUA_UNLOCK(L); |
703 | return p; | 703 | return p; |
704 | } | 704 | } |
705 | 705 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 1.57 2001/01/26 11:45:51 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.58 2001/01/29 17:16:58 roberto Exp roberto $ |
3 | ** Debug Interface | 3 | ** Debug Interface |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -42,20 +42,20 @@ static int isLmark (StkId o) { | |||
42 | 42 | ||
43 | LUA_API lua_Hook lua_setcallhook (lua_State *L, lua_Hook func) { | 43 | LUA_API lua_Hook lua_setcallhook (lua_State *L, lua_Hook func) { |
44 | lua_Hook oldhook; | 44 | lua_Hook oldhook; |
45 | LUA_LOCK; | 45 | LUA_LOCK(L); |
46 | oldhook = L->callhook; | 46 | oldhook = L->callhook; |
47 | L->callhook = func; | 47 | L->callhook = func; |
48 | LUA_UNLOCK; | 48 | LUA_UNLOCK(L); |
49 | return oldhook; | 49 | return oldhook; |
50 | } | 50 | } |
51 | 51 | ||
52 | 52 | ||
53 | LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func) { | 53 | LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func) { |
54 | lua_Hook oldhook; | 54 | lua_Hook oldhook; |
55 | LUA_LOCK; | 55 | LUA_LOCK(L); |
56 | oldhook = L->linehook; | 56 | oldhook = L->linehook; |
57 | L->linehook = func; | 57 | L->linehook = func; |
58 | LUA_UNLOCK; | 58 | LUA_UNLOCK(L); |
59 | return oldhook; | 59 | return oldhook; |
60 | } | 60 | } |
61 | 61 | ||
@@ -76,14 +76,14 @@ static StkId aux_stackedfunction (lua_State *L, int level, StkId top) { | |||
76 | LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { | 76 | LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { |
77 | StkId f; | 77 | StkId f; |
78 | int status; | 78 | int status; |
79 | LUA_LOCK; | 79 | LUA_LOCK(L); |
80 | f = aux_stackedfunction(L, level, L->top); | 80 | f = aux_stackedfunction(L, level, L->top); |
81 | if (f == NULL) status = 0; /* there is no such level */ | 81 | if (f == NULL) status = 0; /* there is no such level */ |
82 | else { | 82 | else { |
83 | ar->_func = f; | 83 | ar->_func = f; |
84 | status = 1; | 84 | status = 1; |
85 | } | 85 | } |
86 | LUA_UNLOCK; | 86 | LUA_UNLOCK(L); |
87 | return status; | 87 | return status; |
88 | } | 88 | } |
89 | 89 | ||
@@ -162,7 +162,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
162 | const char *name; | 162 | const char *name; |
163 | StkId f; | 163 | StkId f; |
164 | Proto *fp; | 164 | Proto *fp; |
165 | LUA_LOCK; | 165 | LUA_LOCK(L); |
166 | name = NULL; | 166 | name = NULL; |
167 | f = ar->_func; | 167 | f = ar->_func; |
168 | fp = getluaproto(f); | 168 | fp = getluaproto(f); |
@@ -171,7 +171,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
171 | if (name) | 171 | if (name) |
172 | luaA_pushobject(L, (f+1)+(n-1)); /* push value */ | 172 | luaA_pushobject(L, (f+1)+(n-1)); /* push value */ |
173 | } | 173 | } |
174 | LUA_UNLOCK; | 174 | LUA_UNLOCK(L); |
175 | return name; | 175 | return name; |
176 | } | 176 | } |
177 | 177 | ||
@@ -180,7 +180,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
180 | const char *name; | 180 | const char *name; |
181 | StkId f; | 181 | StkId f; |
182 | Proto *fp; | 182 | Proto *fp; |
183 | LUA_LOCK; | 183 | LUA_LOCK(L); |
184 | name = NULL; | 184 | name = NULL; |
185 | f = ar->_func; | 185 | f = ar->_func; |
186 | fp = getluaproto(f); | 186 | fp = getluaproto(f); |
@@ -192,7 +192,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { | |||
192 | else | 192 | else |
193 | setobj((f+1)+(n-1), L->top); | 193 | setobj((f+1)+(n-1), L->top); |
194 | } | 194 | } |
195 | LUA_UNLOCK; | 195 | LUA_UNLOCK(L); |
196 | return name; | 196 | return name; |
197 | } | 197 | } |
198 | 198 | ||
@@ -272,7 +272,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | |||
272 | StkId func; | 272 | StkId func; |
273 | int isactive; | 273 | int isactive; |
274 | int status = 1; | 274 | int status = 1; |
275 | LUA_LOCK; | 275 | LUA_LOCK(L); |
276 | isactive = (*what != '>'); | 276 | isactive = (*what != '>'); |
277 | if (isactive) | 277 | if (isactive) |
278 | func = ar->_func; | 278 | func = ar->_func; |
@@ -309,7 +309,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | |||
309 | } | 309 | } |
310 | } | 310 | } |
311 | if (!isactive) L->top--; /* pop function */ | 311 | if (!isactive) L->top--; /* pop function */ |
312 | LUA_UNLOCK; | 312 | LUA_UNLOCK(L); |
313 | return status; | 313 | return status; |
314 | } | 314 | } |
315 | 315 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.119 2001/01/29 19:34:02 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.120 2001/02/01 17:40:48 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -94,9 +94,9 @@ static void dohook (lua_State *L, lua_Debug *ar, lua_Hook hook) { | |||
94 | StkId old_top = L->Cbase = L->top; | 94 | StkId old_top = L->Cbase = L->top; |
95 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ | 95 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ |
96 | L->allowhooks = 0; /* cannot call hooks inside a hook */ | 96 | L->allowhooks = 0; /* cannot call hooks inside a hook */ |
97 | LUA_UNLOCK; | 97 | LUA_UNLOCK(L); |
98 | (*hook)(L, ar); | 98 | (*hook)(L, ar); |
99 | LUA_LOCK; | 99 | LUA_LOCK(L); |
100 | lua_assert(L->allowhooks == 0); | 100 | lua_assert(L->allowhooks == 0); |
101 | L->allowhooks = 1; | 101 | L->allowhooks = 1; |
102 | L->top = old_top; | 102 | L->top = old_top; |
@@ -135,9 +135,9 @@ static StkId callCclosure (lua_State *L, const struct Closure *cl, StkId base) { | |||
135 | luaD_checkstack(L, nup+LUA_MINSTACK); /* ensure minimum stack size */ | 135 | luaD_checkstack(L, nup+LUA_MINSTACK); /* ensure minimum stack size */ |
136 | for (n=0; n<nup; n++) /* copy upvalues as extra arguments */ | 136 | for (n=0; n<nup; n++) /* copy upvalues as extra arguments */ |
137 | setobj(L->top++, &cl->upvalue[n]); | 137 | setobj(L->top++, &cl->upvalue[n]); |
138 | LUA_UNLOCK; | 138 | LUA_UNLOCK(L); |
139 | n = (*cl->f.c)(L); /* do the actual call */ | 139 | n = (*cl->f.c)(L); /* do the actual call */ |
140 | LUA_LOCK; | 140 | LUA_LOCK(L); |
141 | L->Cbase = old_Cbase; /* restore old C base */ | 141 | L->Cbase = old_Cbase; /* restore old C base */ |
142 | return L->top - n; /* return index of first result */ | 142 | return L->top - n; /* return index of first result */ |
143 | } | 143 | } |
@@ -219,13 +219,13 @@ LUA_API int lua_call (lua_State *L, int nargs, int nresults) { | |||
219 | StkId func; | 219 | StkId func; |
220 | struct CallS c; | 220 | struct CallS c; |
221 | int status; | 221 | int status; |
222 | LUA_LOCK; | 222 | LUA_LOCK(L); |
223 | func = L->top - (nargs+1); /* function to be called */ | 223 | func = L->top - (nargs+1); /* function to be called */ |
224 | c.func = func; c.nresults = nresults; | 224 | c.func = func; c.nresults = nresults; |
225 | status = luaD_runprotected(L, f_call, &c); | 225 | status = luaD_runprotected(L, f_call, &c); |
226 | if (status != 0) /* an error occurred? */ | 226 | if (status != 0) /* an error occurred? */ |
227 | L->top = func; /* remove parameters from the stack */ | 227 | L->top = func; /* remove parameters from the stack */ |
228 | LUA_UNLOCK; | 228 | LUA_UNLOCK(L); |
229 | return status; | 229 | return status; |
230 | } | 230 | } |
231 | 231 | ||
@@ -233,23 +233,23 @@ LUA_API int lua_call (lua_State *L, int nargs, int nresults) { | |||
233 | /* | 233 | /* |
234 | ** Execute a protected parser. | 234 | ** Execute a protected parser. |
235 | */ | 235 | */ |
236 | struct ParserS { /* data to `f_parser' */ | 236 | struct SParser { /* data to `f_parser' */ |
237 | ZIO *z; | 237 | ZIO *z; |
238 | int bin; | 238 | int bin; |
239 | }; | 239 | }; |
240 | 240 | ||
241 | static void f_parser (lua_State *L, void *ud) { | 241 | static void f_parser (lua_State *L, void *ud) { |
242 | struct ParserS *p = (struct ParserS *)ud; | 242 | struct SParser *p = (struct SParser *)ud; |
243 | Proto *tf = p->bin ? luaU_undump(L, p->z) : luaY_parser(L, p->z); | 243 | Proto *tf = p->bin ? luaU_undump(L, p->z) : luaY_parser(L, p->z); |
244 | luaV_Lclosure(L, tf, 0); | 244 | luaV_Lclosure(L, tf, 0); |
245 | } | 245 | } |
246 | 246 | ||
247 | 247 | ||
248 | static int protectedparser (lua_State *L, ZIO *z, int bin) { | 248 | static int protectedparser (lua_State *L, ZIO *z, int bin) { |
249 | struct ParserS p; | 249 | struct SParser p; |
250 | mem_int old_blocks; | 250 | mem_int old_blocks; |
251 | int status; | 251 | int status; |
252 | LUA_LOCK; | 252 | LUA_LOCK(L); |
253 | p.z = z; p.bin = bin; | 253 | p.z = z; p.bin = bin; |
254 | luaC_checkGC(L); | 254 | luaC_checkGC(L); |
255 | old_blocks = G(L)->nblocks; | 255 | old_blocks = G(L)->nblocks; |
@@ -261,7 +261,7 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) { | |||
261 | } | 261 | } |
262 | else if (status == LUA_ERRRUN) /* an error occurred: correct error code */ | 262 | else if (status == LUA_ERRRUN) /* an error occurred: correct error code */ |
263 | status = LUA_ERRSYNTAX; | 263 | status = LUA_ERRSYNTAX; |
264 | LUA_UNLOCK; | 264 | LUA_UNLOCK(L); |
265 | return status; | 265 | return status; |
266 | } | 266 | } |
267 | 267 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 1.83 2001/01/29 19:34:02 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.84 2001/02/01 17:40:48 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -17,6 +17,19 @@ | |||
17 | #include "ltm.h" | 17 | #include "ltm.h" |
18 | 18 | ||
19 | 19 | ||
20 | /* | ||
21 | ** optional "lock" for GC | ||
22 | ** (when Lua calls GC tag methods it unlocks the regular lock) | ||
23 | */ | ||
24 | #ifndef LUA_LOCKGC | ||
25 | #define LUA_LOCKGC(L) { | ||
26 | #endif | ||
27 | |||
28 | #ifndef LUA_UNLOCKGC | ||
29 | #define LUA_UNLOCKGC(L) } | ||
30 | #endif | ||
31 | |||
32 | |||
20 | typedef struct GCState { | 33 | typedef struct GCState { |
21 | Hash *tmark; /* list of marked tables to be visited */ | 34 | Hash *tmark; /* list of marked tables to be visited */ |
22 | Closure *cmark; /* list of marked closures to be visited */ | 35 | Closure *cmark; /* list of marked closures to be visited */ |
@@ -351,12 +364,14 @@ static void callgcTMudata (lua_State *L) { | |||
351 | 364 | ||
352 | 365 | ||
353 | void luaC_collect (lua_State *L, int all) { | 366 | void luaC_collect (lua_State *L, int all) { |
367 | LUA_LOCKGC(L); | ||
354 | collectudata(L, all); | 368 | collectudata(L, all); |
355 | callgcTMudata(L); | 369 | callgcTMudata(L); |
356 | collectstrings(L, all); | 370 | collectstrings(L, all); |
357 | collecttable(L); | 371 | collecttable(L); |
358 | collectproto(L); | 372 | collectproto(L); |
359 | collectclosure(L); | 373 | collectclosure(L); |
374 | LUA_UNLOCKGC(L); | ||
360 | } | 375 | } |
361 | 376 | ||
362 | 377 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmem.h,v 1.18 2000/12/26 18:46:09 roberto Exp roberto $ | 2 | ** $Id: lmem.h,v 1.19 2000/12/28 12:55:41 roberto Exp roberto $ |
3 | ** Interface to Memory Manager | 3 | ** Interface to Memory Manager |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -38,13 +38,5 @@ void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem, | |||
38 | (luint32)(n)*(luint32)sizeof(t))) | 38 | (luint32)(n)*(luint32)sizeof(t))) |
39 | 39 | ||
40 | 40 | ||
41 | #ifdef LUA_DEBUG | ||
42 | extern mem_int memdebug_numblocks; | ||
43 | extern mem_int memdebug_total; | ||
44 | extern mem_int memdebug_maxmem; | ||
45 | extern mem_int memdebug_memlimit; | ||
46 | #endif | ||
47 | |||
48 | |||
49 | #endif | 41 | #endif |
50 | 42 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.c,v 1.62 2001/01/26 14:16:35 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 1.63 2001/01/29 19:34:02 roberto Exp roberto $ |
3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -19,8 +19,7 @@ | |||
19 | 19 | ||
20 | 20 | ||
21 | 21 | ||
22 | const char luaO_ttnil = LUA_TNIL; | 22 | const TObject luaO_nilobject = {LUA_TNIL, {NULL}}; |
23 | const TObject luaO_nilobject = {LUA_TNIL, {(void *)&luaO_ttnil}}; | ||
24 | 23 | ||
25 | 24 | ||
26 | /* | 25 | /* |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 1.91 2001/01/29 19:34:02 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.92 2001/02/01 17:40:48 roberto Exp roberto $ |
3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -12,19 +12,12 @@ | |||
12 | #include "lua.h" | 12 | #include "lua.h" |
13 | 13 | ||
14 | 14 | ||
15 | #ifdef LUA_DEBUG | 15 | #ifndef lua_assert |
16 | #undef NDEBUG | ||
17 | #include <assert.h> | ||
18 | #define lua_assert(c) assert(c) | ||
19 | #else | ||
20 | #define lua_assert(c) /* empty */ | 16 | #define lua_assert(c) /* empty */ |
21 | #endif | 17 | #endif |
22 | 18 | ||
23 | 19 | ||
24 | #ifdef LUA_DEBUG | 20 | #ifndef UNUSED |
25 | /* to avoid warnings, and make sure value is really unused */ | ||
26 | #define UNUSED(x) (x=0, (void)(x)) | ||
27 | #else | ||
28 | #define UNUSED(x) ((void)(x)) /* to avoid warnings */ | 21 | #define UNUSED(x) ((void)(x)) /* to avoid warnings */ |
29 | #endif | 22 | #endif |
30 | 23 | ||
@@ -88,8 +81,7 @@ typedef struct lua_TObject { | |||
88 | { TObject *_o=(obj); struct CallInfo *_v=(x); \ | 81 | { TObject *_o=(obj); struct CallInfo *_v=(x); \ |
89 | _o->tt=LUA_TMARK; _o->value.v=_v; } | 82 | _o->tt=LUA_TMARK; _o->value.v=_v; } |
90 | 83 | ||
91 | #define setnilvalue(obj) \ | 84 | #define setnilvalue(obj) ((obj)->tt=LUA_TNIL) |
92 | { TObject *_o=(obj); _o->tt=LUA_TNIL; _o->value.v = (void *)&luaO_ttnil; } | ||
93 | 85 | ||
94 | #define setobj(obj1,obj2) \ | 86 | #define setobj(obj1,obj2) \ |
95 | { TObject *o1=(obj1); const TObject *o2=(obj2); \ | 87 | { TObject *o1=(obj1); const TObject *o2=(obj2); \ |
@@ -220,7 +212,6 @@ typedef struct CallInfo { | |||
220 | } CallInfo; | 212 | } CallInfo; |
221 | 213 | ||
222 | 214 | ||
223 | extern const char luaO_ttnil; /* "address" of the nil value */ | ||
224 | extern const TObject luaO_nilobject; | 215 | extern const TObject luaO_nilobject; |
225 | 216 | ||
226 | 217 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.c,v 1.54 2001/01/25 16:45:36 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 1.55 2001/01/26 11:45:51 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -19,33 +19,27 @@ | |||
19 | #include "ltm.h" | 19 | #include "ltm.h" |
20 | 20 | ||
21 | 21 | ||
22 | #ifdef LUA_DEBUG | ||
23 | static lua_State *lua_state = NULL; | ||
24 | void luaB_opentests (lua_State *L); | ||
25 | int islocked = 0; | ||
26 | #endif | ||
27 | |||
28 | |||
29 | /* | ||
30 | ** built-in implementation for ERRORMESSAGE. In a "correct" environment | ||
31 | ** ERRORMESSAGE should have an external definition, and so this function | ||
32 | ** would not be used. | ||
33 | */ | ||
34 | static int errormessage (lua_State *L) { | ||
35 | const char *s = lua_tostring(L, 1); | ||
36 | if (s == NULL) s = "(no message)"; | ||
37 | fprintf(stderr, "error: %s\n", s); | ||
38 | return 0; | ||
39 | } | ||
40 | |||
41 | |||
42 | struct Sopen { | 22 | struct Sopen { |
43 | int stacksize; | 23 | int stacksize; |
44 | lua_State *L; | 24 | lua_State *L; |
45 | }; | 25 | }; |
46 | 26 | ||
47 | 27 | ||
48 | static void close_state (lua_State *L); | 28 | static void close_state (lua_State *L, lua_State *OL); |
29 | |||
30 | |||
31 | /* | ||
32 | ** initialize ref array and registry | ||
33 | */ | ||
34 | #define INIT_REFSIZE 4 | ||
35 | |||
36 | static void ref_init (lua_State *L) { | ||
37 | G(L)->refArray = luaM_newvector(L, INIT_REFSIZE, struct Ref); | ||
38 | G(L)->sizeref = INIT_REFSIZE; | ||
39 | sethvalue(&G(L)->refArray[0].o, luaH_new(L, 0)); | ||
40 | G(L)->refArray[0].st = LOCK; | ||
41 | G(L)->nref = 1; | ||
42 | } | ||
49 | 43 | ||
50 | 44 | ||
51 | /* | 45 | /* |
@@ -90,17 +84,8 @@ static void f_luaopen (lua_State *L, void *ud) { | |||
90 | luaS_init(L); | 84 | luaS_init(L); |
91 | luaX_init(L); | 85 | luaX_init(L); |
92 | luaT_init(L); | 86 | luaT_init(L); |
87 | ref_init(L); | ||
93 | G(L)->GCthreshold = 4*G(L)->nblocks; | 88 | G(L)->GCthreshold = 4*G(L)->nblocks; |
94 | LUA_UNLOCK; /* temporary exit to use the API */ | ||
95 | lua_newtable(L); | ||
96 | lua_ref(L, 1); /* create registry */ | ||
97 | lua_register(L, LUA_ERRORMESSAGE, errormessage); | ||
98 | #ifdef LUA_DEBUG | ||
99 | luaB_opentests(L); | ||
100 | if (lua_state == NULL) lua_state = L; /* keep first state to be opened */ | ||
101 | lua_assert(lua_gettop(L) == 0); | ||
102 | #endif | ||
103 | LUA_LOCK; /* go back inside */ | ||
104 | } | 89 | } |
105 | } | 90 | } |
106 | 91 | ||
@@ -108,7 +93,7 @@ static void f_luaopen (lua_State *L, void *ud) { | |||
108 | LUA_API lua_State *lua_open (lua_State *OL, int stacksize) { | 93 | LUA_API lua_State *lua_open (lua_State *OL, int stacksize) { |
109 | struct Sopen so; | 94 | struct Sopen so; |
110 | lua_State *L; | 95 | lua_State *L; |
111 | LUA_LOCK; | 96 | if (OL) LUA_LOCK(OL); |
112 | L = luaM_new(OL, lua_State); | 97 | L = luaM_new(OL, lua_State); |
113 | if (L) { /* allocation OK? */ | 98 | if (L) { /* allocation OK? */ |
114 | L->G = NULL; | 99 | L->G = NULL; |
@@ -123,20 +108,17 @@ LUA_API lua_State *lua_open (lua_State *OL, int stacksize) { | |||
123 | so.L = OL; | 108 | so.L = OL; |
124 | if (luaD_runprotected(L, f_luaopen, &so) != 0) { | 109 | if (luaD_runprotected(L, f_luaopen, &so) != 0) { |
125 | /* memory allocation error: free partial state */ | 110 | /* memory allocation error: free partial state */ |
126 | close_state(L); | 111 | close_state(L, OL); |
127 | L = NULL; | 112 | L = NULL; |
128 | } | 113 | } |
129 | } | 114 | } |
130 | LUA_UNLOCK; | 115 | if (OL) LUA_UNLOCK(OL); |
131 | return L; | 116 | return L; |
132 | } | 117 | } |
133 | 118 | ||
134 | 119 | ||
135 | static void close_state (lua_State *L) { | 120 | static void close_state (lua_State *L, lua_State *OL) { |
136 | lua_State *L1; | 121 | if (OL != NULL) { /* are there other threads? */ |
137 | L1 = L->next; /* any surviving thread (if there is one) */ | ||
138 | if (L1 == L) L1 = NULL; /* no surviving threads */ | ||
139 | if (L1 != NULL) { /* are there other threads? */ | ||
140 | lua_assert(L->previous != L); | 122 | lua_assert(L->previous != L); |
141 | L->previous->next = L->next; | 123 | L->previous->next = L->next; |
142 | L->next->previous = L->previous; | 124 | L->next->previous = L->previous; |
@@ -152,15 +134,18 @@ static void close_state (lua_State *L) { | |||
152 | luaM_freearray(L, G(L)->Mbuffer, G(L)->Mbuffsize, char); | 134 | luaM_freearray(L, G(L)->Mbuffer, G(L)->Mbuffsize, char); |
153 | luaM_freelem(NULL, L->G, global_State); | 135 | luaM_freelem(NULL, L->G, global_State); |
154 | } | 136 | } |
155 | luaM_freearray(L1, L->stack, L->stacksize, TObject); | 137 | luaM_freearray(OL, L->stack, L->stacksize, TObject); |
156 | luaM_freelem(L1, L, lua_State); | 138 | luaM_freelem(OL, L, lua_State); |
157 | } | 139 | } |
158 | 140 | ||
159 | LUA_API void lua_close (lua_State *L) { | 141 | LUA_API void lua_close (lua_State *L) { |
142 | lua_State *OL; | ||
160 | lua_assert(L != lua_state || lua_gettop(L) == 0); | 143 | lua_assert(L != lua_state || lua_gettop(L) == 0); |
161 | LUA_LOCK; | 144 | LUA_LOCK(L); |
162 | close_state(L); | 145 | OL = L->next; /* any surviving thread (if there is one) */ |
163 | LUA_UNLOCK; | 146 | if (OL == L) OL = NULL; /* no surviving threads */ |
147 | close_state(L, OL); | ||
148 | if (OL) LUA_UNLOCK(OL); /* cannot unlock over a freed state */ | ||
164 | lua_assert(L != lua_state || memdebug_numblocks == 0); | 149 | lua_assert(L != lua_state || memdebug_numblocks == 0); |
165 | lua_assert(L != lua_state || memdebug_total == 0); | 150 | lua_assert(L != lua_state || memdebug_total == 0); |
166 | } | 151 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 1.48 2001/01/26 11:45:51 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 1.49 2001/02/01 17:40:48 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -12,24 +12,16 @@ | |||
12 | #include "luadebug.h" | 12 | #include "luadebug.h" |
13 | 13 | ||
14 | 14 | ||
15 | |||
16 | #ifdef LUA_DEBUG | ||
17 | extern int islocked; | ||
18 | #define LUA_LOCK lua_assert(islocked++ == 0) | ||
19 | #define LUA_UNLOCK lua_assert(--islocked == 0) | ||
20 | #endif | ||
21 | |||
22 | |||
23 | /* | 15 | /* |
24 | ** macros that control all entries and exits from Lua core machine | 16 | ** macros that control all entries and exits from Lua core machine |
25 | ** (mainly for thread syncronization) | 17 | ** (mainly for thread syncronization) |
26 | */ | 18 | */ |
27 | #ifndef LUA_LOCK | 19 | #ifndef LUA_LOCK |
28 | #define LUA_LOCK | 20 | #define LUA_LOCK(L) ((void) 0) |
29 | #endif | 21 | #endif |
30 | 22 | ||
31 | #ifndef LUA_UNLOCK | 23 | #ifndef LUA_UNLOCK |
32 | #define LUA_UNLOCK | 24 | #define LUA_UNLOCK(L) ((void) 0) |
33 | #endif | 25 | #endif |
34 | 26 | ||
35 | /* | 27 | /* |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 1.60 2001/01/29 17:16:58 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.61 2001/02/01 16:03:38 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -28,14 +28,16 @@ | |||
28 | #include "lualib.h" | 28 | #include "lualib.h" |
29 | 29 | ||
30 | 30 | ||
31 | void luaB_opentests (lua_State *L); | ||
32 | |||
33 | 31 | ||
34 | /* | 32 | /* |
35 | ** The whole module only makes sense with LUA_DEBUG on | 33 | ** The whole module only makes sense with LUA_DEBUG on |
36 | */ | 34 | */ |
37 | #ifdef LUA_DEBUG | 35 | #ifdef LUA_DEBUG |
38 | 36 | ||
37 | lua_State *lua_state = NULL; | ||
38 | |||
39 | int islocked = 0; | ||
40 | |||
39 | 41 | ||
40 | 42 | ||
41 | static void setnameval (lua_State *L, const char *name, int val) { | 43 | static void setnameval (lua_State *L, const char *name, int val) { |
@@ -279,6 +281,7 @@ static int udataval (lua_State *L) { | |||
279 | static int doonnewstack (lua_State *L) { | 281 | static int doonnewstack (lua_State *L) { |
280 | lua_State *L1 = lua_open(L, luaL_check_int(L, 1)); | 282 | lua_State *L1 = lua_open(L, luaL_check_int(L, 1)); |
281 | if (L1 == NULL) return 0; | 283 | if (L1 == NULL) return 0; |
284 | *((int **)L1) = &islocked; /* initialize the lock */ | ||
282 | lua_dostring(L1, luaL_check_string(L, 2)); | 285 | lua_dostring(L1, luaL_check_string(L, 2)); |
283 | lua_pushnumber(L, 1); | 286 | lua_pushnumber(L, 1); |
284 | lua_close(L1); | 287 | lua_close(L1); |
@@ -288,8 +291,10 @@ static int doonnewstack (lua_State *L) { | |||
288 | 291 | ||
289 | static int newstate (lua_State *L) { | 292 | static int newstate (lua_State *L) { |
290 | lua_State *L1 = lua_open(NULL, luaL_check_int(L, 1)); | 293 | lua_State *L1 = lua_open(NULL, luaL_check_int(L, 1)); |
291 | if (L1) | 294 | if (L1) { |
295 | *((int **)L1) = &islocked; /* initialize the lock */ | ||
292 | lua_pushuserdata(L, L1); | 296 | lua_pushuserdata(L, L1); |
297 | } | ||
293 | else | 298 | else |
294 | lua_pushnil(L); | 299 | lua_pushnil(L); |
295 | return 1; | 300 | return 1; |
@@ -311,6 +316,7 @@ static int loadlib (lua_State *L) { | |||
311 | static int closestate (lua_State *L) { | 316 | static int closestate (lua_State *L) { |
312 | luaL_checktype(L, 1, LUA_TUSERDATA); | 317 | luaL_checktype(L, 1, LUA_TUSERDATA); |
313 | lua_close((lua_State *)lua_touserdata(L, 1)); | 318 | lua_close((lua_State *)lua_touserdata(L, 1)); |
319 | LUA_UNLOCK(L); /* close cannot unlock that */ | ||
314 | return 0; | 320 | return 0; |
315 | } | 321 | } |
316 | 322 | ||
@@ -552,6 +558,9 @@ static const struct luaL_reg tests_funcs[] = { | |||
552 | 558 | ||
553 | 559 | ||
554 | void luaB_opentests (lua_State *L) { | 560 | void luaB_opentests (lua_State *L) { |
561 | *((int **)L) = &islocked; /* init lock */ | ||
562 | lua_state = L; /* keep first state to be opened */ | ||
563 | /* open lib in a new table */ | ||
555 | lua_newtable(L); | 564 | lua_newtable(L); |
556 | lua_getglobals(L); | 565 | lua_getglobals(L); |
557 | lua_pushvalue(L, -2); | 566 | lua_pushvalue(L, -2); |
@@ -559,6 +568,12 @@ void luaB_opentests (lua_State *L) { | |||
559 | luaL_openl(L, tests_funcs); /* open functions inside new table */ | 568 | luaL_openl(L, tests_funcs); /* open functions inside new table */ |
560 | lua_setglobals(L); /* restore old table of globals */ | 569 | lua_setglobals(L); /* restore old table of globals */ |
561 | lua_setglobal(L, "T"); /* set new table as global T */ | 570 | lua_setglobal(L, "T"); /* set new table as global T */ |
571 | /* open other libraries */ | ||
572 | lua_baselibopen(L); | ||
573 | lua_iolibopen(L); | ||
574 | lua_strlibopen(L); | ||
575 | lua_mathlibopen(L); | ||
576 | lua_dblibopen(L); | ||
562 | } | 577 | } |
563 | 578 | ||
564 | #endif | 579 | #endif |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.c,v 1.63 2001/01/25 16:45:36 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 1.64 2001/01/26 11:45:51 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 | */ |
@@ -111,14 +111,14 @@ static void checktag (lua_State *L, int tag) { | |||
111 | 111 | ||
112 | LUA_API int lua_copytagmethods (lua_State *L, int tagto, int tagfrom) { | 112 | LUA_API int lua_copytagmethods (lua_State *L, int tagto, int tagfrom) { |
113 | int e; | 113 | int e; |
114 | LUA_LOCK; | 114 | LUA_LOCK(L); |
115 | checktag(L, tagto); | 115 | checktag(L, tagto); |
116 | checktag(L, tagfrom); | 116 | checktag(L, tagfrom); |
117 | for (e=0; e<TM_N; e++) { | 117 | for (e=0; e<TM_N; e++) { |
118 | if (luaT_validevent(tagto, e)) | 118 | if (luaT_validevent(tagto, e)) |
119 | luaT_gettm(G(L), tagto, e) = luaT_gettm(G(L), tagfrom, e); | 119 | luaT_gettm(G(L), tagto, e) = luaT_gettm(G(L), tagfrom, e); |
120 | } | 120 | } |
121 | LUA_UNLOCK; | 121 | LUA_UNLOCK(L); |
122 | return tagto; | 122 | return tagto; |
123 | } | 123 | } |
124 | 124 | ||
@@ -156,7 +156,7 @@ const char *luaT_typename (global_State *G, const TObject *o) { | |||
156 | 156 | ||
157 | LUA_API void lua_gettagmethod (lua_State *L, int t, const char *event) { | 157 | LUA_API void lua_gettagmethod (lua_State *L, int t, const char *event) { |
158 | int e; | 158 | int e; |
159 | LUA_LOCK; | 159 | LUA_LOCK(L); |
160 | e = luaI_checkevent(L, event, t); | 160 | e = luaI_checkevent(L, event, t); |
161 | checktag(L, t); | 161 | checktag(L, t); |
162 | if (luaT_validevent(t, e) && luaT_gettm(G(L), t, e)) { | 162 | if (luaT_validevent(t, e) && luaT_gettm(G(L), t, e)) { |
@@ -165,13 +165,13 @@ LUA_API void lua_gettagmethod (lua_State *L, int t, const char *event) { | |||
165 | else | 165 | else |
166 | setnilvalue(L->top); | 166 | setnilvalue(L->top); |
167 | incr_top; | 167 | incr_top; |
168 | LUA_UNLOCK; | 168 | LUA_UNLOCK(L); |
169 | } | 169 | } |
170 | 170 | ||
171 | 171 | ||
172 | LUA_API void lua_settagmethod (lua_State *L, int t, const char *event) { | 172 | LUA_API void lua_settagmethod (lua_State *L, int t, const char *event) { |
173 | int e; | 173 | int e; |
174 | LUA_LOCK; | 174 | LUA_LOCK(L); |
175 | e = luaI_checkevent(L, event, t); | 175 | e = luaI_checkevent(L, event, t); |
176 | checktag(L, t); | 176 | checktag(L, t); |
177 | if (!luaT_validevent(t, e)) | 177 | if (!luaT_validevent(t, e)) |
@@ -190,6 +190,6 @@ LUA_API void lua_settagmethod (lua_State *L, int t, const char *event) { | |||
190 | luaD_error(L, "tag method must be a function (or nil)"); | 190 | luaD_error(L, "tag method must be a function (or nil)"); |
191 | } | 191 | } |
192 | L->top--; | 192 | L->top--; |
193 | LUA_UNLOCK; | 193 | LUA_UNLOCK(L); |
194 | } | 194 | } |
195 | 195 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.162 2001/02/01 16:03:38 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.163 2001/02/01 17:39:55 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -159,7 +159,7 @@ void luaV_settable (lua_State *L, StkId t, StkId key, StkId top) { | |||
159 | } | 159 | } |
160 | else { /* try a `settable' tag method */ | 160 | else { /* try a `settable' tag method */ |
161 | Closure *tm = luaT_gettmbyObj(G(L), t, TM_SETTABLE); | 161 | Closure *tm = luaT_gettmbyObj(G(L), t, TM_SETTABLE); |
162 | L->top = top; | 162 | lua_assert(L->top == top); |
163 | if (tm == NULL) /* no tag method? */ | 163 | if (tm == NULL) /* no tag method? */ |
164 | luaG_typeerror(L, t, "index"); | 164 | luaG_typeerror(L, t, "index"); |
165 | else { | 165 | else { |
@@ -206,7 +206,7 @@ void luaV_setglobal (lua_State *L, TString *s, StkId top) { | |||
206 | setobj(oldvalue, top-1); /* raw set */ | 206 | setobj(oldvalue, top-1); /* raw set */ |
207 | } | 207 | } |
208 | else { /* call tag method */ | 208 | else { /* call tag method */ |
209 | L->top = top; | 209 | lua_assert(L->top == top); |
210 | luaD_checkstack(L, 3); | 210 | luaD_checkstack(L, 3); |
211 | setobj(top+2, top-1); /* new value */ | 211 | setobj(top+2, top-1); /* new value */ |
212 | setobj(top+1, oldvalue); /* old value */ | 212 | setobj(top+1, oldvalue); /* old value */ |