lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On 20/11/13 17:37, Rena wrote:
I wonder if there's a good reason for Lua 5.3 or a third-party library
to add table.new(narr, nrec) (as seen in LuaJIT) to Lua? It seems like a
useful optimization, and its implementation should only take a couple of
lines (call lua_createtable() and return).

--
Sent from my Game Boy.

When I want it and whilst using vanilla Lua then I use the following which I feel is horrible. It would be nice to finally have it in the core but I would not hold my breath.

dmail@dmail00:~$ cat table_new.lua
local t ={nil,nil,nil,nil,nil,nil,[1]=nil,[1]=nil,[1]=nil}
dmail@dmail00:~$ luac-5.2.2 -l -l table_new.lua

main <table_new.lua:0,0> (7 instructions at 0x927db60)
0+ params, 7 slots, 1 upvalue, 1 local, 2 constants, 0 functions
	1	[1]	NEWTABLE 	0 6 3
	2	[1]	LOADNIL  	1 5
	3	[1]	SETTABLE 	0 -1 -2	; 1 nil
	4	[1]	SETTABLE 	0 -1 -2	; 1 nil
	5	[1]	SETTABLE 	0 -1 -2	; 1 nil
	6	[1]	SETLIST  	0 6 1	; 1
	7	[1]	RETURN   	0 1
constants (2) for 0x927db60:
	1	1
	2	nil
locals (1) for 0x927db60:
	0	t	7	8
upvalues (1) for 0x927db60:
	0	_ENV	1	0

--
Liam