Optimizing Lua string literals to save 400 bytes
a day ago
- #Compression
- #Lua
- #ComputerCraft
- The authors face disk space limitations in ComputerCraft: Tweaked, where programs written in Lua exceed the 125KB floppy limit, with their repository's code exceeding 440KB.
- They use compression to create self-decompressing archives for easy installation, merging data with a decompressor into a single file.
- Serializing Lua data as literals is challenging, especially for tables and strings, with various representation nuances.
- String serialization involves handling quoted strings with escapes and raw strings delimited by brackets, which ignore backslashes but require managing newline sequences and escape characters.
- To handle raw strings containing all byte sequences, including CR, they employ a substitution technique using 'gsub' with an escape character and bitwise encoding to minimize size overhead.