diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-08-31 17:23:40 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-08-31 17:23:40 -0300 |
commit | f0b3cd1d6f35ba34091450d5e3057269114a17b6 (patch) | |
tree | ceffcf31f1823709b7ab4e63801e5e483abf8490 /lapi.c | |
parent | fb5e6d5ac498649b8e1b6bf068d18078ef70d523 (diff) | |
download | lua-f0b3cd1d6f35ba34091450d5e3057269114a17b6.tar.gz lua-f0b3cd1d6f35ba34091450d5e3057269114a17b6.tar.bz2 lua-f0b3cd1d6f35ba34091450d5e3057269114a17b6.zip |
new API functions `pop', `insert', and `move'
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 38 |
1 files changed, 25 insertions, 13 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.90 2000/08/29 20:43:28 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.91 2000/08/31 14:08:27 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 | */ |
@@ -65,7 +65,25 @@ void lua_settop (lua_State *L, int index) { | |||
65 | if (index >= 0) | 65 | if (index >= 0) |
66 | luaD_adjusttop(L, L->Cbase, index); | 66 | luaD_adjusttop(L, L->Cbase, index); |
67 | else | 67 | else |
68 | L->top += index; /* index is negative */ | 68 | L->top = L->top+index+1; /* index is negative */ |
69 | } | ||
70 | |||
71 | |||
72 | void lua_move (lua_State *L, int index) { | ||
73 | TObject *p = Index(L, index); | ||
74 | TObject temp = *p; | ||
75 | while (++p < L->top) *(p-1) = *p; | ||
76 | *(L->top-1) = temp; | ||
77 | } | ||
78 | |||
79 | |||
80 | void lua_insert (lua_State *L, int index) { | ||
81 | TObject temp = *(L->top-1); | ||
82 | TObject *p = Index(L, index); | ||
83 | TObject *q; | ||
84 | for (q = L->top-1; q>p; q--) | ||
85 | *q = *(q-1); | ||
86 | *p = temp; | ||
69 | } | 87 | } |
70 | 88 | ||
71 | 89 | ||
@@ -218,8 +236,7 @@ void lua_gettable (lua_State *L) { | |||
218 | 236 | ||
219 | 237 | ||
220 | void lua_rawget (lua_State *L) { | 238 | void lua_rawget (lua_State *L) { |
221 | if (ttype(L->top - 2) != TAG_TABLE) | 239 | LUA_ASSERT(ttype(L->top-2) == TAG_TABLE, "not a table"); |
222 | lua_error(L, "indexed expression not a table"); | ||
223 | *(L->top - 2) = *luaH_get(L, hvalue(L->top - 2), L->top - 1); | 240 | *(L->top - 2) = *luaH_get(L, hvalue(L->top - 2), L->top - 1); |
224 | L->top--; | 241 | L->top--; |
225 | } | 242 | } |
@@ -278,8 +295,7 @@ void lua_settable (lua_State *L) { | |||
278 | 295 | ||
279 | 296 | ||
280 | void lua_rawset (lua_State *L) { | 297 | void lua_rawset (lua_State *L) { |
281 | if (ttype(L->top-3) != TAG_TABLE) | 298 | LUA_ASSERT(ttype(L->top-3) == TAG_TABLE, "not a table"); |
282 | lua_error(L, "indexed expression not a table"); | ||
283 | *luaH_set(L, hvalue(L->top-3), L->top-2) = *(L->top-1); | 299 | *luaH_set(L, hvalue(L->top-3), L->top-2) = *(L->top-1); |
284 | L->top -= 3; | 300 | L->top -= 3; |
285 | } | 301 | } |
@@ -287,8 +303,7 @@ void lua_rawset (lua_State *L) { | |||
287 | 303 | ||
288 | void lua_setglobals (lua_State *L) { | 304 | void lua_setglobals (lua_State *L) { |
289 | TObject *newtable = --L->top; | 305 | TObject *newtable = --L->top; |
290 | if (ttype(newtable) != TAG_TABLE) | 306 | LUA_ASSERT(ttype(newtable) == TAG_TABLE, "not a table"); |
291 | lua_error(L, "Lua API error - invalid value for global table"); | ||
292 | L->gt = hvalue(newtable); | 307 | L->gt = hvalue(newtable); |
293 | } | 308 | } |
294 | 309 | ||
@@ -350,9 +365,7 @@ void lua_settag (lua_State *L, int tag) { | |||
350 | 365 | ||
351 | void lua_unref (lua_State *L, int ref) { | 366 | void lua_unref (lua_State *L, int ref) { |
352 | if (ref >= 0) { | 367 | if (ref >= 0) { |
353 | if (ref >= L->refSize || L->refArray[ref].st >= 0) | 368 | LUA_ASSERT(ref < L->refSize && L->refArray[ref].st < 0, "invalid ref"); |
354 | lua_error(L, "Lua API error - " | ||
355 | "invalid argument for function `lua_unref'"); | ||
356 | L->refArray[ref].st = L->refFree; | 369 | L->refArray[ref].st = L->refFree; |
357 | L->refFree = ref; | 370 | L->refFree = ref; |
358 | } | 371 | } |
@@ -362,8 +375,7 @@ void lua_unref (lua_State *L, int ref) { | |||
362 | int lua_next (lua_State *L) { | 375 | int lua_next (lua_State *L) { |
363 | const TObject *t = Index(L, -2); | 376 | const TObject *t = Index(L, -2); |
364 | Node *n; | 377 | Node *n; |
365 | if (ttype(t) != TAG_TABLE) | 378 | LUA_ASSERT(ttype(t) == TAG_TABLE, "object is not a table in `lua_next'"); |
366 | lua_error(L, "Lua API error - object is not a table in `lua_next'"); | ||
367 | n = luaH_next(L, hvalue(t), Index(L, -1)); | 379 | n = luaH_next(L, hvalue(t), Index(L, -1)); |
368 | if (n) { | 380 | if (n) { |
369 | *(L->top-1) = *key(n); | 381 | *(L->top-1) = *key(n); |