LuaSrcDiet



Introduction

LuaSrcDiet is a utility written in Lua for the purpose of turning Lua 5.1 source code like this:

local function calc_indent(s)
  local col = 0
  for i = 1, #s do
    local c = sub(s, i, i)
    col = col + 1
    if c == "\t" then  -- tab
      while col % 8 > 0 do col = col + 1 end
    end
  end--for
  return math.floor(col / 8)
end

into a more compact or 'squeezed' form (minus a lot of unnecessary characters) like this:

local function _(l)local e=0
for o=1,#l do
local n=n(l,o,o)e=e+1
if n=="\t"then
while e%8>0 do e=e+1 end
end
end
return r.floor(e/8)end

and still be able to run normally under standard Lua 5.1.

LuaSrcDiet reduces the size of Lua 5.1.x source files by aggressively removing all unnecessary whitespace and comments, optimizing constant tokens, and renaming local variables to shorter names. For example, LuaSrcDiet squeezes its own sources from 156KB down to 42KB. Further bzip2 or lzma compression can bring the file size further down to under 13KB. That's 12X reduction in size, if you don't mind the decompression and compilation time.

LuaSrcDiet is broadly similar to Luiz's lstrip (tar.gz link) for Lua 5.1, which can be found on Luiz's Libraries and tools for Lua page. LuaSrcDiet with its modified Lua source code lexer and parser allows most optimization options to be enabled or disabled separately, and can do a bit more like renaming local variable names.

There is also Matthew Wild's squish, which incorporates LuaSrcDiet and offers more code compression options. squish goes beyond what LuaSrcDiet does, as the latter (as a matter of policy) only sticks to source code readable by standard Lua binaries.


LuaSrcDiet and Obfuscation

Owing to the use of LuaSrcDiet among certain things like WoW add-ons, the following is a clarification of this author's intentions:


What's New

As of version 0.12.0, LuaSrcDiet has been moved to a new project host site at: http://code.google.com/p/luasrcdiet/

Version 0.12.1 (2012-04-07):
Version 0.12.0 (2011-09-13):
Version 0.11.2 (2008-06-08):
Version 0.11.1 (2008-06-03):
Version 0.11.0 (2008-05-28):
Version 0.10.2 (2008-05-27):
Version 0.10.1 (2008-05-25):

Acknowledgements

LuaSrcDiet was originally hosted on LuaForge. Thanks to the LuaForge team for their contributions to the Lua ecosystem. LuaSrcDiet was developed exclusively using the SciTE editor, on Cygwin, and managed using SVN. Parts of LuaSrcDiet is based on Yueliang, which is in turn based on the Lua sources.


2012-04-07 khman