Looking for fast and simple OOP library

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
reno57
Prole
Posts: 17
Joined: Thu Apr 14, 2016 9:46 pm

Looking for fast and simple OOP library

Post by reno57 »

Hello,

For my project i use an OOP library : GitHub - rxi/classic: Tiny class module for Lua.
I realized that there is others libraries like : GitHub - kikito/middleclass : A simple OOP library for Lua.

As i'm looking for a fast and easy to use OOP library, do you think my choice is right ? or, may be i should switch to kikito's library or to another one ?

Have you some library to suggest ?

thanks in advance
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Looking for fast and simple OOP library

Post by Positive07 »

I generaly use Middleclass, but you should use whatever you feel better with. If you like Classic then just go with it.

I think currently the only one that takes performance as the first objective is Classy which is similar to Middleclass. And the one that takes filesize into consideration is 30log, Classic is also really tiny!

Middleclass is the most complete one, with inheritance, full metamethods support and subclassing. Also I consider it's documentation to be great!

Again, use whatever you think works best, you should try them and decide on yourself. They are all very similar though!
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
reno57
Prole
Posts: 17
Joined: Thu Apr 14, 2016 9:46 pm

Re: Looking for fast and simple OOP library

Post by reno57 »

Thanks Positive07, to share your experience about OOP library.
User avatar
scissors61
Citizen
Posts: 76
Joined: Fri Jan 08, 2016 10:16 am

Re: Looking for fast and simple OOP library

Post by scissors61 »

I think the forum was trying to answer this question, and I agree.
Attachments
Selección_001.jpg
Selección_001.jpg (65.8 KiB) Viewed 5003 times
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: Looking for fast and simple OOP library

Post by airstruck »

As i'm looking for a fast and easy to use OOP library, do you think my choice is right?
Is it fast and easy to use? Does it have the features you need, but not too many features you don't need? If so, it's probably fine.

If you only use single inheritance, and don't need mixins or other fancy stuff, it should be either fairly trivial or somewhat educational to whip something up yourself; for example if you just want the convenience of being able to define methods with the Class:method syntax. Here's the "class.lua" from a project I worked on recently where I decided to use classes to achieve OOP.

Code: Select all

return function (super)
    local meta = { __index = {} }
    return setmetatable(meta.__index, {
        __call = function (_, ...)
            local instance = setmetatable({}, meta)
            if instance.init then
                instance:init(...)
            end
            return instance
        end,
        __index = super
    })
end
Also probably worth noting, the "class" metaphor is really not necessary for OOP in Lua. You can just as well use factory functions:

Code: Select all

local bark = function (self) print(self.name .. ' says woof') end
local Dog = function (name) return { name = name, bark = bark } end

local dog = Dog('Rufus')
dog:bark() -- 'Rufus says woof'
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 249 guests