[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Variable names
- From: Rici Lake <lua@...>
- Date: Wed, 4 Aug 2004 10:18:13 -0500
On 4-Aug-04, at 9:51 AM, Andreas Falkenhahn wrote:
I want to implement a function which creates a new table and
initializes
it, e.g.
newarray(test, 100)
Now the C function newarray() should do the following Lua code:
test = {}
for i=1,100 do test[i] = 0 end
Surely it would be better to use this API:
test = newarray(100)
That is what return values are for :)
int l_newarray (lua_State *L) {
int n = luaL_optint(L, 1, 42);
int i;
lua_newtable(L);
for (i = 1; i <= n; ++i) lua_rawseti(L, -1, 0);
return 1;
}