Re: tables with multiple indeces?
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: tables with multiple indeces?
- From: Gavin Kistner <gavin@...>
- Date: 2006年3月20日 09:09:22 -0700
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 } )