Posted 01 May 2013 - 01:52 PM
I have just started playing around with OOP in lua and don't understand why this doesn't work:
my understanding would be that OSLabel would inherit caption from OSObject (As it does in c++) and so lbl.caption should equal "Object_Caption" but as far as I can see it equals nil..? so presumably I'm doing something stupid :)/>
Error: bios:156: bad argument: string expected, got nil
OSObject = {
caption = "Object_Caption",
x=1,
y=1
}
OSLabel = {
__index = OSObject,
New = function(self)
local new = {}
setmetatable(new,{__index = self})
return new
end
}
local lbl = OSLabel:New()
write("lbl.caption = ")
write(lbl.caption)
my understanding would be that OSLabel would inherit caption from OSObject (As it does in c++) and so lbl.caption should equal "Object_Caption" but as far as I can see it equals nil..? so presumably I'm doing something stupid :)/>
Error: bios:156: bad argument: string expected, got nil