Page 1 of 1

Lua function declarations

Posted: Sat Dec 07, 2019 12:31 am
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!

Re: Lua function declarations

Posted: Sat Dec 07, 2019 2:26 pm
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?

Re: Lua function declarations

Posted: Sat Dec 07, 2019 4:24 pm
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.

Re: Lua function declarations

Posted: Sat Dec 07, 2019 5:36 pm
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.

Re: Lua function declarations

Posted: Sat Dec 07, 2019 6:17 pm
by pixelfixation
Is there a different GUI Library you guys would recommend I use?

Re: Lua function declarations

Posted: Sat Dec 07, 2019 8:27 pm
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

Re: Lua function declarations

Posted: Sat Dec 07, 2019 9:33 pm
by raidho36
pixelfixation wrote: Sat Dec 07, 2019 12:31 am In Lua what is the difference between these two function declarations.
None.