summaryrefslogtreecommitdiffstatshomepage
path: root/plugins
diff options
context:
space:
mode:
author cracyc <cracyc@users.noreply.github.com>2018-04-21 08:52:15 -0500
committer cracyc <cracyc@users.noreply.github.com>2018-04-21 08:52:15 -0500
commit0c0e38ca58d07ada747ee0171eb27d50cb9e2a56 (patch)
tree84c06ccb4097ce14c4fd0163bfbdab0b671f2cc3 /plugins
parent966b8599beaab22da95c398fc6d5013276acb1d8 (diff)
plugins/portname: sort the output file (nw)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/portname/init.lua11
1 files changed, 10 insertions, 1 deletions
diff --git a/plugins/portname/init.lua b/plugins/portname/init.lua
index 594878f77b0..b6403d2cbb4 100644
--- a/plugins/portname/init.lua
+++ b/plugins/portname/init.lua
@@ -72,15 +72,23 @@ function portname.startplugin()
local ports = {}
for pname, port in pairs(manager:machine():ioport().ports) do
local labels = {}
- ports[pname] = { labels = labels }
+ local sort = {}
for fname, field in pairs(port.fields) do
local mask = tostring(field.mask)
if not labels[mask] then
+ sort[#sort + 1] = mask
labels[mask] = { name = fname, player = field.player }
setmetatable(labels[mask], { __tojson = function(v,s)
+ local label = { name = v.name, player = v.player }
+ setmetatable(label, { __jsonorder = { "player", "name" }})
return json.stringify({ name = v.name, player = v.player }) end })
end
end
+ if #sort > 0 then
+ table.sort(sort, function(i, j) return tonumber(i) < tonumber(j) end)
+ setmetatable(labels, { __jsonorder = sort })
+ ports[pname] = { labels = labels }
+ end
end
local function check_path(path)
local attr = lfs.attributes(path)
@@ -117,6 +125,7 @@ function portname.startplugin()
if emu.softname() ~= "" then
ctable.softname = emu.softname()
end
+ setmetatable(ctable, { __jsonorder = { "romname", "softname", "ports" }})
file:write(json.stringify(ctable, { indent = true }))
file:close()
manager:machine():popmessage(string.format(_("Input port name file saved to %s"), ctrlrpath .. "/portname/" .. filename))