diff options
author | Philipp Gesang <phg@phi-gamma.net> | 2016-07-26 23:48:32 +0200 |
---|---|---|
committer | Philipp Gesang <phg@phi-gamma.net> | 2016-07-26 23:48:32 +0200 |
commit | bc004d99276155c0892b19965c967aeb2de01a1e (patch) | |
tree | 2ecf8522f671619e8cab05e3af48a52cc8fa4315 /src/fontloader/misc/fontloader-util-fil.lua | |
parent | b1ca1874fc12611b98c3155fe3d197bdaf77c273 (diff) | |
download | luaotfload-bc004d99276155c0892b19965c967aeb2de01a1e.tar.gz |
[fontloader] sync with Context as of 2016-07-26
Diffstat (limited to 'src/fontloader/misc/fontloader-util-fil.lua')
-rw-r--r-- | src/fontloader/misc/fontloader-util-fil.lua | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/fontloader/misc/fontloader-util-fil.lua b/src/fontloader/misc/fontloader-util-fil.lua index 47d9d03..eeb6856 100644 --- a/src/fontloader/misc/fontloader-util-fil.lua +++ b/src/fontloader/misc/fontloader-util-fil.lua @@ -6,8 +6,10 @@ if not modules then modules = { } end modules ['util-fil'] = { license = "see context related readme files" } -local byte = string.byte +local byte = string.byte +local char = string.char local extract = bit32.extract +local floor = math.floor -- 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 @@ -36,6 +38,8 @@ function files.size(f) return f:seek("end") end +files.getsize = files.size + function files.setposition(f,n) if zerobased[f] then f:seek("set",n) @@ -180,3 +184,32 @@ end function files.skiplong(f,n) f:read(4*(n or 1)) end + +-- writers (kind of slow) + +function files.writecardinal2(f,n) + local a = char(n % 256) + n = floor(n/256) + local b = char(n % 256) + f:write(b,a) +end + +function files.writecardinal4(f,n) + local a = char(n % 256) + n = floor(n/256) + local b = char(n % 256) + n = floor(n/256) + local c = char(n % 256) + n = floor(n/256) + local d = char(n % 256) + f:write(d,c,b,a) +end + +function files.writestring(f,s) + f:write(char(byte(s,1,#s))) +end + +function files.writebyte(f,b) + f:write(char(b)) +end + |