diff options
author | Marius <mariausol@gmail.com> | 2012-08-09 01:00:13 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2012-08-09 01:00:13 +0300 |
commit | 343077218254bccdd7e518c5cc74d473d0bbf605 (patch) | |
tree | b3b58ac303f7513cb39e1695fb8f29e8fd960519 /tex/context/base/mlib-run.lua | |
parent | e3f2891a6167e2efe5b9cee3b374eec103cbb526 (diff) | |
download | context-343077218254bccdd7e518c5cc74d473d0bbf605.tar.gz |
beta 2012.08.08 23:45
Diffstat (limited to 'tex/context/base/mlib-run.lua')
-rw-r--r-- | tex/context/base/mlib-run.lua | 66 |
1 files changed, 52 insertions, 14 deletions
diff --git a/tex/context/base/mlib-run.lua b/tex/context/base/mlib-run.lua index 813b35399..08ed22e47 100644 --- a/tex/context/base/mlib-run.lua +++ b/tex/context/base/mlib-run.lua @@ -29,29 +29,29 @@ approach is way faster than an external <l n='metapost'/> and processing time nears zero.</p> --ldx]]-- +local format, gsub, match, find = string.format, string.gsub, string.match, string.find +local emptystring = string.is_empty +local lpegmatch, P = lpeg.match, lpeg.P + local trace_graphics = false trackers.register("metapost.graphics", function(v) trace_graphics = v end) local report_metapost = logs.reporter("metapost") - local texerrormessage = logs.texerrormessage -local format, gsub, match, find = string.format, string.gsub, string.match, string.find -local emptystring = string.is_empty - -local starttiming, stoptiming = statistics.starttiming, statistics.stoptiming +local starttiming = statistics.starttiming +local stoptiming = statistics.stoptiming -local mplib = mplib +local mplib = mplib +metapost = metapost or { } +local metapost = metapost -metapost = metapost or { } -local metapost = metapost +local mplibone = tonumber(mplib.version()) <= 1.50 metapost.showlog = false metapost.lastlog = "" metapost.texerrors = false metapost.exectime = metapost.exectime or { } -- hack -local mplibone = tonumber(mplib.version()) <= 1.50 - directives.register("mplib.texerrors", function(v) metapost.texerrors = v end) function metapost.resetlastlog() @@ -68,19 +68,57 @@ end -- end -- end -local function i_finder(name, mode, ftype) -- fake message for mpost.map and metafun.mpvi - name = file.is_qualified_path(name) and name or resolvers.findfile(name,ftype) - if not (find(name,"/metapost/context/base/") or find(name,"/metapost/context/") or find(name,"/metapost/base/")) then +----- mpbasepath = lpeg.instringchecker(lpeg.append { "/metapost/context/", "/metapost/base/" }) +local mpbasepath = lpeg.instringchecker(P("/metapost/") * (P("context") + P("base")) * P("/")) + +-- local function i_finder(askedname,mode,ftype) -- fake message for mpost.map and metafun.mpvi +-- local foundname = file.is_qualified_path(askedname) and askedname or resolvers.findfile(askedname,ftype) +-- if not mpbasepath(foundname) then +-- -- we could use the via file but we don't have a complete io interface yet +-- local data, found, forced = metapost.checktexts(io.loaddata(foundname) or "") +-- if found then +-- local tempname = luatex.registertempfile(foundname,true) +-- io.savedata(tempname,data) +-- foundname = tempname +-- end +-- end +-- return foundname +-- end + +-- mplib has no real io interface so we have a different mechanism than +-- tex (as soon as we have more control, we will use the normal code) + +local finders = { } +mplib.finders = finders + +-- for some reason mp sometimes calls this function twice which is inefficient +-- but we cannot catch this + +local function preprocessed(name) + if not mpbasepath(name) then + -- we could use the via file but we don't have a complete io interface yet local data, found, forced = metapost.checktexts(io.loaddata(name) or "") if found then local temp = luatex.registertempfile(name,true) io.savedata(temp,data) - name = temp + return temp end end return name end +mplib.preprocessed = preprocessed -- helper + +finders.file = function(specification,name,mode,ftype) + return preprocessed(resolvers.findfile(name,ftype)) +end + +local function i_finder(name,mode,ftype) -- fake message for mpost.map and metafun.mpvi + local specification = url.hashed(name) + local finder = finders[specification.scheme] or finders.file + return finder(specification,name,mode,ftype) +end + local function o_finder(name, mode, ftype) return name end |