Love Object Orientated Programming

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Love Object Orientated Programming

Post by Robin »

You won't get the community very exited with projects like this, though. If that is your goal, just write a game. Those things are like catnip to us. :P
Help us help you: attach a .love.
mager1794
Prole
Posts: 5
Joined: Wed Sep 01, 2010 3:18 am

Re: Love Object Orientated Programming

Post by mager1794 »

I will ^_^

and I'll create some reusable classes while im at it. But i do intend to develop a good IDE for Love.

I've done it before http://www.mmowned.com/forums/world-of- ... iptor.html and thats not even the final version. The final version was amazing. I intend to base off of my source for that it should only take a few weeks. :P Is that something to excite the community about? lol
User avatar
Luiji
Party member
Posts: 396
Joined: Mon May 17, 2010 6:59 pm

Re: Love Object Orientated Programming

Post by Luiji »

It would if the last 5 IDEs didn't die. :cry:
Good bye.
User avatar
leiradel
Party member
Posts: 184
Joined: Thu Mar 11, 2010 3:40 am
Location: Lisbon, Portugal

Re: Love Object Orientated Programming

Post by leiradel »

I wrote once or twice to the Lua mailing list asking for OOP support in the language. I understand that metatables can be used to fake the OO paradigm in Lua, but there are some problems with them.

One big problem in my opinion is when you use many Lua libraries developed by others. If each use their own OOP library you end up with different ways to do the same thing, i.e. to instantiate one object from a class in one library you use "obj = Class.new()", to do the same thing with a class from another library you use "obj = Class:Create()"...

As OOP is such an useful feature to have, what people think about having a love.oop library, blessed by Löve developers? What features do you need from such a library? Mine are:

1. Don't look cryptic
2. Allow the calling of inherited methods
3. Allow multiple inheritance
4. Be lightweight, i.e. do not perform tons of work when I call a method, ideally just one table lookup to get the method
5. Have an "instanceof" function just like the Java operator with the same name

It should look similar to this:

Code: Select all

local Image = class()

function Image:new( filename )
...
end

local Sprite = class( Image )

function Sprite:new( filename )
  Image.new( self ) -- inherited method call (constructor in this case)
  ...
end

local hero = Sprite( 'hero.png' ) -- calls new with a newly created instance
Polymorphism comes for free as Lua is dynamically typed. An object can be anything, and if it's not the right type, you'll get an error sooner or later: attempt to call method 'xxx' (a nil value) :D

Hope this helps mager1794 in his efforts and we end up with an OOP library to rule them all...

Cheers,

Andre
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Love Object Orientated Programming

Post by vrld »

leiradel wrote:As OOP is such an useful feature to have, what people think about having a love.oop library, blessed by Löve developers? What features do you need from such a library?
As said before, the wiki already features some libraries that do what you want to. There is also a complete chapter devoted to OOP in Programming in Lua.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
leiradel
Party member
Posts: 184
Joined: Thu Mar 11, 2010 3:40 am
Location: Lisbon, Portugal

Re: Love Object Orientated Programming

Post by leiradel »

vrld wrote:As said before, the wiki already features some libraries that do what you want to. There is also a complete chapter devoted to OOP in Programming in Lua.
I'm aware of that. I also own a Programming in Lua book, and I have written class libraries myself, the first one being for Lua 3. What I'm saying is that LÖVE should have one and only one class library, and the only way of having that is if the developers embed one inside the engine so it becomes *the* class library. It could be one of the existing libraries or could be a new one.

Imagine yourself using a couple of libraries in your LÖVE application, each one using its own class library. When creating an instance you'll have to remember from which library it is so that you know you have to create it with Class:new() instead of Class.Create(). Having only one class library improves code readability, interoperability between different libraries and efficiency when writing code.

That can't be a bad thing, can it?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Love Object Orientated Programming

Post by Robin »

leiradel wrote:That can't be a bad thing, can it?
Except it's Lua. You seem to know it very well, you should also know that agreeing on a single OOP method is not going to happen.
leiradel wrote:Imagine yourself using a couple of libraries in your LÖVE application, each one using its own class library. When creating an instance you'll have to remember from which library it is so that you know you have to create it with Class:new() instead of Class.Create(). Having only one class library improves code readability, interoperability between different libraries and efficiency when writing code.
Not really. Each library has its own API anyway, OOP notation is just a minor part of it.
Help us help you: attach a .love.
User avatar
leiradel
Party member
Posts: 184
Joined: Thu Mar 11, 2010 3:40 am
Location: Lisbon, Portugal

Re: Love Object Orientated Programming

Post by leiradel »

Robin wrote:You seem to know it very well, you should also know that agreeing on a single OOP method is not going to happen.
Correct, because Lua authors neither implement it in the language nor mandate that a single class system to be used. But since we're in a closed system here, *we* could have the benefits of standardization.
Robin wrote:
leiradel wrote:Having only one class library improves code readability, interoperability between different libraries and efficiency when writing code.
Not really. Each library has its own API anyway, OOP notation is just a minor part of it.
OOP helps with the understanding of the API. Instead of tenths of functions operating in a number of data types you have a number of data types encapsulating their own methods. So while OOP doesn't replace good API design it helps by structuring your program around your data types and not code. Code is something we write with the only purpose of manipulating data.

I'm neither discussing the benefits of OOP nor saying everyone should use it. Only that there should be only one class system for those who want to use it.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Love Object Orientated Programming

Post by Robin »

leiradel wrote:But since we're in a closed system here, *we* could have the benefits of standardization.
Well...

The whole issue for Lua is a philosophical decision, LÖVE's philosophy is largely based upon it.

Also, on a more practical note: early in the history of LÖVE, it was going to have everything but the kitchen sink, from which the devs departed later on because it was not practical. I'd say love.oop would qualify as a kitchen sink.
leiradel wrote:I'm neither discussing the benefits of OOP nor saying everyone should use it. Only that there should be only one class system for those who want to use it.
I know you are, and that is exactly what I'm arguing against. ;)
Help us help you: attach a .love.
User avatar
leiradel
Party member
Posts: 184
Joined: Thu Mar 11, 2010 3:40 am
Location: Lisbon, Portugal

Re: Love Object Orientated Programming

Post by leiradel »

Robin wrote:I'd say love.oop would qualify as a kitchen sink.
Which is unfortunate. I have this feeling that Lua adoption is held back because many of the available libraries use some kind of class system which is not compatible with other class systems so it's difficult for someone to reuse that code by e.g. extending the base classes to add functionality. You're limit on just using that code.
Robin wrote:I know you are, and that is exactly what I'm arguing against. ;)
Hahaha, I couldn't help it could I?

Yeah, I like the OOP paradigm, so much that I've been always looking for a OO scripting language since the limitations of the no-man's-land Lua approach to it came to me. Unfortunately I still didn't find one having all benefits of Lua *and* OO.
Post Reply

Who is online

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