C++ programmer going into LOVE

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.
Post Reply
Cl4d
Prole
Posts: 1
Joined: Wed Jul 06, 2011 11:39 pm

C++ programmer going into LOVE

Post 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.
User avatar
RPG
Party member
Posts: 157
Joined: Wed Mar 02, 2011 5:02 am
Location: Russia
Contact:

Re: C++ programmer going into LOVE

Post 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.
User avatar
Ensayia
Party member
Posts: 399
Joined: Sat Jun 12, 2010 7:57 pm

Re: C++ programmer going into LOVE

Post 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!
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: C++ programmer going into LOVE

Post by Robin »

As for the game main loop see love.run. Also note that you rarely need to redefine it yourself.
Help us help you: attach a .love.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: C++ programmer going into LOVE

Post 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
Last edited by kikito on Thu Jul 07, 2011 8:37 pm, edited 1 time in total.
When I write def I mean function.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: C++ programmer going into LOVE

Post 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

User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: C++ programmer going into LOVE

Post 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.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: C++ programmer going into LOVE

Post 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 ^^
Post Reply

Who is online

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