Skip to content

Commit

Permalink
Update json.lua from pending pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
winniehell committed Oct 21, 2024
1 parent 3462373 commit 2e56476
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/resources/pandoc/datadir/_json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
-- https://github.com/rxi/json.lua
--
-- includes unreleased upstream changes: https://github.com/rxi/json.lua/blob/dbf4b2dd2eb7c23be2773c89eb059dadd6436f94/json.lua
-- includes unmerged upstream pull request: https://github.com/rxi/json.lua/pull/51
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy of
-- this software and associated documentation files (the "Software"), to deal in
Expand All @@ -27,6 +28,21 @@

local json = { _version = "0.1.2-quarto" }

-- taken from https://www.lua.org/pil/19.3.html
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

-------------------------------------------------------------------------------
-- Encode
-------------------------------------------------------------------------------
Expand Down Expand Up @@ -89,7 +105,7 @@ local function encode_table(val, stack)

else
-- Treat as an object
for k, v in pairs(val) do
for k, v in pairsByKeys(val) do
if type(k) ~= "string" then
error("invalid table: mixed or invalid key types")
end
Expand Down Expand Up @@ -388,4 +404,4 @@ function json.decode(str)
end


return json
return json

0 comments on commit 2e56476

Please sign in to comment.