lua-users home
lua-l archive

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


> Say, I have three tables, A, B and C. I want user to transparently
> read from them as from single table, first looking to A, then to B,
> and then to C, and raising error if there is no requested key.

> Do anyone know more elegant solution?

How about this:

   A= { a=10 }
   B= { b=20 }
   C= { c=30 }

   setmetatable(A, { __index=B} )
   setmetatable(B, { __index=C} )
   setmetatable(C, { __index=error} )

   print(A.a)
   print(A.b)
   print(A.c)
   print(A.z)

--lhf