diff options
author | Philipp Gesang <phg@phi-gamma.net> | 2016-04-08 19:13:51 +0200 |
---|---|---|
committer | Philipp Gesang <phg@phi-gamma.net> | 2016-04-08 19:13:51 +0200 |
commit | f3495d7db72f854d8f7560a6ff11fa9012003062 (patch) | |
tree | 38b9ad5b0d15ccd5c8288be2221defc091eada64 | |
parent | 233c885a37efeabaab00c68f1dd4262705a0ac9e (diff) | |
parent | 935306412b57f436fcb5307a14941ded3eb3168d (diff) | |
download | lualibs-f3495d7db72f854d8f7560a6ff11fa9012003062.tar.gz |
Merge pull request #29 from phi-gamma/master
version 2.4
-rw-r--r-- | NEWS | 8 | ||||
-rw-r--r-- | lualibs-lpeg.lua | 2 | ||||
-rw-r--r-- | lualibs-lua.lua | 14 | ||||
-rw-r--r-- | lualibs-trac-inf.lua | 6 | ||||
-rw-r--r-- | lualibs-unicode.lua | 9 | ||||
-rw-r--r-- | lualibs-util-fil.lua | 167 | ||||
-rw-r--r-- | lualibs-util-prs.lua | 11 | ||||
-rw-r--r-- | lualibs-util-tab.lua | 2 | ||||
-rw-r--r-- | lualibs.dtx | 26 | ||||
-rw-r--r-- | whatsnew.lua | 2 |
10 files changed, 220 insertions, 27 deletions
@@ -1,7 +1,13 @@ History of the lualibs package +2016/04/06 v2.4/ + * sync with Context beta as of 2016-04-06 + * basic maintenance + * include util-fil.lua, a fontloader requirement, in the extended + collection + 2015/12/02 v2.3/ * sync with Context beta as of 2015-11-19 - * basic maintainance + * basic maintenance 2014/05/05 v2.2/ * sync with Context beta as of 2014-07-26 diff --git a/lualibs-lpeg.lua b/lualibs-lpeg.lua index 5be1246..959ca55 100644 --- a/lualibs-lpeg.lua +++ b/lualibs-lpeg.lua @@ -110,7 +110,7 @@ local underscore = P("_") local hexdigit = digit + lowercase + uppercase local cr, lf, crlf = P("\r"), P("\n"), P("\r\n") ----- newline = crlf + S("\r\n") -- cr + lf -local newline = P("\r") * (P("\n") + P(true)) + P("\n") +local newline = P("\r") * (P("\n") + P(true)) + P("\n") -- P("\r")^-1 * P("\n")^-1 local escaped = P("\\") * anything local squote = P("'") local dquote = P('"') diff --git a/lualibs-lua.lua b/lualibs-lua.lua index cb61829..b90f37e 100644 --- a/lualibs-lua.lua +++ b/lualibs-lua.lua @@ -19,12 +19,20 @@ if not modules then modules = { } end modules ['l-lua'] = { -- compatibility hacksand helpers -local major, minor = string.match(_VERSION,"^[^%d]+(%d+)%.(%d+).*$") +_MAJORVERSION, _MINORVERSION = string.match(_VERSION,"^[^%d]+(%d+)%.(%d+).*$") -_MAJORVERSION = tonumber(major) or 5 -_MINORVERSION = tonumber(minor) or 1 +_MAJORVERSION = tonumber(_MAJORVERSION) or 5 +_MINORVERSION = tonumber(_MINORVERSION) or 1 _LUAVERSION = _MAJORVERSION + _MINORVERSION/10 +if _LUAVERSION < 5.2 and jit then + -- + -- we want loadstring cum suis to behave like 5.2 + -- + _MINORVERSION = 2 + _LUAVERSION = 5.2 +end + -- lpeg if not lpeg then diff --git a/lualibs-trac-inf.lua b/lualibs-trac-inf.lua index 5497e54..f4c4e55 100644 --- a/lualibs-trac-inf.lua +++ b/lualibs-trac-inf.lua @@ -145,13 +145,13 @@ function statistics.show() -- so far -- collectgarbage("collect") register("lua properties",function() - local list = status.list() - local hashchar = tonumber(list.luatex_hashchars) + local hashchar = tonumber(status.luatex_hashchars) + local hashtype = status.luatex_hashtype local mask = lua.mask or "ascii" return format("engine: %s, used memory: %s, hash type: %s, hash chars: min(%s,40), symbol mask: %s (%s)", jit and "luajit" or "lua", statistics.memused(), - list.luatex_hashtype or "default", + hashtype or "default", hashchar and 2^hashchar or "unknown", mask, mask == "utf" and "τεχ" or "tex") diff --git a/lualibs-unicode.lua b/lualibs-unicode.lua index 70b6032..3dec800 100644 --- a/lualibs-unicode.lua +++ b/lualibs-unicode.lua @@ -528,9 +528,10 @@ end -- end, pattern -- end -function utf.remapper(mapping,option) -- static also returns a pattern +function utf.remapper(mapping,option,action) -- static also returns a pattern local variant = type(mapping) if variant == "table" then + action = action or mapping if option == "dynamic" then local pattern = false table.setmetatablenewindex(mapping,function(t,k,v) rawset(t,k,v) pattern = false end) @@ -539,16 +540,16 @@ function utf.remapper(mapping,option) -- static also returns a pattern return "" else if not pattern then - pattern = Cs((tabletopattern(mapping)/mapping + p_utf8char)^0) + pattern = Cs((tabletopattern(mapping)/action + p_utf8char)^0) end return lpegmatch(pattern,str) end end elseif option == "pattern" then - return Cs((tabletopattern(mapping)/mapping + p_utf8char)^0) + return Cs((tabletopattern(mapping)/action + p_utf8char)^0) -- elseif option == "static" then else - local pattern = Cs((tabletopattern(mapping)/mapping + p_utf8char)^0) + local pattern = Cs((tabletopattern(mapping)/action + p_utf8char)^0) return function(str) if not str or str == "" then return "" diff --git a/lualibs-util-fil.lua b/lualibs-util-fil.lua new file mode 100644 index 0000000..28c92c7 --- /dev/null +++ b/lualibs-util-fil.lua @@ -0,0 +1,167 @@ +if not modules then modules = { } end modules ['util-fil'] = { + version = 1.001, + comment = "companion to luat-lib.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +local byte = string.byte +local extract = bit32.extract + +-- 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 +-- here. + +utilities = utilities or { } +local files = { } +utilities.files = files + +local zerobased = { } + +function files.open(filename,zb) + local f = io.open(filename,"rb") + if f then + zerobased[f] = zb or false + end + return f +end + +function files.close(f) + zerobased[f] = nil + f:close() +end + +function files.size(f) + return f:seek("end") +end + +function files.setposition(f,n) + if zerobased[f] then + f:seek("set",n) + else + f:seek("set",n - 1) + end +end + +function files.getposition(f) + if zerobased[f] then + return f:seek() + else + return f:seek() + 1 + end +end + +function files.look(f,n,chars) + local p = f:seek() + local s = f:read(n) + f:seek("set",p) + if chars then + return s + else + return byte(s,1,#s) + end +end + +function files.skip(f,n) + if n == 1 then + f:read(n) + else + f:seek("set",f:seek()+n) + end +end + +function files.readbyte(f) + return byte(f:read(1)) +end + +function files.readbytes(f,n) + return byte(f:read(n),1,n) +end + +function files.readchar(f) + return f:read(1) +end + +function files.readstring(f,n) + return f:read(n or 1) +end + +function files.readinteger1(f) -- one byte + local n = byte(f:read(1)) + if n >= 0x80 then + return n - 0xFF - 1 + else + return n + end +end + +files.readcardinal1 = files.readbyte -- one byte +files.readcardinal = files.readcardinal1 +files.readinteger = files.readinteger1 + +function files.readcardinal2(f) + local a, b = byte(f:read(2),1,2) + return 0x100 * a + b +end + +function files.readinteger2(f) + local a, b = byte(f:read(2),1,2) + local n = 0x100 * a + b + if n >= 0x8000 then + return n - 0xFFFF - 1 + else + return n + end +end + +function files.readcardinal3(f) + local a, b, c = byte(f:read(3),1,3) + return 0x10000 * a + 0x100 * b + c +end + +function files.readcardinal4(f) + local a, b, c, d = byte(f:read(4),1,4) + return 0x1000000 * a + 0x10000 * b + 0x100 * c + d +end + +function files.readinteger4(f) + local a, b, c, d = byte(f:read(4),1,4) + local n = 0x1000000 * a + 0x10000 * b + 0x100 * c + d + if n >= 0x8000000 then + return n - 0xFFFFFFFF - 1 + else + return n + end +end + +function files.readfixed4(f) + local a, b, c, d = byte(f:read(4),1,4) + local n = 0x100 * a + b + if n >= 0x8000 then + return n - 0xFFFF - 1 + (0x100 * c + d)/0xFFFF + else + return n + (0x100 * c + d)/0xFFFF + end +end + +function files.read2dot14(f) + local a, b = byte(f:read(2),1,2) + local n = 0x100 * a + b + local m = extract(n,0,30) + if n > 0x7FFF then + n = extract(n,30,2) + return m/0x4000 - 4 + else + n = extract(n,30,2) + return n + m/0x4000 + end +end + +function files.skipshort(f,n) + f:read(2*(n or 1)) +end + +function files.skiplong(f,n) + f:read(4*(n or 1)) +end diff --git a/lualibs-util-prs.lua b/lualibs-util-prs.lua index a3c1c6f..01138f1 100644 --- a/lualibs-util-prs.lua +++ b/lualibs-util-prs.lua @@ -24,6 +24,8 @@ local sortedhash = table.sortedhash local sortedkeys = table.sortedkeys local tohash = table.tohash +local hashes = { } +utilities.parsers.hashes = hashes -- we share some patterns local digit = R("09") @@ -315,10 +317,17 @@ end local pattern = Cf(Ct("") * Cg(C((1-S(", "))^1) * S(", ")^0 * Cc(true))^1,rawset) -function utilities.parsers.settings_to_set(str,t) +function utilities.parsers.settings_to_set(str) return str and lpegmatch(pattern,str) or { } end +hashes.settings_to_set = table.setmetatableindex(function(t,k) -- experiment, not public + local v = k and lpegmatch(pattern,k) or { } + t[k] = v + return v +end) + +getmetatable(hashes.settings_to_set).__mode = "kv" -- could be an option (maybe sharing makes sense) function parsers.simple_hash_to_string(h, separator) local t, tn = { }, 0 diff --git a/lualibs-util-tab.lua b/lualibs-util-tab.lua index d6f3d67..a6239ad 100644 --- a/lualibs-util-tab.lua +++ b/lualibs-util-tab.lua @@ -833,5 +833,5 @@ end table.serialize = serialize if setinspector then - setinspector("table",function(v) if type(v) == "table" then print(serialize(v,"table")) return true end end) + setinspector("table",function(v) if type(v) == "table" then print(serialize(v,"table",{})) return true end end) end diff --git a/lualibs.dtx b/lualibs.dtx index 23ba5d8..291049d 100644 --- a/lualibs.dtx +++ b/lualibs.dtx @@ -1,6 +1,6 @@ % \iffalse meta-comment % -% Copyright (C) 2009--2015 by +% Copyright (C) 2009--2016 by % % PRAGMA ADE / ConTeXt Development Team % The LuaLaTeX Dev Team @@ -37,7 +37,7 @@ \input docstrip.tex \Msg{************************************************************************} \Msg{* Installation} -\Msg{* Package: lualibs 2015-12-02 v2.3 Lua additional functions.} +\Msg{* Package: lualibs 2016-04-06 v2.4 Lua additional functions.} \Msg{************************************************************************} \keepsilent @@ -48,7 +48,7 @@ \preamble This is a generated file. -Copyright (C) 2009--2015 by +Copyright (C) 2009--2016 by PRAGMA ADE / ConTeXt Development Team The LuaLaTeX Dev Team @@ -107,7 +107,7 @@ and lualibs-extended.lua. %<*driver> \NeedsTeXFormat{LaTeX2e} \ProvidesFile{lualibs.drv} - [2015/12/02 v2.3 Lua Libraries.] + [2016/04/06 v2.4 Lua Libraries.] \documentclass{ltxdoc} \usepackage{fancyvrb,xspace} \usepackage[x11names]{xcolor} @@ -208,9 +208,9 @@ and lualibs-extended.lua. % \GetFileInfo{lualibs.drv} % % \title{The \identifier{lualibs} package} -% \date{2015/12/02 v2.3} +% \date{2016/04/06 v2.4} % \author{Élie Roux · \email{elie.roux@telecom-bretagne.eu}\\ -% Philipp Gesang · \email{philipp.gesang@alumni.uni-heidelberg.de}} +% Philipp Gesang · \email{phg@phi-gamma.net}} % % \maketitle % @@ -346,6 +346,7 @@ and lualibs-extended.lua. % \begin{tabular}{l l l} % \identifier{lualibs} name & \CONTEXT name & primary purpose \\[1ex] % lualibs-util-str.lua & util-str.lua & extra |string| functions \\ +% lualibs-util-fil.lua & util-fil.lua & extra |file| functions \\ % lualibs-util-tab.lua & util-tab.lua & extra |table| functions \\ % lualibs-util-sto.lua & util-sto.lua & table allocation \\ % lualibs-util-prs.lua & util-sto.lua & miscellaneous parsers \\ @@ -426,8 +427,8 @@ lualibs = lualibs or { } lualibs.module_info = { name = "lualibs", - version = 2.3, - date = "2015-12-02", + version = 2.4, + date = "2016-04-06", description = "ConTeXt Lua standard libraries.", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux & Philipp Gesang", copyright = "PRAGMA ADE / ConTeXt Development Team", @@ -581,8 +582,8 @@ local loadmodule = lualibs.loadmodule local lualibs_basic_module = { name = "lualibs-basic", - version = 2.3, - date = "2015-12-02", + version = 2.4, + date = "2016-04-06", description = "ConTeXt Lua libraries -- basic collection.", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux & Philipp Gesang", copyright = "PRAGMA ADE / ConTeXt Development Team", @@ -663,8 +664,8 @@ lualibs = lualibs or { } local lualibs_extended_module = { name = "lualibs-extended", - version = 2.3, - date = "2015-12-02", + version = 2.4, + date = "2016-04-06", description = "ConTeXt Lua libraries -- extended collection.", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux & Philipp Gesang", copyright = "PRAGMA ADE / ConTeXt Development Team", @@ -776,6 +777,7 @@ end if loaded == false then loadmodule("lualibs-util-str.lua")--- string formatters (fast) + loadmodule("lualibs-util-fil.lua")--- extra file helpers loadmodule("lualibs-util-tab.lua")--- extended table operations loadmodule("lualibs-util-sto.lua")--- storage (hash allocation) ----------("lualibs-util-pck.lua")---!packers; necessary? diff --git a/whatsnew.lua b/whatsnew.lua index e9cc378..35533ca 100644 --- a/whatsnew.lua +++ b/whatsnew.lua @@ -17,7 +17,7 @@ local prefixsep = "-" local namespace = "lualibs" local luasuffix = ".lua" -local basedir = "/home/phg/context/tex/texmf-context/tex/context/base" +local basedir = "/home/phg/context/tex/texmf-context/tex/context/base/mkiv" local cmd_diff = [[diff "%s" "%s"]] ----------------------------------------------------------------------- |