vsariola / pakettic

TIC-80 cartridge packer
MIT License
20 stars 4 forks source link

Parentheses to left of colon operator optimised away #14

Closed going-digital closed 9 months ago

going-digital commented 9 months ago

Pakettic fails on this example:

function TIC()
    cls()
    print(("abc"):sub(1, f//10 % 4 + 1),0,0,12, false, 1)
    f = f + 1
end
f=0

Pakettic optimises ("abc"):sub() to "abc":sub(). This breaks the code. In Lua, ("abc") is a string object, but "abc" is a literal which doesn't have string methods.

going-digital commented 9 months ago

Workaround: Use an intermediate variable.

function TIC()
    cls()
    x="abc"
    print(x:sub(1, f//10 % 4 + 1),0,0,12, false, 1)
    f = f + 1
end
f=0
vsariola commented 9 months ago

Should be fixed, can you try: pip install git+https://github.com/vsariola/pakettic.git@main to check if it resolves your issue.

vsariola commented 9 months ago

If it's ok, I probably should release a minor release before lovebyte, as there's now two bug fixes already there. This one of yours was actually possible to encounter in sizecoding, the other one is more rare.

going-digital commented 9 months ago

Working well - thanks for the fix!