[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lookup nil table index
- From: lua@...
- Date: Thu, 30 Nov 2006 20:33:53 +0100
* On 2006-11-30 Michael Wolf <email@example.com> wrote :
> >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.