[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: preallocating space in tables from Lua
- From: David Manura <dm.lua@...>
- Date: Mon, 27 Jul 2009 21:36:07 -0400
On Mon, Jul 27, 2009 at 4:45 AM, Jerome wrote:
> I thought the normal way to do that from Lua was to put nil in a table
> constructor (ie. local t = {nil,nil,nil,nil,nil} would be equivalent
> to lua_createtable(L, 5, 0)), but that's not mentionned on your page.
> I was certain that lhf posted several times about that pseudo-feature,
> but now I can't find any of these threads in the mailing list archive,
> so I may be wrong.
Yes, that would be better, and I'll mention it (though still involves
an unnecessary loadnil/setlist, which the bytecode hack solution
avoids):
$ echo 'local t = {nil,nil,nil,nil,nil}' | luac -p -l -
main <stdin:0,0> (4 instructions, 16 bytes at 0x680df8)
0+ params, 6 slots, 0 upvalues, 1 local, 0 constants, 0 functions
1 [1] NEWTABLE 0 5 0
2 [1] LOADNIL 1 5
3 [1] SETLIST 0 5 1 ; 1
4 [1] RETURN 0 1