summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/util-sac.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/util-sac.lua')
-rw-r--r--tex/context/base/mkiv/util-sac.lua57
1 files changed, 57 insertions, 0 deletions
diff --git a/tex/context/base/mkiv/util-sac.lua b/tex/context/base/mkiv/util-sac.lua
index 976989a77..19dc0eb0f 100644
--- a/tex/context/base/mkiv/util-sac.lua
+++ b/tex/context/base/mkiv/util-sac.lua
@@ -43,6 +43,8 @@ function streams.size(f)
return f and f[3] or 0
end
+streams.getsize = streams.size
+
function streams.setposition(f,i)
if f[4] then
-- zerobased
@@ -485,3 +487,58 @@ else
end
end
+
+-- For practical reasons we put this here. It's less efficient but ok when we don't
+-- have much access.
+
+do
+
+ local files = utilities.files
+
+ if files then
+
+ local openfile = files.open
+ local openstream = streams.open
+ local openstring = streams.openstring
+
+ local setmetatable = setmetatable
+
+ function io.newreader(str,method)
+ local f, m
+ if method == "string" then
+ f = openstring(str)
+ m = streams
+ elseif method == "stream" then
+ f = openstream(str)
+ m = streams
+ else
+ f = openfile(str,"rb")
+ m = files
+ end
+ if f then
+ local t = { }
+ setmetatable(t, {
+ __index = function(t,k)
+ local r = m[k]
+ if k == "close" then
+ if f then
+ m.close(f)
+ f = nil
+ end
+ return function() end
+ elseif r then
+ local v = function(_,a,b) return r(f,a,b) end
+ t[k] = v
+ return v
+ else
+ print("unknown key",k)
+ end
+ end
+ } )
+ return t
+ end
+ end
+
+ end
+
+end