lua-users home
lua-l archive

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


Hi Everyone,
PiL2 as well as PiL1 has a section on multiple inheritance (section
16.3) complete with an example on  how to implement multiple
inheritance in Lua. The problem with this implementation is that the
inheritance hierarchy is traversed in "depth-first" fashion. This has
a problem. Let say I have the following hierarchy

T--> M --> B   [ B has "foo"]
 \-> N             [ N has "foo"]

If I try T.foo it will find B.foo because depth-first search visits
the whole T->M->B hierarchy before T->N. One gets "foo" from a
grandparent instead of a direct parent.

More natural way of traversing inheritance hierarchy would be a
"breadth-first search" when all immediate parents are visited first
followed by all the grandparents across all the parents and so on.

Is there any simple way to do breadth-first search in this case?
Conventional wisdom from CS books recommends to deploy a FIFO queue.

Thanks,
--Leo--