A good OO lib

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
rokit boy
Party member
Posts: 198
Joined: Wed Jan 18, 2012 7:40 pm

A good OO lib

Post by rokit boy »

Can someone suggest me a very good OO lib with the syntax as close to this:

Code: Select all

class Class1 {

hi = 1
hi2 = 2 -- general fields

function Class1(as) -- constructor
hi2 = as
end

function getHi() -- methods
return hi
end
Then in another script:

Code: Select all

Class1 class1 = new Class1(12)

trol = class1.getHi()
print(trol)
Can someone suggest me one as close to that as possible? Or any class lib if what I just show is nowhere near possible in lua or any other thing similar to my examples.
u wot m8
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: A good OO lib

Post by kikito »

I think Slither is your best bet. Here're some examples.

https://bitbucket.org/bartbes/slither/s ... amples.lua

Obviuosly the syntax is not exactly like the one you proposed, but it's near enough.
When I write def I mean function.
User avatar
rokit boy
Party member
Posts: 198
Joined: Wed Jan 18, 2012 7:40 pm

Re: A good OO lib

Post by rokit boy »

Ok so I think it looks good but when is the __init__ and the __add__ called?
I'm pretty sure __init__ is the initialization but what is __add__?
u wot m8
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: A good OO lib

Post by nevon »

rokit boy wrote:Ok so I think it looks good but when is the __init__ and the __add__ called?
I'm pretty sure __init__ is the initialization but what is __add__?
__add__ is run when you try to add two instances.

Code: Select all

derpherp = derp + herp
You can look at the examples.
User avatar
rokit boy
Party member
Posts: 198
Joined: Wed Jan 18, 2012 7:40 pm

Re: A good OO lib

Post by rokit boy »

nevon wrote:
rokit boy wrote:Ok so I think it looks good but when is the __init__ and the __add__ called?
I'm pretty sure __init__ is the initialization but what is __add__?
__add__ is run when you try to add two instances.

Code: Select all

derpherp = derp + herp
You can look at the examples.
Thanks!
u wot m8
User avatar
rokit boy
Party member
Posts: 198
Joined: Wed Jan 18, 2012 7:40 pm

Re: A good OO lib

Post by rokit boy »

are there any other functions apart from __init__ and __add__ ?
u wot m8
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: A good OO lib

Post by nevon »

rokit boy wrote:are there any other functions apart from __init__ and __add__ ?
Yes. __call__, __len__, __add__, __sub__, __mul__, __div__, __mod__, __pow__, and __neg__

They're all just aliases of the Lua standard metamethods.
User avatar
rokit boy
Party member
Posts: 198
Joined: Wed Jan 18, 2012 7:40 pm

Re: A good OO lib

Post by rokit boy »

Sow ill init be the constructor, __add,div,sub,mul,mod,pow,neg__ are mathematical and the rest I don't know.

Looking forward to making stuff with this.
u wot m8
User avatar
rokit boy
Party member
Posts: 198
Joined: Wed Jan 18, 2012 7:40 pm

Re: A good OO lib

Post by rokit boy »

What is __len__?

Btw. I smell python. Is it python inspired?
u wot m8
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: A good OO lib

Post by Robin »

rokit boy wrote:What is __len__?
The # operator. It is not overridable for tables in Lua 5.1 (though it will be for Lua 5.2).
rokit boy wrote:Btw. I smell python. Is it python inspired?
Yes.
Help us help you: attach a .love.
Post Reply

Who is online

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