dansanderson / picotool

Tools and Python libraries for manipulating Pico-8 game files. http://www.lexaloffle.com/pico-8.php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

luamin should always start short-ifs on new lines

dansanderson opened this issue · comments

Short-ifs only work if they're the only thing on the line. There are some cases where luamin is collapsing the initial whitespace to just a space on the previous line, e.g.:

if(a) then
 if(b) c=1
end

(IIRC there's already special handling to make sure short-if ends with a newline, so it shouldn't be difficult to make it start with one as well.)

I think I saw another mention of this "issue" recently - does that mean you're adding support for short-if's in luamin?
Coz I remember having to change all mine to full-if's in order to make the output valid and I'd like to claw back some of those tokens! 😉

Here's the hack that preserves the newline after a short-if: https://github.com/dansanderson/picotool/blob/master/pico8/lua/lua.py#L1054

This needs to be smarter (and probably more elaborate) to preserve the newline before the if. A cheaper fix is probably to just preserve all newlines, i.e. truncate leading and trailing space per line, and only collapse whitespace within the line.

Yes I'd like to fix it. Pull requests welcome! :)

OK I fixed it. Wasn't too bad. :)