love.js icon indicating copy to clipboard operation
love.js copied to clipboard

goto statements cause a syntax error in love.js

Open akseliv opened this issue 2 years ago • 4 comments

Error: Syntax error: main.lua:362: '=' expected near 'continue'

is thrown for this valid Lua code

goto continue

(as Lua lacks a 'continue' statement, goto is typically the next best thing)

akseliv avatar Jan 31 '23 21:01 akseliv

The goto statement was added in Lua 5.2. As far as I can tell, LuaJIT does not support that and love2d uses LuaJIT. So I think you need to rewrite you code using an if statement so that goto isn't needed. I ran into the same problem and solve it by doing just that.

mvolkmann avatar May 25 '23 21:05 mvolkmann

The goto statement was added in Lua 5.2. As far as I can tell, LuaJIT does not support that and love2d uses LuaJIT. So I think you need to rewrite you code using an if statement so that goto isn't needed. I ran into the same problem and solve it by doing just that.

Apparently LuaJIT supports goto, and Love2D supports it too. luajit.org/extensions.html

ParticleG avatar Jun 12 '23 04:06 ParticleG

I have also noticed this issue. According to this stackoverflow thread, the goto statement exists in LuaJIT since v2.0.1 and Lua since 5.2. Although goto should typically be avoided in well-written code, continue allows early exit of loops - having to avoid constructs like if my_early_exit then goto continue end is a significant blow to the usefulness of love.js - hope this issue gets fixed :+1:

rbaltrusch avatar Mar 07 '24 19:03 rbaltrusch

This is a repeat of #62

As pointed out above, goto was only introduced in Lua 5.2. Luajit adopted the feature.

Since there is no wasm support for luajit, the web target relies on Lua 5.1. There is no fix, short of getting luajit to target wasm. When using the web port make sure to stick to Lua 5.1 syntax / semantics.

alexjgriffith avatar Apr 18 '24 04:04 alexjgriffith