Davidobot / love.js

LÖVE ported to the web using Emscripten, updated to the latest Emscripten and LÖVE (v11.5)
MIT License
605 stars 27 forks source link

goto statements cause a syntax error in love.js #77

Open akseliv opened 1 year ago

akseliv commented 1 year ago

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)

mvolkmann commented 1 year ago

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.

ParticleG commented 1 year ago

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

rbaltrusch commented 6 months ago

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:

alexjgriffith commented 5 months ago

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.