-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************
ScriptName = "MS_LM_Globals"
-- **************************************************
-- General information about this script
-- **************************************************
MS_LM_Globals = {}
function MS_LM_Globals:Name()
return "Print Globals (modified)"
end
function MS_LM_Globals:Version()
return "5.1"
end
function MS_LM_Globals:Description()
return "Print global variables to output file"
end
function MS_LM_Globals:Creator()
return "Lost Marble, modifed by Myles Strous"
end
function MS_LM_Globals:UILabel()
return("Print Globals (modified)")
end
-- **************************************************
-- The guts of this script
-- **************************************************
function MS_LM_Globals:Run(moho)
local outfilename = LM.GUI.SaveFile("Select Output Switch Data File")
if (outfilename == "") then
return
end
local outfile = io.open(outfilename, "w")
if (outfile == nil) then
return
end
outfile:write("\n
\n\tMoho Global Variables\n\n")
outfile:write("Moho Global Variables
\n")
self:PrintTableValues(_G, outfile)
outfile:write("\n")
outfile:close()
end
--function MS_LM_Globals:PrintTableValues(t, outfile)
-- for n, v in t do
-- outfile:write(""..tostring(n).." "..tostring(v).." "..type(v).."
\n")
-- end
--end
function pairsByKeys (t, f)
local a = {}
for n in pairs(t) do table.insert(a, n) end
table.sort(a, f)
local i = 0 -- iterator variable
local iter = function () -- iterator function
i = i + 1
if a[i] == nil then return nil
else return a[i], t[a[i]]
end
end
return iter
end
function MS_LM_Globals:PrintTableValues(t, outfile)
outfile:write("\n")
for name, line in pairsByKeys(t) do
if type(line) == "number" then
outfile:write(" - "..name.." "..tostring(line).." "..type(line).."\n")
end
end
outfile:write("
")
for name, line in pairsByKeys(t) do
if type(line) == "table" then
outfile:write(" - "..name.." "..type(line).."\n")
-- self:PrintTableValues2(line, outfile)
end
end
outfile:write("
")
for name, line in pairsByKeys(t) do
if type(line) == "function" then
outfile:write(" - "..name.." "..type(line).."\n")
end
end
outfile:write("
\n")
end