[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: OOP trouble in Lua with Love2d
- From: Michal Kolodziejczyk <miko@...>
- Date: Tue, 21 May 2013 08:12:41 +0200
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