aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-10-10 10:29:28 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-10-10 10:29:28 -0300
commit10de467c794a536902755c236933623767bb452e (patch)
treebc0577eb71a887170abd07d8b7f52eade4518175
parent533737f26e3f8036d7978e09427ea5ff75aec9df (diff)
downloadlua-10de467c794a536902755c236933623767bb452e.tar.gz
lua-10de467c794a536902755c236933623767bb452e.tar.bz2
lua-10de467c794a536902755c236933623767bb452e.zip
new function `lua_createtable'
-rw-r--r--lapi.c6
-rw-r--r--liolib.c4
-rw-r--r--ltests.c9
-rw-r--r--lua.h6
4 files changed, 13 insertions, 12 deletions
diff --git a/lapi.c b/lapi.c
index 16686e7e..2e5366ba 100644
--- a/lapi.c
+++ b/lapi.c
@@ -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
535LUA_API void lua_newtable (lua_State *L) { 535LUA_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}
diff --git a/liolib.c b/liolib.c
index 3846360a..a2e22c4d 100644
--- a/liolib.c
+++ b/liolib.c
@@ -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);
diff --git a/ltests.c b/ltests.c
index 63e3cc5e..05d2ab16 100644
--- a/ltests.c
+++ b/ltests.c
@@ -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
238static int get_limits (lua_State *L) { 237static 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);
diff --git a/lua.h b/lua.h
index 4e4d5c45..04f83578 100644
--- a/lua.h
+++ b/lua.h
@@ -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);
185LUA_API void lua_getfield (lua_State *L, int idx, const char *k); 185LUA_API void lua_getfield (lua_State *L, int idx, const char *k);
186LUA_API void lua_rawget (lua_State *L, int idx); 186LUA_API void lua_rawget (lua_State *L, int idx);
187LUA_API void lua_rawgeti (lua_State *L, int idx, int n); 187LUA_API void lua_rawgeti (lua_State *L, int idx, int n);
188LUA_API void lua_newtable (lua_State *L); 188LUA_API void lua_createtable (lua_State *L, int narr, int nrec);
189LUA_API void *lua_newuserdata (lua_State *L, size_t sz); 189LUA_API void *lua_newuserdata (lua_State *L, size_t sz);
190LUA_API int lua_getmetatable (lua_State *L, int objindex); 190LUA_API int lua_getmetatable (lua_State *L, int objindex);
191LUA_API void lua_getfenv (lua_State *L, int idx); 191LUA_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), \