Lua function declarations

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
pixelfixation
Prole
Posts: 2
Joined: Fri Dec 06, 2019 8:40 pm

Lua function declarations

Post by pixelfixation »

Hey guys newbie question.

In Lua what is the difference between these two function declarations. I'm trying to use Gspot (side note what is up with that name?!) to make some UI elements and I'm wondering if my errors are coming from this difference.

Code: Select all

love.load = function()
and

Code: Select all

function = love.load()
They seem pretty much the same to me but I haven't touched Lua before yesterday. Thanks!
User avatar
bobbymcbobface
Citizen
Posts: 78
Joined: Tue Jun 04, 2019 8:31 pm

Re: Lua function declarations

Post by bobbymcbobface »

"love.load = function()" might have to be "love.load() = function()"
but I'd recommend doing

function love.load()
blah blah blah
end

since i think both of those functions return nil. Is there a specific error or does the code just stop entirely?
I make games that run on potatoes :P
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Lua function declarations

Post by zorg »

pixelfixation wrote: Sat Dec 07, 2019 12:31 am Hey guys newbie question.

In Lua what is the difference between these two function declarations. I'm trying to use Gspot (side note what is up with that name?!) to make some UI elements and I'm wondering if my errors are coming from this difference.

Code: Select all

love.load = function() ... end
and

Code: Select all

function love.load() ... end
They seem pretty much the same to me but I haven't touched Lua before yesterday. Thanks!
Previous era, people didn't care about naming their libs juvenile things.

Anyway, both declarations are equivalent, the second is just syntax sugar for the first, since functions are first-class values in lua; i edited the above quoted code blocks though so that it shows the correct syntax for both (minus the dots, that's just there to denote stuff goes inside :P)
Your issues are probably elsewhere.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Stifu
Party member
Posts: 106
Joined: Mon Mar 14, 2016 9:53 am
Contact:

Re: Lua function declarations

Post by Stifu »

pixelfixation wrote: Sat Dec 07, 2019 12:31 amI'm trying to use Gspot (side note what is up with that name?!)
Many LÖVE libraries and tools have a name that is a love-related pun, like Möan, Polyamory, LövePotion, Lovebird, MakeLove, etc.
Zabuyaki, our upcoming beat 'em up: https://www.zabuyaki.com
User avatar
pixelfixation
Prole
Posts: 2
Joined: Fri Dec 06, 2019 8:40 pm

Re: Lua function declarations

Post by pixelfixation »

Is there a different GUI Library you guys would recommend I use?
User avatar
riidom
Citizen
Posts: 74
Joined: Wed Jun 19, 2013 4:28 pm
Location: irgendwo an der Elbe
Contact:

Re: Lua function declarations

Post by riidom »

I am using Slab at the moment, I am not very deep inside it yet, mostly having two big text windows where I spam log and debug stuff into.
But it looks good so far.
https://love2d.org/forums/viewtopic.php?f=5&t=86410
https://github.com/coding-jackalope/Slab/wiki
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Lua function declarations

Post by raidho36 »

pixelfixation wrote: Sat Dec 07, 2019 12:31 am In Lua what is the difference between these two function declarations.
None.
Post Reply

Who is online

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