Support nested block comments (a PICO-8 feature, but not a Lua feature)
mhughson opened this issue · 4 comments
I am using the luamin command to try and compress my cart. It does a great job of shrinking the compressed size, but it actually grows my token count by a few hundred (putting it over the limit):
Pre luamin: 8010 tokens
Post-luamin: 8304 tokens
However, the picotool reports no change in token count (and the counts themselves are wrong):
C:\Users\Matt\Downloads\picotool-master>py ./picotool-master/p8tool stats ../../AppData/Roaming/pico-8/carts/mario_new.p8
advanced micro platformer (mario_new.p8)
@matthughson
- version: 16
- lines: 2550
- chars: 59633
- tokens: 9304
- compressed chars: 23048
C:\Users\Matt\Downloads\picotool-master>
C:\Users\Matt\Downloads\picotool-master>py ./picotool-master/p8tool stats ../../AppData/Roaming/pico-8/carts/mario_new_fmt.p8
mario_new_fmt.p8
- version: 8
- lines: 1930
- chars: 31766
- tokens: 9304
- compressed chars: 12466
I have upload the p8 cart file here if you wish to reproduce the issue: mario_new.p8
Is this a known issue? Is there any known work around?
Digging into this a bit more, I see some oddities in the output:
cd("hex\tpage\tpos\ttype")
I found the issue. luamin does not handle nested block comments. For example adding the following:
--[[
will
--[[
this
--]]
break
--[[
everything
--]]
????
--]]
Will output:
break
? ? ? ?
It appears to not be counting the blocks, and just ending the comment block the moment it hits a --]]
This appears to be an inconsistency between PICO-8 and Lua. Lua will terminate the block comment at the first --]]
, similar to C's /* ... /* ... */
.
Naturally picotool should match PICO-8, just noting this for myself as I had hoped I could keep the PICO-8 and vanilla Lua features separate in the code. :/
Looks like I noticed this way back in #18 so I'll resolve this as a dupe. I'll try to get to it soon.