diff options
Diffstat (limited to 'tex/context/modules/mkxl/m-json.mkxl')
-rw-r--r-- | tex/context/modules/mkxl/m-json.mkxl | 86 |
1 files changed, 15 insertions, 71 deletions
diff --git a/tex/context/modules/mkxl/m-json.mkxl b/tex/context/modules/mkxl/m-json.mkxl index 061a15ba0..b08286b08 100644 --- a/tex/context/modules/mkxl/m-json.mkxl +++ b/tex/context/modules/mkxl/m-json.mkxl @@ -11,102 +11,46 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -%D This module is a side effect of looking into json. Currently there are -%D only a few helpers: -%D -%D \starttyping -%D moduledata.json.tolua (str) -%D moduledata.json.tostring(val) -%D \stoptyping -%D -%D Nothing spectacular but maybe handy to have around. - \startmodule [json] -% check for: utilities.json - \registerctxluafile{util-jsn}{} +\registerctxluafile{util-tbs}{} % \def\u#1#2#3#4{\cldcontext{utf.char(0x#1#2#3#4)}} \startluacode - -- when we are at the lua end we can just use the table directly but - -- otherwise we can use accessors at the tex end and if needed some - -- special formatters - -- - -- we can actually map the json to xml and then use xml accessors - -- which has some benefits - - local tonumber = tonumber - local context = context - local gmatch = string.gmatch - - local loaded = { } - local current = nil - local json = utilities.json - - local function loadjsonfile(namespace,filename) - local data = loaded[namespace] - if not data then - local fullname = resolvers.findfile(filename) - if fullname and fullname ~= "" then - data = io.loaddata(fullname) - if data then - data = utilities.json.tolua(data) - end - end - if not data then - data = { } - end - loaded[namespace] = data - metapost.setparameterset(namespace,data) - end - current = data - return data - end - - local function jsonfield(namespace,name,default) - local data = loaded[namespace] or current - if current then - for s in gmatch(name,"[^%.]+") do - data = data[s] or data[tonumber(s) or 0] - if not data then - return - end - end - return data - end - end - - json.field = jsonfield - - function json.loaded(namespace) - return (namespace and loaded[namespace]) or current or { } - end + local tablestore = utilities.tablestore interfaces.implement { - name = "loadjsonfile", - actions = loadjsonfile, + name = "loadtable", + actions = tablestore.load, arguments = { "optional", "optional" }, public = true, protected = true, } interfaces.implement { - name = "jsonfield", - actions = { jsonfield, context }, + name = "tablefield", + actions = { tablestore.field, context }, arguments = "2 arguments", public = true, } interfaces.implement { - name = "jsonfielddefault", - actions = { jsonfield, context }, + name = "tablefielddefault", + actions = { tablestore.field, context }, arguments = "3 arguments", public = true, } + utilities.json.field = tablestore.field + utilities.json.loaded = tablestore.loaded + \stopluacode +\let\loadjsonfile \loadtable +\let\jsonfield \tablefield +\let\jsonfielddefault \tablefielddefault + \stopmodule |