diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-10-10 10:29:28 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-10-10 10:29:28 -0300 |
commit | 10de467c794a536902755c236933623767bb452e (patch) | |
tree | bc0577eb71a887170abd07d8b7f52eade4518175 | |
parent | 533737f26e3f8036d7978e09427ea5ff75aec9df (diff) | |
download | lua-10de467c794a536902755c236933623767bb452e.tar.gz lua-10de467c794a536902755c236933623767bb452e.tar.bz2 lua-10de467c794a536902755c236933623767bb452e.zip |
new function `lua_createtable'
-rw-r--r-- | lapi.c | 6 | ||||
-rw-r--r-- | liolib.c | 4 | ||||
-rw-r--r-- | ltests.c | 9 | ||||
-rw-r--r-- | lua.h | 6 |
4 files changed, 13 insertions, 12 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.245 2003/10/07 20:13:41 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.246 2003/10/10 12:57:55 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 | */ |
@@ -532,10 +532,10 @@ LUA_API void lua_rawgeti (lua_State *L, int idx, int n) { | |||
532 | } | 532 | } |
533 | 533 | ||
534 | 534 | ||
535 | LUA_API void lua_newtable (lua_State *L) { | 535 | LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { |
536 | lua_lock(L); | 536 | lua_lock(L); |
537 | luaC_checkGC(L); | 537 | luaC_checkGC(L); |
538 | sethvalue(L->top, luaH_new(L, 0, 0)); | 538 | sethvalue(L->top, luaH_new(L, narray, luaO_log2(nrec) + 1)); |
539 | api_incr_top(L); | 539 | api_incr_top(L); |
540 | lua_unlock(L); | 540 | lua_unlock(L); |
541 | } | 541 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 2.47 2003/10/07 20:13:41 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 2.48 2003/10/10 12:57:55 roberto Exp roberto $ |
3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -628,7 +628,7 @@ static int io_date (lua_State *L) { | |||
628 | if (stm == NULL) /* invalid date? */ | 628 | if (stm == NULL) /* invalid date? */ |
629 | lua_pushnil(L); | 629 | lua_pushnil(L); |
630 | else if (strcmp(s, "*t") == 0) { | 630 | else if (strcmp(s, "*t") == 0) { |
631 | lua_newtable(L); | 631 | lua_createtable(L, 0, 9); /* 9 = number of fields */ |
632 | setfield(L, "sec", stm->tm_sec); | 632 | setfield(L, "sec", stm->tm_sec); |
633 | setfield(L, "min", stm->tm_min); | 633 | setfield(L, "min", stm->tm_min); |
634 | setfield(L, "hour", stm->tm_hour); | 634 | setfield(L, "hour", stm->tm_hour); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 1.164 2003/10/02 20:31:17 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.165 2003/10/07 20:13:41 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -207,11 +207,10 @@ static int listk (lua_State *L) { | |||
207 | luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), | 207 | luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), |
208 | 1, "Lua function expected"); | 208 | 1, "Lua function expected"); |
209 | p = clvalue(func_at(L, 1))->l.p; | 209 | p = clvalue(func_at(L, 1))->l.p; |
210 | lua_newtable(L); | 210 | lua_createtable(L, p->sizek, 0); |
211 | for (i=0; i<p->sizek; i++) { | 211 | for (i=0; i<p->sizek; i++) { |
212 | lua_pushinteger(L, i+1); | ||
213 | luaA_pushobject(L, p->k+i); | 212 | luaA_pushobject(L, p->k+i); |
214 | lua_settable(L, -3); | 213 | lua_rawseti(L, -2, i+1); |
215 | } | 214 | } |
216 | return 1; | 215 | return 1; |
217 | } | 216 | } |
@@ -236,7 +235,7 @@ static int listlocals (lua_State *L) { | |||
236 | 235 | ||
237 | 236 | ||
238 | static int get_limits (lua_State *L) { | 237 | static int get_limits (lua_State *L) { |
239 | lua_newtable(L); | 238 | lua_createtable(L, 0, 5); |
240 | setnameval(L, "BITS_INT", BITS_INT); | 239 | setnameval(L, "BITS_INT", BITS_INT); |
241 | setnameval(L, "LFPF", LFIELDS_PER_FLUSH); | 240 | setnameval(L, "LFPF", LFIELDS_PER_FLUSH); |
242 | setnameval(L, "MAXVARS", MAXVARS); | 241 | setnameval(L, "MAXVARS", MAXVARS); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.h,v 1.180 2003/10/07 20:13:41 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.181 2003/10/10 12:57:55 roberto Exp roberto $ |
3 | ** Lua - An Extensible Extension Language | 3 | ** Lua - An Extensible Extension Language |
4 | ** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil | 4 | ** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil |
5 | ** http://www.lua.org mailto:info@lua.org | 5 | ** http://www.lua.org mailto:info@lua.org |
@@ -185,7 +185,7 @@ LUA_API void lua_gettable (lua_State *L, int idx); | |||
185 | LUA_API void lua_getfield (lua_State *L, int idx, const char *k); | 185 | LUA_API void lua_getfield (lua_State *L, int idx, const char *k); |
186 | LUA_API void lua_rawget (lua_State *L, int idx); | 186 | LUA_API void lua_rawget (lua_State *L, int idx); |
187 | LUA_API void lua_rawgeti (lua_State *L, int idx, int n); | 187 | LUA_API void lua_rawgeti (lua_State *L, int idx, int n); |
188 | LUA_API void lua_newtable (lua_State *L); | 188 | LUA_API void lua_createtable (lua_State *L, int narr, int nrec); |
189 | LUA_API void *lua_newuserdata (lua_State *L, size_t sz); | 189 | LUA_API void *lua_newuserdata (lua_State *L, size_t sz); |
190 | LUA_API int lua_getmetatable (lua_State *L, int objindex); | 190 | LUA_API int lua_getmetatable (lua_State *L, int objindex); |
191 | LUA_API void lua_getfenv (lua_State *L, int idx); | 191 | LUA_API void lua_getfenv (lua_State *L, int idx); |
@@ -254,6 +254,8 @@ LUA_API void lua_concat (lua_State *L, int n); | |||
254 | 254 | ||
255 | #define lua_pop(L,n) lua_settop(L, -(n)-1) | 255 | #define lua_pop(L,n) lua_settop(L, -(n)-1) |
256 | 256 | ||
257 | #define lua_newtable(L) lua_createtable(L, 0, 0) | ||
258 | |||
257 | #define lua_register(L,n,f) \ | 259 | #define lua_register(L,n,f) \ |
258 | (lua_pushstring(L, n), \ | 260 | (lua_pushstring(L, n), \ |
259 | lua_pushcfunction(L, f), \ | 261 | lua_pushcfunction(L, f), \ |