Skip to content

Commit 7f8e514

Browse files
committed
sort namedentites alphabetically
1 parent 07142c1 commit 7f8e514

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

data/jsontolua.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@
33
local json = require "dkjson"
44
local data = io.read("*all")
55

6+
local function sorted(json_data)
7+
-- we need to sort entity names alphabetically to get good order each time we run this script (for git)
8+
local t = {}
9+
for k in pairs(json_data) do
10+
table.insert(t, k)
11+
end
12+
table.sort(t)
13+
return t
14+
end
15+
616
local json_data = json.decode(data)
717
print("return {")
8-
for name, rec in pairs(json_data) do
18+
for _, name in ipairs(sorted(json_data)) do
19+
local rec = json_data[name]
920
print(string.format('["%s"]="%s",',name:gsub("[&;]", ""), rec.characters:gsub('\\', '\\\\'):gsub("\n", '\\n'):gsub('"', '\\"')))
1021
end
1122

0 commit comments

Comments
 (0)