summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/util-fil.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2018-03-06 15:57:09 +0100
committerContext Git Mirror Bot <phg42.2a@gmail.com>2018-03-06 15:57:09 +0100
commit4ec0856ccdbd5bf6e110467d4623b52566b0e37d (patch)
tree8a7a1c9897870ae2cadcb8a1bee9697819222803 /tex/context/base/mkiv/util-fil.lua
parent2d50de713c23ec150dab395dcbce69b854db2d58 (diff)
downloadcontext-4ec0856ccdbd5bf6e110467d4623b52566b0e37d.tar.gz
2018-03-06 15:07:00
Diffstat (limited to 'tex/context/base/mkiv/util-fil.lua')
-rw-r--r--tex/context/base/mkiv/util-fil.lua57
1 files changed, 39 insertions, 18 deletions
diff --git a/tex/context/base/mkiv/util-fil.lua b/tex/context/base/mkiv/util-fil.lua
index b44dbc3fe..0e8ed4e57 100644
--- a/tex/context/base/mkiv/util-fil.lua
+++ b/tex/context/base/mkiv/util-fil.lua
@@ -6,11 +6,8 @@ if not modules then modules = { } end modules ['util-fil'] = {
license = "see context related readme files"
}
-local byte = string.byte
-local char = string.char
-local extract = bit32.extract
-local rshift = bit32.rshift
-local band = bit32.band
+local byte = string.byte
+local char = string.char
-- Here are a few helpers (the starting point were old ones I used for parsing
-- flac files). In Lua 5.3 we can probably do this better. Some code will move
@@ -239,15 +236,22 @@ end
-- (real) ((n<<16)>>(16+14)) + ((n&0x3fff)/16384.0))
-function files.read2dot14(f)
- local a, b = byte(f:read(2),1,2)
- if a >= 0x80 then
- local n = -(0x100 * a + b)
- return - (extract(n,14,2) + (band(n,0x3FFF) / 16384.0))
- else
- local n = 0x100 * a + b
- return (extract(n,14,2) + (band(n,0x3FFF) / 16384.0))
+if bit32 then
+
+ local extract = bit32.extract
+ local band = bit32.band
+
+ function files.read2dot14(f)
+ local a, b = byte(f:read(2),1,2)
+ if a >= 0x80 then
+ local n = -(0x100 * a + b)
+ return - (extract(n,14,2) + (band(n,0x3FFF) / 16384.0))
+ else
+ local n = 0x100 * a + b
+ return (extract(n,14,2) + (band(n,0x3FFF) / 16384.0))
+ end
end
+
end
function files.skipshort(f,n)
@@ -260,11 +264,28 @@ end
-- writers (kind of slow)
-function files.writecardinal2(f,n)
- local a = char(n % 256)
- n = rshift(n,8)
- local b = char(n % 256)
- f:write(b,a)
+if bit32 then
+
+ local rshift = bit32.rshift
+
+ function files.writecardinal2(f,n)
+ local a = char(n % 256)
+ n = rshift(n,8)
+ local b = char(n % 256)
+ f:write(b,a)
+ end
+
+else
+
+ local floor = math.floor
+
+ function files.writecardinal2(f,n)
+ local a = char(n % 256)
+ n = floor(n/256)
+ local b = char(n % 256)
+ f:write(b,a)
+ end
+
end
function files.writecardinal4(f,n)