stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 22 Sep 2012 06:56 PM |
http://wiki.roblox.com/index.php/User:XLEGOx/luaminify
It's able to minify itself correctly, and its implementation is large enough that I think I've hit almost all of Lua's syntax, so it should be pretty much correct currently.
Try it out and see if it works correctly on your code, let me know if it fails and put up a copy of the problematic code.
Current features: -Strips comments -Collapses whitespace -Renames all local variables
Future features: -Basic static analysis: checking for variable shadowing, and misspellings of local vars -Variable lifting: Movement of all local definitions to the start of scopes where possible. -Constant lifting: Movement of common strings and constants to shared locals at the start of the code. |
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 22 Sep 2012 06:57 PM |
| How long have you been working on that, ahah? |
|
|
| Report Abuse |
|
|
|
| 22 Sep 2012 07:07 PM |
Very nice, and I'm sure it'd be very useful to obfuscate code.
However, I don't get the point of minifying in this case, unless it's to obfuscate. Why would you need your scripts to be smaller?
If it was on a website where you have to save bandwidth if possible, I'd understand, but here, what is the point? |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 22 Sep 2012 07:14 PM |
"How long have you been working on that, ahah?"
Spent about 15 hours on it over the last week.
"Why would you need your scripts to be smaller?"
Unofficial libraries that you paste at the start of a script. For those, the smaller the better. You can leave them as one line, but that nukes the horizontal scroll bar in most editors, so It's nice to have them as a minimal square block of code at the start, which this gives you. |
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 22 Sep 2012 07:32 PM |
| If I took the time to figure out how to use it I'd try to minimize the source code, itself. |
|
|
| Report Abuse |
|
|
aboy5643
|
  |
| Joined: 08 Oct 2010 |
| Total Posts: 5458 |
|
|
| 22 Sep 2012 08:06 PM |
| Can you minify the source O_O |
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 22 Sep 2012 08:09 PM |
| ^baasically what i was saying |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 22 Sep 2012 08:12 PM |
| What do you mean? Like I said in the initial post, of course you can, I've even been using itself as the code to test it with. |
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 22 Sep 2012 08:14 PM |
"It's able to minify itself correctly"
x.x ... read through the post then started to play with the code, then posted what I had posted and forgot what your original post included. |
|
|
| Report Abuse |
|
|
XE8
|
  |
| Joined: 02 Aug 2012 |
| Total Posts: 522 |
|
| |
|
Legend26
|
  |
| Joined: 08 Sep 2008 |
| Total Posts: 10586 |
|
|
| 22 Sep 2012 08:26 PM |
| For future features, what about variables that are never used? |
|
|
| Report Abuse |
|
|
|
| 22 Sep 2012 08:39 PM |
vararg functions are messed up. example code: function x(...) return { ... } end is minified into: function x()return{...}end Which, of course, doesn't compile |
|
|
| Report Abuse |
|
|
Anaminus
|
  |
 |
| Joined: 29 Nov 2006 |
| Total Posts: 5945 |
|
|
| 22 Sep 2012 08:39 PM |
- Forgets vararg operator function a(...)end --> function a()end
- Doesn't like long bracket strings a=[[string]] a=[=[string]=]
- Doesn't like hexadecimal numbers a=0xff
- Doesn't like various syntax sugars local function foo()end foo"string" foo{}
- Makes assumptions on ambiguous syntax a=f (function()end)() --> a=f(function()end)()
- Doesn't detect `(a)=1` as bad syntax |
|
|
| Report Abuse |
|
|
aboy5643
|
  |
| Joined: 08 Oct 2010 |
| Total Posts: 5458 |
|
|
| 22 Sep 2012 08:54 PM |
| Ouch... The major ones need to be fixed before I use this... The syntactically sugary things aren't too high on my priority list for using it :) |
|
|
| Report Abuse |
|
|
sirsavary
|
  |
| Joined: 27 May 2008 |
| Total Posts: 1222 |
|
|
| 22 Sep 2012 09:09 PM |
Looks great, just needs those bugs fixed.
Also, @Anaminus, thanks for all of the plugins that you've made. Huge help to me and my RPG. Also, you gave me a bit of inspiration when I first left Roblox. Thanks a lot :) |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 22 Sep 2012 10:17 PM |
Updated the wiki version.
"- Forgets vararg operator function a(...)end --> function a()end"
Forgot to to test it with only the varargs. It added varargs at the end of the arg list... but if there was no arg list they weren't added. FIXED
"- Doesn't like long bracket strings a=[[string]] a=[=[string]=]"
Forgot that bit. FIXED
"- Doesn't like hexadecimal numbers a=0xff"
Copied the Lua 5.2 source number parser to be sure I have it right this time. FIXED
"- Doesn't like various syntax sugars local function foo()end foo"string" foo{}"
Same thing as ..., it did parse them... but arbitrarily wouldn't accept them as statements on their own, just needed to allow those as statements as well as the normal call. FIXED
"- Makes assumptions on ambiguous syntax a=f (function()end)() --> a=f(function()end)()"
I didn't handle this because It's not really the job of the minifier to check the syntax. (And it's quite a bit harder to check this than the other things, there's no obvious way to do it other than doing some non-trivial checking of the AST. I'll have to look into how the actual Lua parser recognizes it)
"- Doesn't detect `(a)=1` as bad syntax"
Again, not really the job of the minifier to check syntax, but anyhow, FIXED |
|
|
| Report Abuse |
|
|
sirsavary
|
  |
| Joined: 27 May 2008 |
| Total Posts: 1222 |
|
|
| 22 Sep 2012 10:40 PM |
I'm getting the following error:
C:\Users\****\Documents\Roblox\Minify.lua:1558: attempt to get length of global 'arg' (a nil value) Script "C:\Users\****\Documents\Roblox\Minify.lua", Line 1558 stack end
Script is being run from Tools > Execute Script
Join the Tamerac RPG Beta Club for exclusive updates! |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 22 Sep 2012 10:41 PM |
| You run it as a command line utility, not in Roblox. I could make a Roblox plugin too. |
|
|
| Report Abuse |
|
|
sirsavary
|
  |
| Joined: 27 May 2008 |
| Total Posts: 1222 |
|
|
| 22 Sep 2012 10:42 PM |
Plugin would be nice, when you say command line do you mean from an actual command prompt, or the command bar withing Roblox?
Join the Tamerac RPG Beta Club for exclusive updates! http://www.roblox.com/Groups/group.aspx?gid=701790 |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 22 Sep 2012 10:53 PM |
"Plugin would be nice, when you say command line do you mean from an actual command prompt, or the command bar withing Roblox?"
The actual command line, unless you've got a way to execute normal Lua code with file-io and what not from in Roblox.
This is intended to be a tool for any arbitrary Lua code, not Roblox specific, at least this version is (I'll be adding Roblox specific static analysis later). |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 23 Sep 2012 12:58 AM |
Added a plugin, which you can find with instructions at: https://github.com/stravant/LuaMinify
You select the script to minify, and then hit the plugin's button to minify it. Depending on whether you have the "overwrite" button toggled on or not, it will either put a copy of the old script into the new minified one disabled, or just replace the old one outright. |
|
|
| Report Abuse |
|
|
|
| 23 Sep 2012 01:07 AM |
Wouldn't it be better to create a new disabled script that contains the minified code, or to print it in the output? I don't really like the idea of putting it in the actual script in a comment.
Also, this is what I foresee:
People will minify a script without realizing that the overwrite button is on and will then be angry because they'll have lost their original code.
What about you make it work with the ChangeHistoryService so we can undo? The staff did do it with the terrain plugins, after all... |
|
|
| Report Abuse |
|
|
|
| 23 Sep 2012 01:41 AM |
I tried to minify my scripting engine and the output started yelling at me...
Minify Plugin: >> :17:25: `do` expected. >> ` for _, child in next, player:GetChildren() do` ^--- Script "/Users/Mark Otaris/Documents/Roblox/plugins/RobloxPlugin/Mi", Line 53 stack end Disconnected event because of exception |
|
|
| Report Abuse |
|
|
|
| 23 Sep 2012 01:45 AM |
| I also looked at the new version of your constraint solver (you put it on the wiki some days ago). It seems to work with terrain perfectly well and I seem to be able to click in the sky or on terrain without it breaking. Pretty nice, but it broke and the output told me that the mover is already moving... :P |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 23 Sep 2012 12:30 PM |
"Wouldn't it be better to create a new disabled script that contains the minified code"
That's basically what I do right now, although I put the minified code in the selected script, and keep a copy of the original as a disabled child script of the selected script. Note that, for nicety I also have it so that if you try to minify an already minified script, it will assume that the unminified code that it should minify is in the child script. So that you can select a script and hit minify as many times as you want and it will not keep creating new scripts. It also lets you easily maintain a minified copy and an unminified copy while working on the level.
"People will minify a script without realizing that the overwrite button is on and will then be angry because they'll have lost their original code."
That's why it's off by default. If you turn on a setting without knowing what it does you're usually going to get burned eventually. I need to have it there, because for actual usage by people that want to protect their code, they're going to be using it a lot where they "use it on a place before publishing the release version", where they exactly don't want any copies of the originals left.
"What about you make it work with the ChangeHistoryService so we can undo?" FIXED
"`for _, child in next, player:GetChildren() do`" FIXED
Pushed the changes to git. |
|
|
| Report Abuse |
|
|