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 /lapi.c | |
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
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 206 |
1 files changed, 103 insertions, 103 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 | ||