diff options
Diffstat (limited to 'ltablib.c')
-rw-r--r-- | ltablib.c | 34 |
1 files changed, 17 insertions, 17 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltablib.c,v 1.14 2002/10/23 19:08:23 roberto Exp roberto $ | 2 | ** $Id: ltablib.c,v 1.15 2002/11/14 11:51:50 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 | */ |
@@ -40,7 +40,7 @@ static void aux_setn (lua_State *L, int t, int n) { | |||
40 | 40 | ||
41 | static int aux_getn (lua_State *L, int t) { | 41 | static int aux_getn (lua_State *L, int t) { |
42 | int n; | 42 | int n; |
43 | luaL_check_type(L, t, LUA_TTABLE); | 43 | luaL_checktype(L, t, LUA_TTABLE); |
44 | lua_pushliteral(L, "n"); /* try t.n */ | 44 | lua_pushliteral(L, "n"); /* try t.n */ |
45 | lua_rawget(L, t); | 45 | lua_rawget(L, t); |
46 | if ((n = checkint(L)) >= 0) return n; | 46 | if ((n = checkint(L)) >= 0) return n; |
@@ -64,7 +64,7 @@ static int aux_getn (lua_State *L, int t) { | |||
64 | static int luaB_foreachi (lua_State *L) { | 64 | static int luaB_foreachi (lua_State *L) { |
65 | int i; | 65 | int i; |
66 | int n = aux_getn(L, 1); | 66 | int n = aux_getn(L, 1); |
67 | luaL_check_type(L, 2, LUA_TFUNCTION); | 67 | luaL_checktype(L, 2, LUA_TFUNCTION); |
68 | for (i=1; i<=n; i++) { | 68 | for (i=1; i<=n; i++) { |
69 | lua_pushvalue(L, 2); /* function */ | 69 | lua_pushvalue(L, 2); /* function */ |
70 | lua_pushnumber(L, i); /* 1st argument */ | 70 | lua_pushnumber(L, i); /* 1st argument */ |
@@ -79,8 +79,8 @@ static int luaB_foreachi (lua_State *L) { | |||
79 | 79 | ||
80 | 80 | ||
81 | static int luaB_foreach (lua_State *L) { | 81 | static int luaB_foreach (lua_State *L) { |
82 | luaL_check_type(L, 1, LUA_TTABLE); | 82 | luaL_checktype(L, 1, LUA_TTABLE); |
83 | luaL_check_type(L, 2, LUA_TFUNCTION); | 83 | luaL_checktype(L, 2, LUA_TFUNCTION); |
84 | lua_pushnil(L); /* first key */ | 84 | lua_pushnil(L); /* first key */ |
85 | for (;;) { | 85 | for (;;) { |
86 | if (lua_next(L, 1) == 0) | 86 | if (lua_next(L, 1) == 0) |
@@ -103,8 +103,8 @@ static int luaB_getn (lua_State *L) { | |||
103 | 103 | ||
104 | 104 | ||
105 | static int luaB_setn (lua_State *L) { | 105 | static int luaB_setn (lua_State *L) { |
106 | luaL_check_type(L, 1, LUA_TTABLE); | 106 | luaL_checktype(L, 1, LUA_TTABLE); |
107 | aux_setn(L, 1, luaL_check_int(L, 2)); | 107 | aux_setn(L, 1, luaL_checkint(L, 2)); |
108 | return 0; | 108 | return 0; |
109 | } | 109 | } |
110 | 110 | ||
@@ -116,7 +116,7 @@ static int luaB_tinsert (lua_State *L) { | |||
116 | if (v == 2) /* called with only 2 arguments */ | 116 | if (v == 2) /* called with only 2 arguments */ |
117 | pos = n; /* insert new element at the end */ | 117 | pos = n; /* insert new element at the end */ |
118 | else { | 118 | else { |
119 | pos = luaL_check_int(L, 2); /* 2nd argument is the position */ | 119 | pos = luaL_checkint(L, 2); /* 2nd argument is the position */ |
120 | if (pos > n) n = pos; /* `grow' array if necessary */ | 120 | if (pos > n) n = pos; /* `grow' array if necessary */ |
121 | v = 3; /* function may be called with more than 3 args */ | 121 | v = 3; /* function may be called with more than 3 args */ |
122 | } | 122 | } |
@@ -133,7 +133,7 @@ static int luaB_tinsert (lua_State *L) { | |||
133 | 133 | ||
134 | static int luaB_tremove (lua_State *L) { | 134 | static int luaB_tremove (lua_State *L) { |
135 | int n = aux_getn(L, 1); | 135 | int n = aux_getn(L, 1); |
136 | int pos = luaL_opt_int(L, 2, n); | 136 | int pos = luaL_optint(L, 2, n); |
137 | if (n <= 0) return 0; /* table is `empty' */ | 137 | if (n <= 0) return 0; /* table is `empty' */ |
138 | aux_setn(L, 1, n-1); /* t.n = n-1 */ | 138 | aux_setn(L, 1, n-1); /* t.n = n-1 */ |
139 | lua_rawgeti(L, 1, pos); /* result = t[pos] */ | 139 | lua_rawgeti(L, 1, pos); /* result = t[pos] */ |
@@ -150,15 +150,15 @@ static int luaB_tremove (lua_State *L) { | |||
150 | static int str_concat (lua_State *L) { | 150 | static int str_concat (lua_State *L) { |
151 | luaL_Buffer b; | 151 | luaL_Buffer b; |
152 | size_t lsep; | 152 | size_t lsep; |
153 | const char *sep = luaL_opt_lstr(L, 2, "", &lsep); | 153 | const char *sep = luaL_optlstring(L, 2, "", &lsep); |
154 | int i = luaL_opt_int(L, 3, 1); | 154 | int i = luaL_optint(L, 3, 1); |
155 | int n = luaL_opt_int(L, 4, 0); | 155 | int n = luaL_optint(L, 4, 0); |
156 | luaL_check_type(L, 1, LUA_TTABLE); | 156 | luaL_checktype(L, 1, LUA_TTABLE); |
157 | if (n == 0) n = aux_getn(L, 1); | 157 | if (n == 0) n = aux_getn(L, 1); |
158 | luaL_buffinit(L, &b); | 158 | luaL_buffinit(L, &b); |
159 | for (; i <= n; i++) { | 159 | for (; i <= n; i++) { |
160 | lua_rawgeti(L, 1, i); | 160 | lua_rawgeti(L, 1, i); |
161 | luaL_arg_check(L, lua_isstring(L, -1), 1, "table contains non-strings"); | 161 | luaL_argcheck(L, lua_isstring(L, -1), 1, "table contains non-strings"); |
162 | luaL_addvalue(&b); | 162 | luaL_addvalue(&b); |
163 | if (i != n) | 163 | if (i != n) |
164 | luaL_addlstring(&b, sep, lsep); | 164 | luaL_addlstring(&b, sep, lsep); |
@@ -262,9 +262,9 @@ static void auxsort (lua_State *L, int l, int u) { | |||
262 | 262 | ||
263 | static int luaB_sort (lua_State *L) { | 263 | static int luaB_sort (lua_State *L) { |
264 | int n = aux_getn(L, 1); | 264 | int n = aux_getn(L, 1); |
265 | luaL_check_stack(L, 40, ""); /* assume array is smaller than 2^40 */ | 265 | luaL_checkstack(L, 40, ""); /* assume array is smaller than 2^40 */ |
266 | if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */ | 266 | if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */ |
267 | luaL_check_type(L, 2, LUA_TFUNCTION); | 267 | luaL_checktype(L, 2, LUA_TFUNCTION); |
268 | lua_settop(L, 2); /* make sure there is two arguments */ | 268 | lua_settop(L, 2); /* make sure there is two arguments */ |
269 | auxsort(L, 1, n); | 269 | auxsort(L, 1, n); |
270 | return 0; | 270 | return 0; |
@@ -293,7 +293,7 @@ LUALIB_API int lua_tablibopen (lua_State *L) { | |||
293 | lua_pushliteral(L, "__mode"); | 293 | lua_pushliteral(L, "__mode"); |
294 | lua_pushliteral(L, "k"); | 294 | lua_pushliteral(L, "k"); |
295 | lua_rawset(L, -3); /* metatable(N).__mode = "k" */ | 295 | lua_rawset(L, -3); /* metatable(N).__mode = "k" */ |
296 | luaL_opennamedlib(L, LUA_TABLIBNAME, tab_funcs, 1); | 296 | luaL_openlib(L, LUA_TABLIBNAME, tab_funcs, 1); |
297 | return 0; | 297 | return 0; |
298 | } | 298 | } |
299 | 299 | ||