diff options
Diffstat (limited to 'tex/context/base/mkiv/lpdf-ini.lua')
-rw-r--r-- | tex/context/base/mkiv/lpdf-ini.lua | 74 |
1 files changed, 63 insertions, 11 deletions
diff --git a/tex/context/base/mkiv/lpdf-ini.lua b/tex/context/base/mkiv/lpdf-ini.lua index e2a85bccf..0d96abb7d 100644 --- a/tex/context/base/mkiv/lpdf-ini.lua +++ b/tex/context/base/mkiv/lpdf-ini.lua @@ -12,6 +12,7 @@ local setmetatable, getmetatable, type, next, tostring, tonumber, rawset = setme local char, byte, format, gsub, concat, match, sub, gmatch = string.char, string.byte, string.format, string.gsub, table.concat, string.match, string.sub, string.gmatch local utfchar, utfbyte, utfvalues = utf.char, utf.byte, utf.values local sind, cosd, floor, max, min = math.sind, math.cosd, math.floor, math.max, math.min +local sort = table.sort local lpegmatch, P, C, R, S, Cc, Cs = lpeg.match, lpeg.P, lpeg.C, lpeg.R, lpeg.S, lpeg.Cc, lpeg.Cs local formatters = string.formatters local isboolean = string.is_boolean @@ -369,34 +370,85 @@ local f_tonumber = formatters["%F"] local tostring_a, tostring_d +-- tostring_d = function(t,contentonly,key) +-- if next(t) then +-- local r, rn = { }, 0 +-- for k, v in next, t do +-- -- for k, v in sortedhash(t) do -- can be an option +-- rn = rn + 1 +-- local tv = type(v) +-- if tv == "string" then +-- r[rn] = f_key_value(k,toeight(v)) +-- elseif tv == "number" then +-- r[rn] = f_key_number(k,v) +-- -- elseif tv == "unicode" then -- can't happen +-- -- r[rn] = f_key_value(k,tosixteen(v)) +-- elseif tv == "table" then +-- local mv = getmetatable(v) +-- if mv and mv.__lpdftype then +-- -- if v == t then +-- -- report_objects("ignoring circular reference in dirctionary") +-- -- r[rn] = f_key_null(k) +-- -- else +-- r[rn] = f_key_value(k,tostring(v)) +-- -- end +-- elseif v[1] then +-- r[rn] = f_key_value(k,tostring_a(v)) +-- else +-- r[rn] = f_key_value(k,tostring_d(v)) +-- end +-- else +-- r[rn] = f_key_value(k,tostring(v)) +-- end +-- end +-- if contentonly then +-- return concat(r," ") +-- elseif key then +-- return f_key_dictionary(key,r) +-- else +-- return f_dictionary(r) +-- end +-- elseif contentonly then +-- return "" +-- else +-- return "<< >>" +-- end +-- end + tostring_d = function(t,contentonly,key) if next(t) then - local r, rn = { }, 0 - for k, v in next, t do - rn = rn + 1 + local r, n = { }, 0 + for k in next, t do + n = n + 1 + r[n] = k + end + sort(r) + for i=1,n do + local k = r[i] + local v = t[k] local tv = type(v) if tv == "string" then - r[rn] = f_key_value(k,toeight(v)) + r[i] = f_key_value(k,toeight(v)) elseif tv == "number" then - r[rn] = f_key_number(k,v) + r[i] = f_key_number(k,v) -- elseif tv == "unicode" then -- can't happen - -- r[rn] = f_key_value(k,tosixteen(v)) + -- r[i] = f_key_value(k,tosixteen(v)) elseif tv == "table" then local mv = getmetatable(v) if mv and mv.__lpdftype then -- if v == t then -- report_objects("ignoring circular reference in dirctionary") - -- r[rn] = f_key_null(k) + -- r[i] = f_key_null(k) -- else - r[rn] = f_key_value(k,tostring(v)) + r[i] = f_key_value(k,tostring(v)) -- end elseif v[1] then - r[rn] = f_key_value(k,tostring_a(v)) + r[i] = f_key_value(k,tostring_a(v)) else - r[rn] = f_key_value(k,tostring_d(v)) + r[i] = f_key_value(k,tostring_d(v)) end else - r[rn] = f_key_value(k,tostring(v)) + r[i] = f_key_value(k,tostring(v)) end end if contentonly then |