lua-users home
lua-l archive

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


On Mar 20, 2006, at 8:41 AM, Chris Marrin wrote:
This WILL happen if you do this:

    t[{1,2,3}]

As a silly idea, to simplify the syntax, how about:
t{ 1, 2, 3 }

Where 't' is actually a closure function wrapping up a table of your choosing?

function narray( ... )
	-- fill out your table here
	-- local _t =
	return function( ... )
		local indices = { ... }
		local theObj = _t
		for i=1,#indices do
			theObj = theObj[ indices[ i ] ]
		end
		return theObj
	end
end

local t = narray( 3, 3, 3 )
print( t{ 1, 2, 3 } )