Page 2 of 2

Re: Help with OOP

Posted: Sun Dec 04, 2016 8:08 am
by Sir_Silver
Just a small note:

Code: Select all

item = {}
item.__index = item

function item:new(id)
   local item_object = setmetatable({}, item)

   return item_object
end

Seems that "item.__index = item" doesn't do anything at all.
You might want to check that again, the example I wrote works fine. You might have a point with separating the "interface" as you call it so that an object doesn't have the new method, but as it stands the code works exactly as intended lol.

Re: Help with OOP

Posted: Mon Dec 05, 2016 1:44 pm
by nyenye
It's the same thing, a table with a property __index with value item, so yes it's the same in both cases.