lua-users home
lua-l archive

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


On 20.05.2013 19:58, Coda Highland wrote:
> I would also have initialized the default to { r=0, g=0, b=0 } rather
> than {}, to avoid doing a modulo on nil.

I think OP tried to do that (with "Color = {r = 0, g = 0, b = 0} in
first line"), but failed to use this on object creation. Modified code
should be written as:

Color = {r = 0, g = 0, b = 0}

function Color:new(o)
     local o = o or {}
     o.r = (o.r or Color.r) % 255
     o.g = (o.g or Color.g) % 255
     o.b = (o.b or Color.b) % 255
     setmetatable(o, self)
     self.__index = self
     return o;
end

Regards,
miko