new function `lua_createtable'

This commit is contained in:
Roberto Ierusalimschy 2003-10-10 10:29:28 -03:00
parent 533737f26e
commit 10de467c79
4 changed files with 13 additions and 12 deletions

6
lapi.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lapi.c,v 1.245 2003/10/07 20:13:41 roberto Exp roberto $
** $Id: lapi.c,v 1.246 2003/10/10 12:57:55 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@ -532,10 +532,10 @@ LUA_API void lua_rawgeti (lua_State *L, int idx, int n) {
}
LUA_API void lua_newtable (lua_State *L) {
LUA_API void lua_createtable (lua_State *L, int narray, int nrec) {
lua_lock(L);
luaC_checkGC(L);
sethvalue(L->top, luaH_new(L, 0, 0));
sethvalue(L->top, luaH_new(L, narray, luaO_log2(nrec) + 1));
api_incr_top(L);
lua_unlock(L);
}

View File

@ -1,5 +1,5 @@
/*
** $Id: liolib.c,v 2.47 2003/10/07 20:13:41 roberto Exp roberto $
** $Id: liolib.c,v 2.48 2003/10/10 12:57:55 roberto Exp roberto $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
@ -628,7 +628,7 @@ static int io_date (lua_State *L) {
if (stm == NULL) /* invalid date? */
lua_pushnil(L);
else if (strcmp(s, "*t") == 0) {
lua_newtable(L);
lua_createtable(L, 0, 9); /* 9 = number of fields */
setfield(L, "sec", stm->tm_sec);
setfield(L, "min", stm->tm_min);
setfield(L, "hour", stm->tm_hour);

View File

@ -1,5 +1,5 @@
/*
** $Id: ltests.c,v 1.164 2003/10/02 20:31:17 roberto Exp roberto $
** $Id: ltests.c,v 1.165 2003/10/07 20:13:41 roberto Exp roberto $
** Internal Module for Debugging of the Lua Implementation
** See Copyright Notice in lua.h
*/
@ -207,11 +207,10 @@ static int listk (lua_State *L) {
luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1),
1, "Lua function expected");
p = clvalue(func_at(L, 1))->l.p;
lua_newtable(L);
lua_createtable(L, p->sizek, 0);
for (i=0; i<p->sizek; i++) {
lua_pushinteger(L, i+1);
luaA_pushobject(L, p->k+i);
lua_settable(L, -3);
lua_rawseti(L, -2, i+1);
}
return 1;
}
@ -236,7 +235,7 @@ static int listlocals (lua_State *L) {
static int get_limits (lua_State *L) {
lua_newtable(L);
lua_createtable(L, 0, 5);
setnameval(L, "BITS_INT", BITS_INT);
setnameval(L, "LFPF", LFIELDS_PER_FLUSH);
setnameval(L, "MAXVARS", MAXVARS);

6
lua.h
View File

@ -1,5 +1,5 @@
/*
** $Id: lua.h,v 1.180 2003/10/07 20:13:41 roberto Exp roberto $
** $Id: lua.h,v 1.181 2003/10/10 12:57:55 roberto Exp roberto $
** Lua - An Extensible Extension Language
** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
** http://www.lua.org mailto:info@lua.org
@ -185,7 +185,7 @@ LUA_API void lua_gettable (lua_State *L, int idx);
LUA_API void lua_getfield (lua_State *L, int idx, const char *k);
LUA_API void lua_rawget (lua_State *L, int idx);
LUA_API void lua_rawgeti (lua_State *L, int idx, int n);
LUA_API void lua_newtable (lua_State *L);
LUA_API void lua_createtable (lua_State *L, int narr, int nrec);
LUA_API void *lua_newuserdata (lua_State *L, size_t sz);
LUA_API int lua_getmetatable (lua_State *L, int objindex);
LUA_API void lua_getfenv (lua_State *L, int idx);
@ -254,6 +254,8 @@ LUA_API void lua_concat (lua_State *L, int n);
#define lua_pop(L,n) lua_settop(L, -(n)-1)
#define lua_newtable(L) lua_createtable(L, 0, 0)
#define lua_register(L,n,f) \
(lua_pushstring(L, n), \
lua_pushcfunction(L, f), \