Lua 5.1.2 is goto statement possible?

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.
Ekamu
Party member
Posts: 171
Joined: Fri Sep 20, 2013 11:06 am

Lua 5.1.2 is goto statement possible?

Post by Ekamu » Thu Nov 14, 2013 2:12 pm

Many other languages have a continue statement that skips the rest of the current iteration of the innermost loop. In Lua 5.2, this can be imitated using goto:

> for i = 1, 10 do
>> if i>3 and i<6 then goto continue end
>> print(i)
>> ::continue:: -- a name surrounded in :: :: is a goto label
>> end
Image
Is this possible in Lua 5.1.4.
(LOVE 8.0 Uses Lua 5.1.4 right? or 5.2)

User avatar
ejmr
Party member
Posts: 302
Joined: Fri Jun 01, 2012 7:45 am
Location: South Carolina, U.S.A.
Contact:

Re: Lua 5.1.2 is goto statement possible?

Post by ejmr » Thu Nov 14, 2013 2:44 pm

I don't think LÖVE would support goto statements unless compiled to use LuaJIT, which does backport the feature from Lua 5.2. However, I am only speculating.

Edit: And yes, LÖVE uses Lua 5.1 by default, not 5.2.
ejmr :: Programming and Game-Dev Blog, GitHub
南無妙法蓮華經

Xugro
Citizen
Posts: 61
Joined: Wed Sep 29, 2010 8:14 pm

Re: Lua 5.1.2 is goto statement possible?

Post by Xugro » Thu Nov 14, 2013 4:07 pm

For such a simple problem it is better to use the break keyword:
http://www.lua.org/pil/4.4.html

User avatar
Roland_Yonaba
Inner party member
Posts: 1562
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Lua 5.1.2 is goto statement possible?

Post by Roland_Yonaba » Thu Nov 14, 2013 6:59 pm

The goto statement was only introduced in Lua 5.2.
Since Löve uses Lua 5.1.4, you won't have it.
Actually I don't feel like using it, but I reckon goto might have some advantages.
Anyway, as Xugro mentionned, there's the break statement, and that's fairly enough. :)

User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Lua 5.1.2 is goto statement possible?

Post by micha » Thu Nov 14, 2013 7:23 pm

Xugro wrote:For such a simple problem it is better to use the break keyword:
http://www.lua.org/pil/4.4.html
In the above post, goto is used to simulate a "continue" not a "break". "Break" ends the loop and jumps to the part after the loop. "Continue" only ends the current iteration of the loop and goes to the next iteration. I haven't used it ever, though.

Ekamu
Party member
Posts: 171
Joined: Fri Sep 20, 2013 11:06 am

Re: Lua 5.1.2 is goto statement possible?

Post by Ekamu » Thu Nov 14, 2013 8:39 pm

I thought it would be useful for situations where you would need to jump to a specific function outside your loop instead of just the next one outside your loop.
But I actually don't have use for it in my code. just interested to know if it was possible in 5.1.

Whats wrong with 5.2? I thought since it being a later version its better. maybe not since LOVE sticks to 5.1

User avatar
Roland_Yonaba
Inner party member
Posts: 1562
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Lua 5.1.2 is goto statement possible?

Post by Roland_Yonaba » Thu Nov 14, 2013 9:39 pm

Ekamu wrote:Whats wrong with 5.2? I thought since it being a later version its better. maybe not since LOVE sticks to 5.1
You might to go through these threads:

User avatar
ejmr
Party member
Posts: 302
Joined: Fri Jun 01, 2012 7:45 am
Location: South Carolina, U.S.A.
Contact:

Re: Lua 5.1.2 is goto statement possible?

Post by ejmr » Thu Nov 14, 2013 9:59 pm

This is somewhat off topic, but what are the obvious, large issues with Lua 5.2 that stand in the way of LÖVE using it? The first thread mentions some backwards compatibility problems, which is what I am the most interested in. Since 5.2 will be two years old next month I don't feel like the "it's too new" argument has much merit anymore.
ejmr :: Programming and Game-Dev Blog, GitHub
南無妙法蓮華經

User avatar
slime
Solid Snayke
Posts: 2851
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Lua 5.1.2 is goto statement possible?

Post by slime » Thu Nov 14, 2013 10:05 pm

ejmr wrote:This is somewhat off topic, but what are the obvious, large issues with Lua 5.2 that stand in the way of LÖVE using it? The first thread mentions some backwards compatibility problems, which is what I am the most interested in. Since 5.2 will be two years old next month I don't feel like the "it's too new" argument has much merit anymore.
  • If Lua 5.2 is not built in compatibility mode, a lot of code written for Lua 5.1 will not work in 5.2. The same goes for Lua libraries - the current Luasocket release only works in Lua 5.1 or Lua 5.2-with-compatibility with some slight modifications to Luasocket.
  • Code written for Lua 5.1 is completely compatible with LuaJIT without any modification. The same is not true for code written for Lua 5.2.
LÖVE 0.9.0 will use LuaJIT by default. If the choice is either Lua 5.2 or LuaJIT for games, I'd pick LuaJIT 100% of the time.

User avatar
Roland_Yonaba
Inner party member
Posts: 1562
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Lua 5.1.2 is goto statement possible?

Post by Roland_Yonaba » Thu Nov 14, 2013 10:11 pm

slime wrote:LÖVE 0.9.0 will use LuaJIT by default
Image

Post Reply

Who is online

Users browsing this forum: CogentInvalid, Google [Bot] and 10 guests