lua-users home
lua-l archive

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



* On 2006-11-30 Michael Wolf <miwo@gmx.at> wrote  :

> Hello,
> 
> >I'm working on code with quite deep tables. When referring to an element
> >in the table, I use the table keys joined by dots, eg:
> >
> >	a = thing.foo.bar.this.that
> >
> >When one of the indicated elements does not exist, an error is generated
> >for apperent reasons: attempt to index nil value.
> 
> I use a little function to do the deep table lookup, if a key could be nil:
> 

[ snipped code ]

> You can use it as follows:
> a = indextbl(thing,'foo','bar','this','that')

Yes, I use something similar at this moment ( find("thing.foo.bar.this.that") ),
but for code clarity I was looking for a bit less cluttered solution.
The nil-metatable does the job for me.

-- 
:wq
^X^Cy^K^X^C^C^C^C