Page 1 of 1

C++ programmer going into LOVE

Posted: Thu Jul 07, 2011 3:18 am
by Cl4d
I really have hard time getting into LOVE, I have never done any scripting. Are there classes, inheritance? what about mainloops for game? I'm a bit confused.

Re: C++ programmer going into LOVE

Posted: Thu Jul 07, 2011 4:04 am
by RPG
The source code of engine is very complicated, I had to choose another engine to be modified. But LUA language and LOVE API are very simple, try to download tutorials.

Re: C++ programmer going into LOVE

Posted: Thu Jul 07, 2011 5:52 am
by Ensayia
Lua is not only a scripting language, but a full programming language as well. Coming from C++ a few of the nice changes are no need to declare variable types or sizes, and Lua's famous table data structure. A table is something akin to a dynamically resizable array that can hold numbers, strings, functions, other tables... the list goes on. Lua also has an excellent garbage collector to manage memory for you.

Everyone here will point you here to get started: http://www.lua.org/pil/
It is one of the best resources for learning the language.

Also if you are interested in OOP: http://www.lua.org/pil/13.html
Lua metatables can be used to create an OOP type environment. This is more advanced stuff you can play with once you get a grasp on the language.

The first thing I can recommend you to do after learning syntax is to learn how to use Tables. They are one of the greatest things that sets Lua apart from other languages!

Re: C++ programmer going into LOVE

Posted: Thu Jul 07, 2011 7:16 am
by Robin
As for the game main loop see love.run. Also note that you rarely need to redefine it yourself.

Re: C++ programmer going into LOVE

Posted: Thu Jul 07, 2011 7:28 am
by kikito
Cl4d wrote:I really have hard time getting into LOVE, I have never done any scripting. What about mainloops for game? I'm a bit confused.
There is a main loop (love.run) in LÖVE, but most of the time (specially when you are learning) you don't need to use it. Instead there are three functions: love.load() for loading initial resources (i.e. images, etc), love.update(dt) for updating variables (moving characters, adding new ones, etc) and love.draw() to draw them.
Cl4d wrote:Are there classes, inheritance?
LÖVE is scripted in the Lua language. Lua isn't Object-oriented. If you are familiar with Javascript, it's similar in some aspects.

Nevertheless, there are lots of people (me among them) doing Object Oriented libraries on top of the "basic structure" provided by Lua (just like there are some OOP libraries for Javascript, too).

On the Libraries section in the wiki there are at least two: my library, MiddleClass and also SECS

Re: C++ programmer going into LOVE

Posted: Thu Jul 07, 2011 6:52 pm
by T-Bone
As it has already been pointed out, Lua does not have real object orientation built in. It comes very close if you master metatables, though. As a matter of fact, after just a few weeks of Lua, I find metatables to be very useful and flexible. Before Lua, I mainly wrote Java so programming without OO is unthinkable for me, yet metatables provide pretty much everything you need.

There are lots of guides and stuff, but I thought I'd write a simple "class" to you just to show how it's done with metatables.

Code: Select all

example={}

example.attribute = 4
function example:method()
    self.attribute = self.attribute + 1
end

function newExampleObject()
   newObject = {}
   setmetatable(newObject,example)
   example.__index=example
   return newObject
end

obj = newExampleObject()
obj:method()
obj:method()
print(obj.attribute) --prints 6


Re: C++ programmer going into LOVE

Posted: Fri Jul 08, 2011 4:32 am
by BlackBulletIV
T-Bone wrote:

Code: Select all

example={}

example.attribute = 4
function example:method()
    self.attribute = self.attribute + 1
end

function newExampleObject()
   newObject = {}
   setmetatable(newObject,example)
   example.__index=example
   return newObject
end
That could be rephrased as:

Code: Select all

example = {}
example.__index = example

...

function newExampleObject()
  return setmetatable({}, example)
end
By the way, I've got a tutorial on metatables that might be useful.

Re: C++ programmer going into LOVE

Posted: Fri Jul 08, 2011 7:06 am
by T-Bone
BlackBulletIV wrote:
T-Bone wrote:

Code: Select all

example={}

example.attribute = 4
function example:method()
    self.attribute = self.attribute + 1
end

function newExampleObject()
   newObject = {}
   setmetatable(newObject,example)
   example.__index=example
   return newObject
end
That could be rephrased as:

Code: Select all

example = {}
example.__index = example

...

function newExampleObject()
  return setmetatable({}, example)
end
By the way, I've got a tutorial on metatables that might be useful.
That's true. Your formulations are better ^^