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

string.format("%s", true) raises an error #11

Open Davidobot opened 4 years ago

idbrii commented 3 years ago

I don't know anything about love.js internals, but I read something recently that's relevant:

According to this answer, it seems that Lua 5.2 calls a new C function luaL_tolstring which autoconverts booleans to strings. Maybe love.js is somehow not building with the right flag to include that version?

alexjgriffith commented 2 years ago

This is not a bug in love.js. Its a PUC Lua5.1 issue :(

Casting to strings in string.format is not defined behaviour in Lua5.1. As with most undefined behaviour its treated differently between PUC and luajit implementations. PUC will only cast numbers as strings, while luajit, for compatibility with Lua5.2, will cast numbers, tables and bools as strings.

If you need to use a bool in string.format, cast it to a string using tostring.

string.format("%s", tostring(true))
idbrii commented 2 years ago

But love2d uses luajit and not PUC Lua5.1, so that shouldn't be an issue here? Maybe something in love.js changes some compatibility flags that drops us back to the 5.1 behaviour?

alexjgriffith commented 2 years ago

Love2d supports PUC Lua5.1 by default. It is used on platforms that don't support luajit. By passing in the -LOVE_JIT=0 when building the megasource it reverts to using Lua 5.1 .

Unfortunately, using PUC Lua5.1 is necessary for APPLE and Emscripten builds as the core of luajit is platform specific assembly (not c or c++) . It would have to manually be ported to wasm.

If you want to try, you can remove the arg from the build script.

LuaJit Disabled on Mac

LuaJit Disabled in Emscripten

web-love-jit The absence of the jit global variable indicates that this version of love was not compiled with luajit.