lua-users home
lua-l archive

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



You'll find about this at the archives:
http://lua-users.org/cgi-bin/namazu.cgi?query=attempt+to+index+a+nil&sort=score&idxname=lua-l&max=20


John Hind kirjoitti 24.4.2007 kello 19:40:

X = trunk.branch.leaf

 

If “leaf” is nil, “X” will be set to nil, but if “branch” or “trunk” is nil, this is an error “attempt to index a nil value”. Surely it would be architecturally more consistent (and practically more useful) if an attempt to index a nil value evaluated to nil?

 

From a recent piece of code I’ve written:

 

a = tb[p1]; if not a then return end

a = a[p2]; if not a then return end

a = a[p3]; if not a then return end

a = a[p4]; if not a then return end

 

It would have been neat to be able just to write:

 

a = tb[p1][p2][p3][p4]

if not a then return end

 

- John Hind