diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-12-07 16:31:16 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-12-07 16:31:16 -0200 |
| commit | 70751dd27c4225955fe018d6829ea45e3e66a51c (patch) | |
| tree | f190cfa201bcb793247463e948e8ed0de8b9994b /ltablib.c | |
| parent | 39a8082f50c7321d75425f08a551a1d331dcea2d (diff) | |
| download | lua-70751dd27c4225955fe018d6829ea45e3e66a51c.tar.gz lua-70751dd27c4225955fe018d6829ea45e3e66a51c.tar.bz2 lua-70751dd27c4225955fe018d6829ea45e3e66a51c.zip | |
details
Diffstat (limited to 'ltablib.c')
| -rw-r--r-- | ltablib.c | 30 |
1 files changed, 15 insertions, 15 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltablib.c,v 1.25 2004/05/10 18:06:14 roberto Exp roberto $ | 2 | ** $Id: ltablib.c,v 1.26 2004/06/15 13:37:21 roberto Exp roberto $ |
| 3 | ** Library for Table Manipulation | 3 | ** Library for Table Manipulation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -19,7 +19,7 @@ | |||
| 19 | #define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n)) | 19 | #define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n)) |
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | static int luaB_foreachi (lua_State *L) { | 22 | static int foreachi (lua_State *L) { |
| 23 | int i; | 23 | int i; |
| 24 | int n = aux_getn(L, 1); | 24 | int n = aux_getn(L, 1); |
| 25 | luaL_checktype(L, 2, LUA_TFUNCTION); | 25 | luaL_checktype(L, 2, LUA_TFUNCTION); |
| @@ -36,7 +36,7 @@ static int luaB_foreachi (lua_State *L) { | |||
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | 38 | ||
| 39 | static int luaB_foreach (lua_State *L) { | 39 | static int foreach (lua_State *L) { |
| 40 | luaL_checktype(L, 1, LUA_TTABLE); | 40 | luaL_checktype(L, 1, LUA_TTABLE); |
| 41 | luaL_checktype(L, 2, LUA_TFUNCTION); | 41 | luaL_checktype(L, 2, LUA_TFUNCTION); |
| 42 | lua_pushnil(L); /* first key */ | 42 | lua_pushnil(L); /* first key */ |
| @@ -54,13 +54,13 @@ static int luaB_foreach (lua_State *L) { | |||
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | 56 | ||
| 57 | static int luaB_getn (lua_State *L) { | 57 | static int getn (lua_State *L) { |
| 58 | lua_pushinteger(L, aux_getn(L, 1)); | 58 | lua_pushinteger(L, aux_getn(L, 1)); |
| 59 | return 1; | 59 | return 1; |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | 62 | ||
| 63 | static int luaB_setn (lua_State *L) { | 63 | static int setn (lua_State *L) { |
| 64 | luaL_checktype(L, 1, LUA_TTABLE); | 64 | luaL_checktype(L, 1, LUA_TTABLE); |
| 65 | luaL_setn(L, 1, luaL_checkint(L, 2)); | 65 | luaL_setn(L, 1, luaL_checkint(L, 2)); |
| 66 | lua_pushvalue(L, 1); | 66 | lua_pushvalue(L, 1); |
| @@ -68,7 +68,7 @@ static int luaB_setn (lua_State *L) { | |||
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | 70 | ||
| 71 | static int luaB_tinsert (lua_State *L) { | 71 | static int tinsert (lua_State *L) { |
| 72 | int v = lua_gettop(L); /* number of arguments */ | 72 | int v = lua_gettop(L); /* number of arguments */ |
| 73 | int e = aux_getn(L, 1) + LUA_FIRSTINDEX; /* first empty element */ | 73 | int e = aux_getn(L, 1) + LUA_FIRSTINDEX; /* first empty element */ |
| 74 | int pos; /* where to insert new element */ | 74 | int pos; /* where to insert new element */ |
| @@ -90,7 +90,7 @@ static int luaB_tinsert (lua_State *L) { | |||
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | 92 | ||
| 93 | static int luaB_tremove (lua_State *L) { | 93 | static int tremove (lua_State *L) { |
| 94 | int e = aux_getn(L, 1) + LUA_FIRSTINDEX - 1; | 94 | int e = aux_getn(L, 1) + LUA_FIRSTINDEX - 1; |
| 95 | int pos = luaL_optint(L, 2, e); | 95 | int pos = luaL_optint(L, 2, e); |
| 96 | if (e < LUA_FIRSTINDEX) return 0; /* table is `empty' */ | 96 | if (e < LUA_FIRSTINDEX) return 0; /* table is `empty' */ |
| @@ -220,7 +220,7 @@ static void auxsort (lua_State *L, int l, int u) { | |||
| 220 | } /* repeat the routine for the larger one */ | 220 | } /* repeat the routine for the larger one */ |
| 221 | } | 221 | } |
| 222 | 222 | ||
| 223 | static int luaB_sort (lua_State *L) { | 223 | static int sort (lua_State *L) { |
| 224 | int n = aux_getn(L, 1); | 224 | int n = aux_getn(L, 1); |
| 225 | luaL_checkstack(L, 40, ""); /* assume array is smaller than 2^40 */ | 225 | luaL_checkstack(L, 40, ""); /* assume array is smaller than 2^40 */ |
| 226 | if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */ | 226 | if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */ |
| @@ -235,13 +235,13 @@ static int luaB_sort (lua_State *L) { | |||
| 235 | 235 | ||
| 236 | static const luaL_reg tab_funcs[] = { | 236 | static const luaL_reg tab_funcs[] = { |
| 237 | {"concat", str_concat}, | 237 | {"concat", str_concat}, |
| 238 | {"foreach", luaB_foreach}, | 238 | {"foreach", foreach}, |
| 239 | {"foreachi", luaB_foreachi}, | 239 | {"foreachi", foreachi}, |
| 240 | {"getn", luaB_getn}, | 240 | {"getn", getn}, |
| 241 | {"setn", luaB_setn}, | 241 | {"setn", setn}, |
| 242 | {"sort", luaB_sort}, | 242 | {"sort", sort}, |
| 243 | {"insert", luaB_tinsert}, | 243 | {"insert", tinsert}, |
| 244 | {"remove", luaB_tremove}, | 244 | {"remove", tremove}, |
| 245 | {NULL, NULL} | 245 | {NULL, NULL} |
| 246 | }; | 246 | }; |
| 247 | 247 | ||
