diff options
author | Marius <mariausol@gmail.com> | 2010-08-14 15:56:20 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2010-08-14 15:56:20 +0300 |
commit | b469b8ec1b494ab72cd462bfc539ce01440e6aaf (patch) | |
tree | 3a9c3fb8433c5f75020fef1d531bedb7c948f66c /tex/context/base/l-io.lua | |
parent | 39e30629c15ae4a899532d84c4abea127f2847a6 (diff) | |
download | context-b469b8ec1b494ab72cd462bfc539ce01440e6aaf.tar.gz |
beta 2010.08.10 17:14
Diffstat (limited to 'tex/context/base/l-io.lua')
-rw-r--r-- | tex/context/base/l-io.lua | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tex/context/base/l-io.lua b/tex/context/base/l-io.lua index 66e279309..89227a63f 100644 --- a/tex/context/base/l-io.lua +++ b/tex/context/base/l-io.lua @@ -185,3 +185,36 @@ function io.ask(question,default,options) end end end + +function io.readnumber(f,n,m) + if m then + f:seek("set",n) + n = m + end + if n == 1 then + return byte(f:read(1)) + elseif n == 2 then + local a, b = byte(f:read(2),1,2) + return 256*a + b + elseif n == 4 then + local a, b, c, d = byte(f:read(4),1,4) + return 256^3 * a + 256^2 * b + 256*c + d + elseif n == 8 then + local a, b = readnumber(f,4), readnumber(f,4) + return 256 * b + c + elseif n == 12 then + local a, b, c = readnumber(f,4), readnumber(f,4), readnumber(f,4) + return 256^2 * a + 256 * b + c + else + return 0 + end +end + +function io.readstring(f,n,m) + if m then + f:seek("set",n) + n = m + end + local str = gsub(f:read(n),"%z","") + return str +end |