diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-01-18 13:59:09 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-01-18 13:59:09 -0200 |
commit | f2c451d7455aad3496f32dfa2bfca7f7e8b5376d (patch) | |
tree | 38e30f839516ff5b6178351750b5e3256f4dd98e /lapi.c | |
parent | 619edfd9e4c210bdfcfbf1e911d1760c53c4293f (diff) | |
download | lua-f2c451d7455aad3496f32dfa2bfca7f7e8b5376d.tar.gz lua-f2c451d7455aad3496f32dfa2bfca7f7e8b5376d.tar.bz2 lua-f2c451d7455aad3496f32dfa2bfca7f7e8b5376d.zip |
all accesses to TObjects done through macros
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 62 |
1 files changed, 28 insertions, 34 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.115 2001/01/10 17:41:50 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.116 2001/01/10 18:56:11 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 | */ |
@@ -33,7 +33,6 @@ const char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n" | |||
33 | 33 | ||
34 | 34 | ||
35 | 35 | ||
36 | |||
37 | TObject *luaA_index (lua_State *L, int index) { | 36 | TObject *luaA_index (lua_State *L, int index) { |
38 | return Index(L, index); | 37 | return Index(L, index); |
39 | } | 38 | } |
@@ -50,7 +49,7 @@ static TObject *luaA_indexAcceptable (lua_State *L, int index) { | |||
50 | 49 | ||
51 | 50 | ||
52 | void luaA_pushobject (lua_State *L, const TObject *o) { | 51 | void luaA_pushobject (lua_State *L, const TObject *o) { |
53 | *L->top = *o; | 52 | setobj(L->top, o); |
54 | incr_top; | 53 | incr_top; |
55 | } | 54 | } |
56 | 55 | ||
@@ -80,7 +79,7 @@ LUA_API void lua_settop (lua_State *L, int index) { | |||
80 | 79 | ||
81 | LUA_API void lua_remove (lua_State *L, int index) { | 80 | LUA_API void lua_remove (lua_State *L, int index) { |
82 | StkId p = luaA_index(L, index); | 81 | StkId p = luaA_index(L, index); |
83 | while (++p < L->top) *(p-1) = *p; | 82 | while (++p < L->top) setobj(p-1, p); |
84 | L->top--; | 83 | L->top--; |
85 | } | 84 | } |
86 | 85 | ||
@@ -88,14 +87,13 @@ LUA_API void lua_remove (lua_State *L, int index) { | |||
88 | LUA_API void lua_insert (lua_State *L, int index) { | 87 | LUA_API void lua_insert (lua_State *L, int index) { |
89 | StkId p = luaA_index(L, index); | 88 | StkId p = luaA_index(L, index); |
90 | StkId q; | 89 | StkId q; |
91 | for (q = L->top; q>p; q--) | 90 | for (q = L->top; q>p; q--) setobj(q, q-1); |
92 | *q = *(q-1); | 91 | setobj(p, L->top); |
93 | *p = *L->top; | ||
94 | } | 92 | } |
95 | 93 | ||
96 | 94 | ||
97 | LUA_API void lua_pushvalue (lua_State *L, int index) { | 95 | LUA_API void lua_pushvalue (lua_State *L, int index) { |
98 | *L->top = *luaA_index(L, index); | 96 | setobj(L->top, luaA_index(L, index)); |
99 | api_incr_top(L); | 97 | api_incr_top(L); |
100 | } | 98 | } |
101 | 99 | ||
@@ -200,21 +198,19 @@ LUA_API const void *lua_topointer (lua_State *L, int index) { | |||
200 | 198 | ||
201 | 199 | ||
202 | LUA_API void lua_pushnil (lua_State *L) { | 200 | LUA_API void lua_pushnil (lua_State *L) { |
203 | ttype(L->top) = LUA_TNIL; | 201 | setnilvalue(L->top); |
204 | api_incr_top(L); | 202 | api_incr_top(L); |
205 | } | 203 | } |
206 | 204 | ||
207 | 205 | ||
208 | LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { | 206 | LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { |
209 | nvalue(L->top) = n; | 207 | setnvalue(L->top, n); |
210 | ttype(L->top) = LUA_TNUMBER; | ||
211 | api_incr_top(L); | 208 | api_incr_top(L); |
212 | } | 209 | } |
213 | 210 | ||
214 | 211 | ||
215 | LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { | 212 | LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { |
216 | tsvalue(L->top) = luaS_newlstr(L, s, len); | 213 | setsvalue(L->top, luaS_newlstr(L, s, len)); |
217 | ttype(L->top) = LUA_TSTRING; | ||
218 | api_incr_top(L); | 214 | api_incr_top(L); |
219 | } | 215 | } |
220 | 216 | ||
@@ -236,8 +232,7 @@ LUA_API void lua_pushusertag (lua_State *L, void *u, int tag) { | |||
236 | /* ORDER LUA_T */ | 232 | /* ORDER LUA_T */ |
237 | if (!(tag == LUA_ANYTAG || tag == LUA_TUSERDATA || validtag(tag))) | 233 | if (!(tag == LUA_ANYTAG || tag == LUA_TUSERDATA || validtag(tag))) |
238 | luaO_verror(L, "invalid tag for a userdata (%d)", tag); | 234 | luaO_verror(L, "invalid tag for a userdata (%d)", tag); |
239 | tsvalue(L->top) = luaS_createudata(L, u, tag); | 235 | setuvalue(L->top, luaS_createudata(L, u, tag)); |
240 | ttype(L->top) = LUA_TUSERDATA; | ||
241 | api_incr_top(L); | 236 | api_incr_top(L); |
242 | } | 237 | } |
243 | 238 | ||
@@ -250,7 +245,7 @@ LUA_API void lua_pushusertag (lua_State *L, void *u, int tag) { | |||
250 | 245 | ||
251 | LUA_API void lua_getglobal (lua_State *L, const char *name) { | 246 | LUA_API void lua_getglobal (lua_State *L, const char *name) { |
252 | StkId top = L->top; | 247 | StkId top = L->top; |
253 | *top = *luaV_getglobal(L, luaS_new(L, name)); | 248 | setobj(top, luaV_getglobal(L, luaS_new(L, name))); |
254 | L->top = top; | 249 | L->top = top; |
255 | api_incr_top(L); | 250 | api_incr_top(L); |
256 | } | 251 | } |
@@ -259,7 +254,7 @@ LUA_API void lua_getglobal (lua_State *L, const char *name) { | |||
259 | LUA_API void lua_gettable (lua_State *L, int index) { | 254 | LUA_API void lua_gettable (lua_State *L, int index) { |
260 | StkId t = Index(L, index); | 255 | StkId t = Index(L, index); |
261 | StkId top = L->top; | 256 | StkId top = L->top; |
262 | *(top-1) = *luaV_gettable(L, t); | 257 | setobj(top-1, luaV_gettable(L, t)); |
263 | L->top = top; /* tag method may change top */ | 258 | L->top = top; /* tag method may change top */ |
264 | } | 259 | } |
265 | 260 | ||
@@ -267,31 +262,32 @@ LUA_API void lua_gettable (lua_State *L, int index) { | |||
267 | LUA_API void lua_rawget (lua_State *L, int index) { | 262 | LUA_API void lua_rawget (lua_State *L, int index) { |
268 | StkId t = Index(L, index); | 263 | StkId t = Index(L, index); |
269 | LUA_ASSERT(ttype(t) == LUA_TTABLE, "table expected"); | 264 | LUA_ASSERT(ttype(t) == LUA_TTABLE, "table expected"); |
270 | *(L->top - 1) = *luaH_get(hvalue(t), L->top - 1); | 265 | setobj(L->top - 1, luaH_get(hvalue(t), L->top - 1)); |
271 | } | 266 | } |
272 | 267 | ||
273 | 268 | ||
274 | LUA_API void lua_rawgeti (lua_State *L, int index, int n) { | 269 | LUA_API void lua_rawgeti (lua_State *L, int index, int n) { |
275 | StkId o = Index(L, index); | 270 | StkId o = Index(L, index); |
276 | LUA_ASSERT(ttype(o) == LUA_TTABLE, "table expected"); | 271 | LUA_ASSERT(ttype(o) == LUA_TTABLE, "table expected"); |
277 | *L->top = *luaH_getnum(hvalue(o), n); | 272 | setobj(L->top, luaH_getnum(hvalue(o), n)); |
278 | api_incr_top(L); | 273 | api_incr_top(L); |
279 | } | 274 | } |
280 | 275 | ||
281 | 276 | ||
282 | LUA_API void lua_getglobals (lua_State *L) { | 277 | LUA_API void lua_getglobals (lua_State *L) { |
283 | hvalue(L->top) = L->gt; | 278 | sethvalue(L->top, L->gt); |
284 | ttype(L->top) = LUA_TTABLE; | ||
285 | api_incr_top(L); | 279 | api_incr_top(L); |
286 | } | 280 | } |
287 | 281 | ||
288 | 282 | ||
289 | LUA_API int lua_getref (lua_State *L, int ref) { | 283 | LUA_API int lua_getref (lua_State *L, int ref) { |
290 | if (ref == LUA_REFNIL) | 284 | if (ref == LUA_REFNIL) { |
291 | ttype(L->top) = LUA_TNIL; | 285 | setnilvalue(L->top); |
286 | } | ||
292 | else if (0 <= ref && ref < L->nref && | 287 | else if (0 <= ref && ref < L->nref && |
293 | (L->refArray[ref].st == LOCK || L->refArray[ref].st == HOLD)) | 288 | (L->refArray[ref].st == LOCK || L->refArray[ref].st == HOLD)) { |
294 | *L->top = L->refArray[ref].o; | 289 | setobj(L->top, &L->refArray[ref].o); |
290 | } | ||
295 | else | 291 | else |
296 | return 0; | 292 | return 0; |
297 | api_incr_top(L); | 293 | api_incr_top(L); |
@@ -300,8 +296,7 @@ LUA_API int lua_getref (lua_State *L, int ref) { | |||
300 | 296 | ||
301 | 297 | ||
302 | LUA_API void lua_newtable (lua_State *L) { | 298 | LUA_API void lua_newtable (lua_State *L) { |
303 | hvalue(L->top) = luaH_new(L, 0); | 299 | sethvalue(L->top, luaH_new(L, 0)); |
304 | ttype(L->top) = LUA_TTABLE; | ||
305 | api_incr_top(L); | 300 | api_incr_top(L); |
306 | } | 301 | } |
307 | 302 | ||
@@ -330,7 +325,7 @@ LUA_API void lua_settable (lua_State *L, int index) { | |||
330 | LUA_API void lua_rawset (lua_State *L, int index) { | 325 | LUA_API void lua_rawset (lua_State *L, int index) { |
331 | StkId t = Index(L, index); | 326 | StkId t = Index(L, index); |
332 | LUA_ASSERT(ttype(t) == LUA_TTABLE, "table expected"); | 327 | LUA_ASSERT(ttype(t) == LUA_TTABLE, "table expected"); |
333 | *luaH_set(L, hvalue(t), L->top-2) = *(L->top-1); | 328 | setobj(luaH_set(L, hvalue(t), L->top-2), (L->top-1)); |
334 | L->top -= 2; | 329 | L->top -= 2; |
335 | } | 330 | } |
336 | 331 | ||
@@ -338,7 +333,7 @@ LUA_API void lua_rawset (lua_State *L, int index) { | |||
338 | LUA_API void lua_rawseti (lua_State *L, int index, int n) { | 333 | LUA_API void lua_rawseti (lua_State *L, int index, int n) { |
339 | StkId o = Index(L, index); | 334 | StkId o = Index(L, index); |
340 | LUA_ASSERT(ttype(o) == LUA_TTABLE, "table expected"); | 335 | LUA_ASSERT(ttype(o) == LUA_TTABLE, "table expected"); |
341 | *luaH_setnum(L, hvalue(o), n) = *(L->top-1); | 336 | setobj(luaH_setnum(L, hvalue(o), n), (L->top-1)); |
342 | L->top--; | 337 | L->top--; |
343 | } | 338 | } |
344 | 339 | ||
@@ -364,7 +359,7 @@ LUA_API int lua_ref (lua_State *L, int lock) { | |||
364 | MAX_INT, "reference table overflow"); | 359 | MAX_INT, "reference table overflow"); |
365 | ref = L->nref++; | 360 | ref = L->nref++; |
366 | } | 361 | } |
367 | L->refArray[ref].o = *(L->top-1); | 362 | setobj(&L->refArray[ref].o, L->top-1); |
368 | L->refArray[ref].st = lock ? LOCK : HOLD; | 363 | L->refArray[ref].st = lock ? LOCK : HOLD; |
369 | } | 364 | } |
370 | L->top--; | 365 | L->top--; |
@@ -442,8 +437,8 @@ LUA_API int lua_next (lua_State *L, int index) { | |||
442 | LUA_ASSERT(ttype(t) == LUA_TTABLE, "table expected"); | 437 | LUA_ASSERT(ttype(t) == LUA_TTABLE, "table expected"); |
443 | n = luaH_next(L, hvalue(t), luaA_index(L, -1)); | 438 | n = luaH_next(L, hvalue(t), luaA_index(L, -1)); |
444 | if (n) { | 439 | if (n) { |
445 | *(L->top-1) = *key(n); | 440 | setobj(L->top-1, key(n)); |
446 | *L->top = *val(n); | 441 | setobj(L->top, val(n)); |
447 | api_incr_top(L); | 442 | api_incr_top(L); |
448 | return 1; | 443 | return 1; |
449 | } | 444 | } |
@@ -485,8 +480,7 @@ LUA_API void lua_concat (lua_State *L, int n) { | |||
485 | 480 | ||
486 | LUA_API void *lua_newuserdata (lua_State *L, size_t size) { | 481 | LUA_API void *lua_newuserdata (lua_State *L, size_t size) { |
487 | TString *ts = luaS_newudata(L, size, NULL); | 482 | TString *ts = luaS_newudata(L, size, NULL); |
488 | tsvalue(L->top) = ts; | 483 | setuvalue(L->top, ts); |
489 | ttype(L->top) = LUA_TUSERDATA; | ||
490 | api_incr_top(L); | 484 | api_incr_top(L); |
491 | return ts->u.d.value; | 485 | return ts->u.d.value; |
492 | } | 486 | } |