diff options
author | Hans Hagen <pragma@wxs.nl> | 2020-08-03 14:53:53 +0200 |
---|---|---|
committer | Context Git Mirror Bot <phg@phi-gamma.net> | 2020-08-03 14:53:53 +0200 |
commit | 757aa0290bc1f866475e055fdf8a9c6df1124860 (patch) | |
tree | 3b8bc79a80e33900f3b3f82cd1f4e5e1936f1331 /tex/context/base/mkiv/syst-lua.lmt | |
parent | cbaeded86ee193677fe0cae364b564616557449d (diff) | |
download | context-757aa0290bc1f866475e055fdf8a9c6df1124860.tar.gz |
2020-08-03 14:20:00
Diffstat (limited to 'tex/context/base/mkiv/syst-lua.lmt')
-rw-r--r-- | tex/context/base/mkiv/syst-lua.lmt | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/tex/context/base/mkiv/syst-lua.lmt b/tex/context/base/mkiv/syst-lua.lmt index 018231e30..68f0d1b75 100644 --- a/tex/context/base/mkiv/syst-lua.lmt +++ b/tex/context/base/mkiv/syst-lua.lmt @@ -313,3 +313,102 @@ do } end + +do + + -- This is some 20% slower than native but we only provide this for compatibility + -- reasons so we don't care that much about it. Eventually we can drop the + -- built-in method. + + local channels = { } + + local findbinfile = resolvers.findbinfile + local loadbinfile = resolvers.loadbinfile + local opentexfile = resolvers.opentexfile + + local scaninteger = tokens.scanners.integer + local scankeyword = tokens.scanners.keyword + local scanstring = tokens.scanners.string + local scancsname = tokens.scanners.csname + + local setmacro = tokens.setters.macro + local vrbcatcodes = tex.vrbcatcodes + + interfaces.implement { + name = "openin", + public = true, + protected = true, + actions = function() + local n = scaninteger() + scankeyword("=") + local s = scanstring(true) + local c = channels[n] + if c then + c:close() + end + local f = findbinfile(s,"tex") + if f then + channels[n] = opentexfile(f) + else + channels[n] = false + end + end, + } + + interfaces.implement { + name = "closein", + public = true, + protected = true, + value = "none", + actions = function() + local n = scaninteger() + local c = channels[n] + if c then + c:close() + end + channels[n] = false + end, + } + + interfaces.implement { + name = "read", + public = true, + protected = true, + value = "none", + actions = function(prefix) + local n = scaninteger() + scankeyword("to") + local m = scancsname(true) + local c = channels[n] + local s = c and c:reader() + if not s then + channels[n] = false + s = "\\par" -- or just "", no need to fake tex here + end + setmacro(m, s, prefix) -- checks for frozen + end, + } + + interfaces.implement { + name = "readline", + public = true, + protected = true, + actions = function(prefix) + local n = scaninteger() + scankeyword("to") + local m = scancsname(true) + local c = channels[n] + local s = c and c:reader() + if not s then + channels[n] = false + s = "" + end + setmacro(vrbcatcodes, m, s, prefix) -- checks for frozen + end, + } + + callback.register("end_of_file", function(n) + return not channels[n] + end) + +end |