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

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

Open Davidobot opened this issue 5 years ago • 4 comments

Davidobot avatar Sep 17 '20 16:09 Davidobot

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?

idbrii avatar Mar 29 '21 23:03 idbrii

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))

alexjgriffith avatar Mar 25 '22 20:03 alexjgriffith

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?

idbrii avatar Mar 26 '22 00:03 idbrii

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.

alexjgriffith avatar Mar 26 '22 01:03 alexjgriffith