Merged in windirstat/premake-dev/fix_issue_25 (pull request #96)

Compress embedded scripts with LuaSrcDiet
This commit is contained in:
Jason Perkins 2015-03-29 15:48:16 -04:00
commit 4d88c7f7b5
7 changed files with 4827 additions and 22 deletions

View File

@ -24,3 +24,4 @@ Since 5.0-alpha1:
* New API: debugsearchpaths()
* os.outputof() now returns command exit code as second value
* Added AVX2 to vectorextensions()
* Embedded scripts now compressed with LuaSrcDiet (Oliver Schneider)

View File

@ -19,6 +19,8 @@ Patch contributors:
* new API for undefining symbols
Mihai Sebea <http://twitter.com/mihai_sebea>
* Xcode exporter fixes and improvements
Oliver Schneider
* Compress embedded scripts with LuaSrcDiet
Renaud Guillard <https://bitbucket.org/noresources>
* add library search paths argument to os.findlib()
* return command exit code from os.outputof()

View File

@ -5,43 +5,33 @@
-- issues in Mac OS X Universal builds.
--
local raw_sum = 0
local trim_sum = 0
local function loadScript(fname)
dofile("scripts/luasrcdiet/LuaSrcDiet.lua")
-- Let LuaSrcDiet do its job
fname = path.getabsolute(fname)
local f = io.open(fname)
local s = assert(f:read("*a"))
f:close()
-- strip tabs
s = s:gsub("[\t]", "")
local s,l = get_slim_luasrc(fname)
-- Now do some cleanup so we can write these out as C strings
-- strip any CRs
s = s:gsub("[\r]", "")
-- strip out block comments
s = s:gsub("[^\"']%-%-%[%[.-%]%]", "")
s = s:gsub("[^\"']%-%-%[=%[.-%]=%]", "")
s = s:gsub("[^\"']%-%-%[==%[.-%]==%]", "")
-- strip out inline comments
s = s:gsub("\n%-%-[^\n]*", "\n")
-- escape backslashes
s = s:gsub("\\", "\\\\")
-- strip duplicate line feeds
s = s:gsub("\n+", "\n")
-- strip out leading comments
s = s:gsub("^%-%-[^\n]*\n", "")
-- escape line feeds
s = s:gsub("\n", "\\n")
-- escape double quote marks
s = s:gsub("\"", "\\\"")
return s
-- overall counters
raw_sum = raw_sum + l:len()
trim_sum = trim_sum + s:len()
return s
end
@ -157,7 +147,7 @@
end
if oldVersion ~= result then
print("Writing scripts.c")
printf("Writing scripts.c (compressed %2.1f%%)", (trim_sum / raw_sum) * 100)
file = io.open(scriptsFile, "w+b")
file:write(result)
file:close()

View File

@ -0,0 +1,45 @@
LuaSrcDiet License
------------------
LuaSrcDiet is licensed under the terms of the MIT license reproduced
below. This means that LuaSrcDiet is free software and can be used for
both academic and commercial purposes at absolutely no cost.
Think of LuaSrcDiet as a compiler or a text filter; whatever that is
processed by LuaSrcDiet is not affected by its license. It does not add
anything new into your source code; it only transforms code that already
exist.
Hence, there is no need to tag this license onto Lua programs that are
only processed. Given the liberal terms of this kind of license, the
primary purpose is just to claim authorship of LuaSrcDiet.
Parts of LuaSrcDiet is based on Lua 5 code. See the file COPYRIGHT_Lua51
(Lua 5.1.4) for Lua 5's license.
===============================================================================
Copyright (C) 2005-2008,2011 Kein-Hong Man <keinhong@gmail.com>
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
===============================================================================
(end of COPYRIGHT)

File diff suppressed because it is too large Load Diff

140
scripts/luasrcdiet/README Normal file
View File

@ -0,0 +1,140 @@
LuaSrcDiet
Compresses Lua source code by removing unnecessary characters.
Copyright (c) 2005-2008,2011,2012 Kein-Hong Man <keinhong@gmail.com>
The COPYRIGHT file describes the conditions
under which this software may be distributed.
http://code.google.com/p/luasrcdiet/
========================================================================
WHAT'S NEW IN VERSION 0.12.1
----------------------------
* Fixed a long comment glitch when using the --keep option. (Two
extra characters were duplicated before the ending brackets.)
* Faster function call syntax sugar optimization using a one-pass
token deletion loop.
WHAT'S NEW IN VERSION 0.12.0
----------------------------
* Added single-file versions of LuaSrcDiet in various sizes. First
done by some other projects that packaged LuaSrcDiet, e.g. eLua.
* BUG FIX: String optimization of "\ddd" type escape mechanism,
"\00101" was incorrectly optimized to "\101".
* --opt-srcequiv: Source equivalence checking. Tries hard to compare
'before' and 'after' lexer token streams for equivalence.
* --opt-binequiv: Binary chunk equivalence checking. Tries hard to
compare 'before' and 'after' binary chunks for equivalence.
* When using --opt-eols, the last EOL character is now removed.
* --opt-experimental: Turns on a few experimental optimizations:
(a) ';' operator removal (deleted or turned into whitespace).
(b) f("string") f('string') f([[string]]) calls are turned
into their syntactic sugar equivalents, e.g. f"string"
* Plugins are now embedded into single-file versions.
* First release of completed documentation files.
* New Makefile and numerous minor updates.
* Old code for Lua 5.0 removed.
BUGS
----
* Nothing in my list. See below for limitations...
INCOMPLETE SUPPORT
------------------
* Locals optimization does NOT understand implicit 'arg' locals in
vararg functions (see option LUA_COMPAT_VARARG in the Lua sources).
* NO support in lexer for decimal points other than '.'.
* NO support in lexer for Lua 5.0.x nested long strings.
EXPERIMENTAL SOFTWARE
---------------------
LuaSrcDiet is "experimental software". For LuaSrcDiet, this means that
it was coded for one user -- the coder. Although I may be able to help
LuaSrcDiet users, there should not be any expectation of 'support'.
Don't hook this thing up to nuclear missiles.
I don't have the time for steady maintenance or for building up and
cultivating a user base, so developers are welcome to fork LuaSrcDiet or
incorporate it into their own software, as long as authorship
attribution for LuaSrcDiet source code is maintained. Say if LuaSrcDiet
is called as a separate program, then it is simply an aggregation of
separate software and each program should stick to its own license.
Programs you process using LuaSrcDiet are of course not affected at all
by LuaSrcDiet's license; it's just a text filter. See COPYRIGHT. If you
insist on extreme COPYRIGHT views, then better delete this whole thing
right away, then gouge your eyes out. :-p
OLDER STUFF
-----------
There has been some slash-and-burn going on. I'm inclined to move
forward, and not spend time maintaining older stuff forever. If you
still need the older stuff, they can be found in:
* Lua 5.0.x old versions: last seen in version 0.11.2.
* Lua 5.1.x old codebase: last seen in version 0.11.2.
FUTURE PLANS
------------
Lua 5.1.x releases for LuaSrcDiet will pretty much stagnate at 0.12.1
after implementation of a couple more experimental optimizations, and
effort will be shifted towards something for Lua 5.2.x. The timeline for
this is indeterminate.
========================================================================
USING LUASRCDIET
Now is a good time to take a look at the documentation. Start with
LuaSrcDiet.html in the doc directory.
LuaSrcDiet is now packaged as a single-file Lua script for maximum
convenience. Just drop it in and splice something into your Makefile.
New source stream and binary chunk equivalence checking minimizes the
possibility of LuaSrcDiet borking your stuff.
========================================================================
ACKNOWLEDGEMENTS
Coded using SciTE. Developed mostly under Cygwin with a generic Lua
5.1.4 binary.
========================================================================
FEEDBACK
Feedback and contributions are welcome. Your name will be acknowledged,
as long as you are willing to comply with COPYRIGHT. If your material is
self-contained, you can retain a copyright notice for those material in
your own name, as long as you use the same Lua 5/MIT-style copyright.
Enjoy!
Kein-Hong Man (esq.)
Kuala Lumpur
Malaysia 20120407

View File

@ -0,0 +1,12 @@
This is a patched up version of LuaSrcDiet 0.12.1.
The following changes were implemented:
* added local variables 'loaded_file_contents' and 'saved_file_contents'.
* overriding load_file() to store the loaded file contents in above mentioned
variable.
* overriding save_file() to store trimmed down source in above mentioned
variable.
ATTENTION: there are multiple functions of that name!
* commented out the "main functions" (search for this text).
* added function get_slim_luasrc() to return trimmed down code.