lua-users home
lua-l archive

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


There was a bug in the example of MI classes I sent before, although the example worked. This is the error:


function Account:balance()  --> method has the same name as a property
    return self.balance
end

It is interesting to see why the example works anyway. When the an Account object is initialized, a 'balance' property is created in the object which hides the balance() method, which lives in the class (the object's metatable). The example works because it calls a derived method and the class holding the derived method does not have a 'balance' property that would hide it.

Just change the name of the method to getbalance() to make this example correct. It's a revealing bug, anyway.

Regards,
Hugo Etchegoyen