Help with OOP

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Sir_Silver
Party member
Posts: 286
Joined: Mon Aug 22, 2016 2:25 pm
Contact:

Re: Help with OOP

Post 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.
nyenye
Citizen
Posts: 62
Joined: Fri Dec 02, 2016 1:44 pm

Re: Help with OOP

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 4 guests