Skip to content

Commit

Permalink
Minor changes to plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
stravant committed Sep 23, 2012
1 parent cb64ffe commit 1b9ef93
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions FormatMini.lua
Expand Up @@ -117,6 +117,7 @@ function Format_Mini(ast)
out = out..formatExpr(expr.Base)..expr.Indexer..expr.Ident.Data

elseif expr.AstType == 'Function' then
expr.Scope:RenameVars()
out = out.."function("
if #expr.Arguments > 0 then
for i = 1, #expr.Arguments do
Expand Down
12 changes: 6 additions & 6 deletions ParseLua.lua
Expand Up @@ -412,8 +412,8 @@ function ParseLua(src)
local scope = {}
scope.Parent = parent
scope.LocalList = {}
scope.LocalMap = {}
function scope:RenameVars()
local newList = {}
for _, var in pairs(scope.LocalList) do
local id;
VarUid = 0
Expand All @@ -426,15 +426,14 @@ function ParseLua(src)
varToUse = (varToUse - d) / #VarDigits
id = id..VarDigits[d+1]
end
until not GlobalVarGetMap[id] and not parent:GetLocal(id) and not newList[id]
until not GlobalVarGetMap[id] and not parent:GetLocal(id) and not scope.LocalMap[id]
var.Name = id
newList[id] = var
scope.LocalMap[id] = var
end
scope.LocalList = newList
end
function scope:GetLocal(name)
--first, try to get my variable
local my = scope.LocalList[name]
local my = scope.LocalMap[name]
if my then return my end

--next, try parent
Expand All @@ -452,7 +451,8 @@ function ParseLua(src)
my.Name = name
my.CanRename = true
--
scope.LocalList[name] = my
scope.LocalList[#scope.LocalList+1] = my
scope.LocalMap[name] = my
--
return my
end
Expand Down
Empty file removed RobloxMinifyPlugin.lua
Empty file.
20 changes: 14 additions & 6 deletions RobloxPlugin/Minify.lua
@@ -1,4 +1,11 @@

--
-- Minify.lua
--
-- A compilation of all of the neccesary code to Minify a source file, all into one single
-- script for usage on Roblox. Needed to deal with Roblox' lack of `require`.
--

function lookupify(tb)
for _, v in pairs(tb) do
tb[v] = true
Expand Down Expand Up @@ -455,8 +462,8 @@ function ParseLua(src)
local scope = {}
scope.Parent = parent
scope.LocalList = {}
scope.LocalMap = {}
function scope:RenameVars()
local newList = {}
for _, var in pairs(scope.LocalList) do
local id;
VarUid = 0
Expand All @@ -469,15 +476,14 @@ function ParseLua(src)
varToUse = (varToUse - d) / #VarDigits
id = id..VarDigits[d+1]
end
until not GlobalVarGetMap[id] and not parent:GetLocal(id) and not newList[id]
until not GlobalVarGetMap[id] and not parent:GetLocal(id) and not scope.LocalMap[id]
var.Name = id
newList[id] = var
scope.LocalMap[id] = var
end
scope.LocalList = newList
end
function scope:GetLocal(name)
--first, try to get my variable
local my = scope.LocalList[name]
local my = scope.LocalMap[name]
if my then return my end

--next, try parent
Expand All @@ -495,7 +501,8 @@ function ParseLua(src)
my.Name = name
my.CanRename = true
--
scope.LocalList[name] = my
scope.LocalList[#scope.LocalList+1] = my
scope.LocalMap[name] = my
--
return my
end
Expand Down Expand Up @@ -1344,6 +1351,7 @@ function Format_Mini(ast)
out = out..formatExpr(expr.Base)..expr.Indexer..expr.Ident.Data

elseif expr.AstType == 'Function' then
expr.Scope:RenameVars()
out = out.."function("
if #expr.Arguments > 0 then
for i = 1, #expr.Arguments do
Expand Down
7 changes: 7 additions & 0 deletions RobloxPlugin/MinifyToolbar.lua
@@ -1,4 +1,11 @@

--
-- MinifyToolbar.lua
--
-- The main script that generates a toolbar for studio that allows minification of selected
-- scripts, calling on the _G.Minify function defined in `Minify.lua`
--

local plugin = PluginManager():CreatePlugin()
local toolbar = plugin:CreateToolbar("Minify")
local minifyButton = toolbar:CreateButton("", "Minify Selected Script", 'MinifyButtonIcon.png')
Expand Down

0 comments on commit 1b9ef93

Please sign in to comment.