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 .
rokit boy
Party member
Posts: 198 Joined: Wed Jan 18, 2012 7:40 pm
Post
by rokit boy » Sun Apr 01, 2012 3:14 pm
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
rokit boy
Party member
Posts: 198 Joined: Wed Jan 18, 2012 7:40 pm
Post
by rokit boy » Sun Apr 01, 2012 3:40 pm
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
nevon
Commander of the Circuloids
Posts: 938 Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:
Post
by nevon » Sun Apr 01, 2012 4:00 pm
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.
You can
look at the examples .
rokit boy
Party member
Posts: 198 Joined: Wed Jan 18, 2012 7:40 pm
Post
by rokit boy » Sun Apr 01, 2012 4:06 pm
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.
You can
look at the examples .
Thanks!
u wot m8
rokit boy
Party member
Posts: 198 Joined: Wed Jan 18, 2012 7:40 pm
Post
by rokit boy » Sun Apr 01, 2012 4:07 pm
are there any other functions apart from __init__ and __add__ ?
u wot m8
nevon
Commander of the Circuloids
Posts: 938 Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:
Post
by nevon » Sun Apr 01, 2012 5:53 pm
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 .
rokit boy
Party member
Posts: 198 Joined: Wed Jan 18, 2012 7:40 pm
Post
by rokit boy » Sun Apr 01, 2012 6:26 pm
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
rokit boy
Party member
Posts: 198 Joined: Wed Jan 18, 2012 7:40 pm
Post
by rokit boy » Sun Apr 01, 2012 7:44 pm
What is __len__?
Btw. I smell python. Is it python inspired?
u wot m8
Robin
The Omniscient
Posts: 6506 Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:
Post
by Robin » Sun Apr 01, 2012 7:52 pm
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.
Users browsing this forum: No registered users and 8 guests