summaryrefslogtreecommitdiff
path: root/src/3rdParty/luaminify.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdParty/luaminify.lua')
-rw-r--r--src/3rdParty/luaminify.lua35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/3rdParty/luaminify.lua b/src/3rdParty/luaminify.lua
index d4389d7..3e7cca0 100644
--- a/src/3rdParty/luaminify.lua
+++ b/src/3rdParty/luaminify.lua
@@ -22,7 +22,7 @@ local function lookupify(tb)
22 return tb 22 return tb
23end 23end
24 24
25 25--[[
26local function CountTable(tb) 26local function CountTable(tb)
27 local c = 0 27 local c = 0
28 for _ in pairs(tb) do c = c + 1 end 28 for _ in pairs(tb) do c = c + 1 end
@@ -71,7 +71,7 @@ local function PrintTable(tb, atIndent)
71 out = out..(useNewlines and string.rep(' ', atIndent) or '').."}" 71 out = out..(useNewlines and string.rep(' ', atIndent) or '').."}"
72 return out 72 return out
73end 73end
74 74]]
75 75
76local blacklist = { 76local blacklist = {
77 ["do"] = true, 77 ["do"] = true,
@@ -163,7 +163,7 @@ local Scope = {
163 end, 163 end,
164 164
165 GetLocal = function(self, name) 165 GetLocal = function(self, name)
166 for k, var in pairs(self.Locals) do 166 for _k, var in pairs(self.Locals) do
167 if var.Name == name then return var end 167 if var.Name == name then return var end
168 end 168 end
169 169
@@ -237,7 +237,7 @@ local Scope = {
237 237
238 GetAllVariables = function(self) 238 GetAllVariables = function(self)
239 local ret = self:getVars(true) -- down 239 local ret = self:getVars(true) -- down
240 for k, v in pairs(self:getVars(false)) do -- up 240 for _k, v in pairs(self:getVars(false)) do -- up
241 table.insert(ret, v) 241 table.insert(ret, v)
242 end 242 end
243 return ret 243 return ret
@@ -246,20 +246,20 @@ local Scope = {
246 getVars = function(self, top) 246 getVars = function(self, top)
247 local ret = { } 247 local ret = { }
248 if top then 248 if top then
249 for k, v in pairs(self.Children) do 249 for _k, v in pairs(self.Children) do
250 for k2, v2 in pairs(v:getVars(true)) do 250 for _k2, v2 in pairs(v:getVars(true)) do
251 table.insert(ret, v2) 251 table.insert(ret, v2)
252 end 252 end
253 end 253 end
254 else 254 else
255 for k, v in pairs(self.Locals) do 255 for _k, v in pairs(self.Locals) do
256 table.insert(ret, v) 256 table.insert(ret, v)
257 end 257 end
258 for k, v in pairs(self.Globals) do 258 for _k, v in pairs(self.Globals) do
259 table.insert(ret, v) 259 table.insert(ret, v)
260 end 260 end
261 if self.Parent then 261 if self.Parent then
262 for k, v in pairs(self.Parent:getVars(false)) do 262 for _k, v in pairs(self.Parent:getVars(false)) do
263 table.insert(ret, v) 263 table.insert(ret, v)
264 end 264 end
265 end 265 end
@@ -282,7 +282,7 @@ local Scope = {
282 end, 282 end,
283 283
284 GetGlobal = function(self, name) 284 GetGlobal = function(self, name)
285 for k, v in pairs(self.Globals) do 285 for _k, v in pairs(self.Globals) do
286 if v.Name == name then return v end 286 if v.Name == name then return v end
287 end 287 end
288 288
@@ -295,8 +295,8 @@ local Scope = {
295 return self:GetLocal(name) or self:GetGlobal(name) 295 return self:GetLocal(name) or self:GetGlobal(name)
296 end, 296 end,
297 297
298 ObfuscateLocals = function(self, recommendedMaxLength, validNameChars) 298 ObfuscateLocals = function(self)
299 for i, var in pairs(self.Locals) do 299 for _i, var in pairs(self.Locals) do
300 if var.Name == "_ENV" then 300 if var.Name == "_ENV" then
301 self:RenameLocal(var.Name, "_ENV") 301 self:RenameLocal(var.Name, "_ENV")
302 else 302 else
@@ -796,7 +796,8 @@ local function ParseLua(src)
796 --find the line 796 --find the line
797 local lineNum = 0 797 local lineNum = 0
798 if type(src) == 'string' then 798 if type(src) == 'string' then
799 for line in src:gmatch("[^\n]*\n?") do 799 for l in src:gmatch("[^\n]*\n?") do
800 line = l
800 if line:sub(-1,-1) == '\n' then line = line:sub(1,-2) end 801 if line:sub(-1,-1) == '\n' then line = line:sub(1,-2) end
801 lineNum = lineNum+1 802 lineNum = lineNum+1
802 if lineNum == tok:Peek().Line then 803 if lineNum == tok:Peek().Line then
@@ -951,7 +952,7 @@ local function ParseLua(src)
951 return true, nodeFunc 952 return true, nodeFunc
952 end 953 end
953 954
954 function ParsePrimaryExpr(scope) 955 ParsePrimaryExpr = function(scope)
955 local tokenList = {} 956 local tokenList = {}
956 957
957 if tok:ConsumeSymbol('(', tokenList) then 958 if tok:ConsumeSymbol('(', tokenList) then
@@ -998,7 +999,7 @@ local function ParseLua(src)
998 end 999 end
999 end 1000 end
1000 1001
1001 function ParseSuffixedExpr(scope, onlyDotColon) 1002 ParseSuffixedExpr = function(scope, onlyDotColon)
1002 --base primary expression 1003 --base primary expression
1003 local st, prim = ParsePrimaryExpr(scope) 1004 local st, prim = ParsePrimaryExpr(scope)
1004 if not st then return false, prim end 1005 if not st then return false, prim end
@@ -1089,7 +1090,7 @@ local function ParseLua(src)
1089 end 1090 end
1090 1091
1091 1092
1092 function ParseSimpleExpr(scope) 1093 ParseSimpleExpr = function(scope)
1093 local tokenList = {} 1094 local tokenList = {}
1094 1095
1095 if tok:Is('Number') then 1096 if tok:Is('Number') then
@@ -1243,7 +1244,7 @@ local function ParseLua(src)
1243 ['and'] = {2,2}; 1244 ['and'] = {2,2};
1244 ['or'] = {1,1}; 1245 ['or'] = {1,1};
1245 } 1246 }
1246 function ParseSubExpr(scope, level) 1247 ParseSubExpr = function(scope, level)
1247 --base item, possibly with unop prefix 1248 --base item, possibly with unop prefix
1248 local st, exp 1249 local st, exp
1249 if unops[tok:Peek().Data] then 1250 if unops[tok:Peek().Data] then