i very much like how object oriented programming is described in "programming in lua" 16.1, 16.2:
http://www.lua.org/pil/16.1.html
http://www.lua.org/pil/16.2.html
and would like to follow this approach. but i would like to take things a little further: i would like to have a base "class" called "class", which should be the base of all subclasses, because i want to implement some helper methods there (like "instanceof" etc.), but essentially it should be as described in the book:
function class:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
now to my problem:
i would like to have a class "number", which inherits from "class":
number = class:new()
i would like to define metamethods for operator overloading (__add, __sub, etc.) in this class, so something like:
n1 = number:new()
n2 = number:new()
print(n1 + n2)
works. this is not really a problem. but now i would like to have a third class "money", which inherits from "number":
money = number:new{value=10,currency='EUR'}
i introduce some new properties here and such.
now my problem is, that i don't get things to work, that "money" inherits all methods from "class" and "number" including all metamethods defined in "number".
i've tried several things like overwriting "new" or modifying metatables but i was not able to get things to work, without either loosing the methods of "class" in "money" or loosing the metamethods of "number" in "money"
i know, that there a lot's of class implementations out there, but i would really like to stick with the minimal approach of lua itself.
any help would be very much appreciated!
thanks very much!