texlive[52648] Master/texmf-dist: lualibs (5nov19)

commits+karl at tug.org commits+karl at tug.org
Tue Nov 5 22:36:14 CET 2019


Revision: 52648
          http://tug.org/svn/texlive?view=revision&revision=52648
Author:   karl
Date:     2019-11-05 22:36:14 +0100 (Tue, 05 Nov 2019)
Log Message:
-----------
lualibs (5nov19)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/luatex/lualibs/NEWS
    trunk/Master/texmf-dist/doc/luatex/lualibs/README.md
    trunk/Master/texmf-dist/doc/luatex/lualibs/lualibs.pdf
    trunk/Master/texmf-dist/source/luatex/lualibs/lualibs.dtx
    trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-basic-merged.lua
    trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-basic.lua
    trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-extended-merged.lua
    trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-extended.lua
    trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-gzip.lua
    trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-lpeg.lua
    trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-lua.lua
    trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-table.lua
    trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-unicode.lua
    trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-lua.lua
    trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-str.lua
    trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-tab.lua
    trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-tpl.lua
    trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs.lua

Modified: trunk/Master/texmf-dist/doc/luatex/lualibs/NEWS
===================================================================
--- trunk/Master/texmf-dist/doc/luatex/lualibs/NEWS	2019-11-05 21:35:56 UTC (rev 52647)
+++ trunk/Master/texmf-dist/doc/luatex/lualibs/NEWS	2019-11-05 21:36:14 UTC (rev 52648)
@@ -1,4 +1,7 @@
                         History of the lualibs package
+2019/10/29 v2.68/
+    * sync with Context current as of 2019/10/29
+                        
 2019/08/11 v2.67/
     * sync with Context current as of 2019/08/11
                         

Modified: trunk/Master/texmf-dist/doc/luatex/lualibs/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/luatex/lualibs/README.md	2019-11-05 21:35:56 UTC (rev 52647)
+++ trunk/Master/texmf-dist/doc/luatex/lualibs/README.md	2019-11-05 21:36:14 UTC (rev 52648)
@@ -1,8 +1,8 @@
 # The Lualibs Package
 
-VERSION: 2.67
+VERSION: 2.68
 
-DATE: 2019-08-11
+DATE: 2019-11-05
 
 Lualibs is a collection of Lua modules useful for general programming.
 

Modified: trunk/Master/texmf-dist/doc/luatex/lualibs/lualibs.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/source/luatex/lualibs/lualibs.dtx
===================================================================
--- trunk/Master/texmf-dist/source/luatex/lualibs/lualibs.dtx	2019-11-05 21:35:56 UTC (rev 52647)
+++ trunk/Master/texmf-dist/source/luatex/lualibs/lualibs.dtx	2019-11-05 21:36:14 UTC (rev 52648)
@@ -37,7 +37,7 @@
 \input docstrip.tex
 \Msg{************************************************************************}
 \Msg{* Installation}
-\Msg{* Package: lualibs 2019-08-11 v2.67 Lua additional functions.}
+\Msg{* Package: lualibs 2019-11-05 v2.68 Lua additional functions.}
 \Msg{************************************************************************}
 
 \keepsilent
@@ -107,7 +107,7 @@
 %<*driver>
 \NeedsTeXFormat{LaTeX2e}
 \ProvidesFile{lualibs.drv}
-  [2019/08/11 v2.67 Lua Libraries.]
+  [2019/11/05 v2.68 Lua Libraries.]
 \documentclass{ltxdoc}
 \usepackage{fancyvrb,xspace}
 \usepackage[x11names]{xcolor}
@@ -208,7 +208,7 @@
 % \GetFileInfo{lualibs.drv}
 %
 % \title{The \identifier{lualibs} package}
-% \date{2019/08/11 v2.67}
+% \date{2019/11/05 v2.68}
 % \author{Élie Roux      · \email{elie.roux at telecom-bretagne.eu}\\
 %         Philipp Gesang · \email{phg at phi-gamma.net}\\
 %         Ulrike Fischer · \email{fischer at troubleshooting-tex.de}\\
@@ -429,8 +429,8 @@
 
 lualibs.module_info = {
   name          = "lualibs",
-  version       = "2.67",       --TAGVERSION
-    date        = "2019-08-11", --TAGDATE
+  version       = "2.68",       --TAGVERSION
+    date        = "2019-11-05", --TAGDATE
   description   = "ConTeXt Lua standard libraries.",
   author        = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux & Philipp Gesang",
   copyright     = "PRAGMA ADE / ConTeXt Development Team",
@@ -583,8 +583,8 @@
 
 local lualibs_basic_module = {
   name          = "lualibs-basic",
-  version       = "2.67",       --TAGVERSION
-  date          = "2019-08-11", --TAGDATE
+  version       = "2.68",       --TAGVERSION
+  date          = "2019-11-05", --TAGDATE
   description   = "ConTeXt Lua libraries -- basic collection.",
   author        = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux & Philipp Gesang",
   copyright     = "PRAGMA ADE / ConTeXt Development Team",
@@ -665,8 +665,8 @@
 
 local lualibs_extended_module = {
   name          = "lualibs-extended",
-  version       = "2.67",       --TAGVERSION
-  date          = "2019-08-11", --TAGDATE
+  version       = "2.68",       --TAGVERSION
+  date          = "2019-11-05", --TAGDATE
   description   = "ConTeXt Lua libraries -- extended collection.",
   author        = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux & Philipp Gesang",
   copyright     = "PRAGMA ADE / ConTeXt Development Team",

Modified: trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-basic-merged.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-basic-merged.lua	2019-11-05 21:35:56 UTC (rev 52647)
+++ trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-basic-merged.lua	2019-11-05 21:36:14 UTC (rev 52648)
@@ -1,6 +1,6 @@
 -- merged file : lualibs-basic-merged.lua
 -- parent file : lualibs-basic.lua
--- merge date  : Tue Aug 13 20:13:08 2019
+-- merge date  : Tue Oct 29 16:47:31 2019
 
 do -- begin closure to overcome local limits and interference
 
@@ -20,6 +20,9 @@
  MINORVERSION=2
  LUAVERSION=5.2
 end
+if lua and lua.openfile then
+ io.open=lua.openfile
+end
 if not lpeg then
  lpeg=require("lpeg")
 end
@@ -613,7 +616,7 @@
 patterns.somecontent=(anything-newline-space)^1 
 patterns.beginline=#(1-newline)
 patterns.longtostring=Cs(whitespace^0/""*((patterns.quoted+nonwhitespace^1+whitespace^1/""*(endofstring+Cc(" ")))^0))
-function anywhere(pattern) 
+local function anywhere(pattern) 
  return (1-P(pattern))^0*P(pattern)
 end
 lpeg.anywhere=anywhere
@@ -3954,44 +3957,99 @@
  copyright="PRAGMA ADE / ConTeXt Development Team",
  license="see context related readme files"
 }
-if not gzip then
- return
-end
-local suffix,suffixes=file.suffix,file.suffixes
-function gzip.load(filename)
- local f=io.open(filename,"rb")
- if not f then
- elseif suffix(filename)=="gz" then
-  f:close()
-  local g=gzip.open(filename,"rb")
-  if g then
-   local str=g:read("*all")
-   g:close()
+if gzip then
+ local suffix,suffixes=file.suffix,file.suffixes
+ function gzip.load(filename)
+  local f=io.open(filename,"rb")
+  if not f then
+  elseif suffix(filename)=="gz" then
+   f:close()
+   local g=gzip.open(filename,"rb")
+   if g then
+    local str=g:read("*all")
+    g:close()
+    return str
+   end
+  else
+   local str=f:read("*all")
+   f:close()
    return str
   end
- else
-  local str=f:read("*all")
-  f:close()
-  return str
  end
+ function gzip.save(filename,data)
+  if suffix(filename)~="gz" then
+   filename=filename..".gz"
+  end
+  local f=io.open(filename,"wb")
+  if f then
+   local s=zlib.compress(data or "",9,nil,15+16)
+   f:write(s)
+   f:close()
+   return #s
+  end
+ end
+ function gzip.suffix(filename)
+  local suffix,extra=suffixes(filename)
+  local gzipped=extra=="gz"
+  return suffix,gzipped
+ end
+else
 end
-function gzip.save(filename,data)
- if suffix(filename)~="gz" then
-  filename=filename..".gz"
+if flate then
+ local type=type
+ local find=string.find
+ local compress=flate.gz_compress
+ local decompress=flate.gz_decompress
+ local absmax=128*1024*1024
+ local initial=64*1024
+ local identifier="^\x1F\x8B\x08"
+ function gzip.compressed(s)
+  return s and find(s,identifier)
  end
- local f=io.open(filename,"wb")
- if f then
-  local s=zlib.compress(data or "",9,nil,15+16)
-  f:write(s)
-  f:close()
-  return #s
+ function gzip.compress(s,level)
+  if s and not find(s,identifier) then 
+   if not level then
+    level=3
+   elseif level<=0 then
+    return s
+   elseif level>9 then
+    level=9
+   end
+   return compress(s,level) or s
+  end
  end
+ function gzip.decompress(s,size,iterate)
+  if s and find(s,identifier) then
+   if type(size)~="number" then
+    size=initial
+   end
+   if size>absmax then
+    size=absmax
+   end
+   if type(iterate)=="number" then
+    max=size*iterate
+   elseif iterate==nil or iterate==true then
+    iterate=true
+    max=absmax
+   end
+   if max>absmax then
+    max=absmax
+   end
+   while true do
+    local d=decompress(s,size)
+    if d then
+     return d
+    end
+    size=2*size
+    if not iterate or size>max then
+     return false
+    end
+   end
+  else
+   return s
+  end
+ end
 end
-function gzip.suffix(filename)
- local suffix,extra=suffixes(filename)
- local gzipped=extra=="gz"
- return suffix,gzipped
-end
 
 end -- closure
 
@@ -5097,49 +5155,52 @@
 function utf.utf32_to_utf8_t(t,endian)
  return endian and utf32_to_utf8_be_t(t) or utf32_to_utf8_le_t(t) or t
 end
-local function little(b)
- if b<0x10000 then
-  return char(b%256,rshift(b,8))
- else
-  b=b-0x10000
-  local b1=rshift(b,10)+0xD800
-  local b2=b%1024+0xDC00
-  return char(b1%256,rshift(b1,8),b2%256,rshift(b2,8))
+if bit32 then
+ local rshift=bit32.rshift
+ local function little(b)
+  if b<0x10000 then
+   return char(b%256,rshift(b,8))
+  else
+   b=b-0x10000
+   local b1=rshift(b,10)+0xD800
+   local b2=b%1024+0xDC00
+   return char(b1%256,rshift(b1,8),b2%256,rshift(b2,8))
+  end
  end
-end
-local function big(b)
- if b<0x10000 then
-  return char(rshift(b,8),b%256)
- else
-  b=b-0x10000
-  local b1=rshift(b,10)+0xD800
-  local b2=b%1024+0xDC00
-  return char(rshift(b1,8),b1%256,rshift(b2,8),b2%256)
+ local function big(b)
+  if b<0x10000 then
+   return char(rshift(b,8),b%256)
+  else
+   b=b-0x10000
+   local b1=rshift(b,10)+0xD800
+   local b2=b%1024+0xDC00
+   return char(rshift(b1,8),b1%256,rshift(b2,8),b2%256)
+  end
  end
-end
-local l_remap=Cs((p_utf8byte/little+P(1)/"")^0)
-local b_remap=Cs((p_utf8byte/big+P(1)/"")^0)
-local function utf8_to_utf16_be(str,nobom)
- if nobom then
-  return lpegmatch(b_remap,str)
- else
-  return char(254,255)..lpegmatch(b_remap,str)
+ local l_remap=Cs((p_utf8byte/little+P(1)/"")^0)
+ local b_remap=Cs((p_utf8byte/big+P(1)/"")^0)
+ local function utf8_to_utf16_be(str,nobom)
+  if nobom then
+   return lpegmatch(b_remap,str)
+  else
+   return char(254,255)..lpegmatch(b_remap,str)
+  end
  end
-end
-local function utf8_to_utf16_le(str,nobom)
- if nobom then
-  return lpegmatch(l_remap,str)
- else
-  return char(255,254)..lpegmatch(l_remap,str)
+ local function utf8_to_utf16_le(str,nobom)
+  if nobom then
+   return lpegmatch(l_remap,str)
+  else
+   return char(255,254)..lpegmatch(l_remap,str)
+  end
  end
-end
-utf.utf8_to_utf16_be=utf8_to_utf16_be
-utf.utf8_to_utf16_le=utf8_to_utf16_le
-function utf.utf8_to_utf16(str,littleendian,nobom)
- if littleendian then
-  return utf8_to_utf16_le(str,nobom)
- else
-  return utf8_to_utf16_be(str,nobom)
+ utf.utf8_to_utf16_be=utf8_to_utf16_be
+ utf.utf8_to_utf16_le=utf8_to_utf16_le
+ function utf.utf8_to_utf16(str,littleendian,nobom)
+  if littleendian then
+   return utf8_to_utf16_le(str,nobom)
+  else
+   return utf8_to_utf16_be(str,nobom)
+  end
  end
 end
 local pattern=Cs (

Modified: trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-basic.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-basic.lua	2019-11-05 21:35:56 UTC (rev 52647)
+++ trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-basic.lua	2019-11-05 21:36:14 UTC (rev 52648)
@@ -29,8 +29,8 @@
 
 local lualibs_basic_module = {
   name          = "lualibs-basic",
-  version       = "2.67",       --TAGVERSION
-  date          = "2019-08-11", --TAGDATE
+  version       = "2.68",       --TAGVERSION
+  date          = "2019-11-05", --TAGDATE
   description   = "ConTeXt Lua libraries -- basic collection.",
   author        = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux & Philipp Gesang",
   copyright     = "PRAGMA ADE / ConTeXt Development Team",
@@ -40,11 +40,11 @@
 local loaded = false --- track success of package loading
 
 if lualibs.prefer_merged then
-  info"Loading merged package for collection ^^e2^^80^^9cbasic^^e2^^80^^9d."
+  info"Loading merged package for collection “basic”."
   loaded = loadmodule('lualibs-basic-merged.lua')
 else
   info"Ignoring merged packages."
-  info"Falling back to individual libraries from collection ^^e2^^80^^9cbasic^^e2^^80^^9d."
+  info"Falling back to individual libraries from collection “basic”."
 end
 
 

Modified: trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-extended-merged.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-extended-merged.lua	2019-11-05 21:35:56 UTC (rev 52647)
+++ trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-extended-merged.lua	2019-11-05 21:36:14 UTC (rev 52648)
@@ -1,6 +1,6 @@
 -- merged file : lualibs-extended-merged.lua
 -- parent file : lualibs-extended.lua
--- merge date  : Tue Aug 13 20:12:59 2019
+-- merge date  : Tue Oct 29 16:47:22 2019
 
 do -- begin closure to overcome local limits and interference
 
@@ -366,7 +366,7 @@
  stripzero=patterns.stripzero,
  stripzeros=patterns.stripzeros,
  escapedquotes=string.escapedquotes,
- FORMAT=string.f9,
+ FORMAT=string.f6,
 }
 local arguments={ "a1" } 
 setmetatable(arguments,{ __index=function(t,k)
@@ -574,12 +574,25 @@
  n=n+1
  return format("((a%s %% 1 == 0) and format('%%i',a%s) or tostring(a%s))",n,n,n)
 end
-local format_N=function(f) 
- n=n+1
- if not f or f=="" then
-  f=".9"
- end 
- return format("(((a%s %% 1 == 0) and format('%%i',a%s)) or lpegmatch(stripzero,format('%%%sf',a%s)))",n,n,f,n)
+local format_N  if environment.FORMAT then
+ format_N=function(f)
+  n=n+1
+  if not f or f=="" then
+   return format("FORMAT(a%s,'%%.9f')",n)
+  elseif f==".6" then
+   return format("FORMAT(a%s)",n)
+  else
+   return format("FORMAT(a%s,'%%%sf')",n,f)
+  end
+ end
+else
+ format_N=function(f) 
+  n=n+1
+  if not f or f=="" then
+   f=".9"
+  end 
+  return format("(((a%s %% 1 == 0) and format('%%i',a%s)) or lpegmatch(stripzero,format('%%%sf',a%s)))",n,n,f,n)
+ end
 end
 local format_a=function(f)
  n=n+1
@@ -1416,7 +1429,21 @@
   m=m+1
   r[m]="{"
   if n>0 then
-   for i=0,n do
+   local v=t[0]
+   if v then
+    local tv=type(v)
+    if tv=="string" then
+     m=m+1 r[m]=f_indexed_string(0,v)
+    elseif tv=="number" then
+     m=m+1 r[m]=f_indexed_number(0,v)
+    elseif tv=="table" then
+     m=m+1 r[m]=f_indexed_table(0)
+     fastserialize(v)
+    elseif tv=="boolean" then
+     m=m+1 r[m]=f_indexed_boolean(0,v)
+    end
+   end
+   for i=1,n do
     local v=t[i]
     local tv=type(v)
     if tv=="string" then
@@ -3377,6 +3404,11 @@
 luautilities.nofstrippedbytes=0
 local strippedchunks={} 
 luautilities.strippedchunks=strippedchunks
+if not LUATEXENGINE then
+ LUATEXENGINE=status.luatex_engine and string.lower(status.luatex_engine)
+ JITSUPPORTED=LUATEXENGINE=="luajittex" or jit
+ CONTEXTLMTXMODE=CONTEXTLMTXMODE or (LUATEXENGINE=="luametatex" and 1) or 0
+end
 luautilities.suffixes={
  tma="tma",
  tmc=(CONTEXTLMTXMODE and CONTEXTLMTXMODE>0 and "tmd") or (jit and "tmb") or "tmc",
@@ -3386,7 +3418,7 @@
  luv="luv",
  luj="luj",
  tua="tua",
- tuc="tuc",
+ tuc=(CONTEXTLMTXMODE and CONTEXTLMTXMODE>0 and "tud") or (jit and "tub") or "tuc",
 }
 local function register(name) 
  if tracestripping then
@@ -3833,6 +3865,7 @@
 local tostring,next=tostring,next
 local format,sub,byte=string.format,string.sub,string.byte
 local P,C,R,Cs,Cc,Carg,lpegmatch,lpegpatterns=lpeg.P,lpeg.C,lpeg.R,lpeg.Cs,lpeg.Cc,lpeg.Carg,lpeg.match,lpeg.patterns
+local formatters=string.formatters
 local replacer
 local function replacekey(k,t,how,recursive)
  local v=t[k]
@@ -3901,6 +3934,10 @@
  local v=t[l]
  return v and v~="" and lpegmatch(replacer,r,1,t,how or "lua",recurse or false) or ""
 end
+local function replaceformatted(l,m,r,t,how,recurse)
+ local v=t[r]
+ return v and formatters[l](v)
+end
 local single=P("%")  
 local double=P("%%") 
 local lquoted=P("%[") 
@@ -3914,16 +3951,19 @@
 local norquoted=rquoted/''
 local nolquotedq=lquotedq/''
 local norquotedq=rquotedq/''
+local nolformatted=P(":")/"%%"
+local norformatted=P(":")/""
 local noloptional=P("%?")/''
 local noroptional=P("?%")/''
 local nomoptional=P(":")/''
 local args=Carg(1)*Carg(2)*Carg(3)
-local key=nosingle*((C((1-nosingle   )^1)*args)/replacekey  )*nosingle
-local quoted=nolquotedq*((C((1-norquotedq )^1)*args)/replacekeyquoted  )*norquotedq
-local unquoted=nolquoted*((C((1-norquoted  )^1)*args)/replacekeyunquoted)*norquoted
+local key=nosingle*((C((1-nosingle)^1)*args)/replacekey)*nosingle
+local quoted=nolquotedq*((C((1-norquotedq)^1)*args)/replacekeyquoted)*norquotedq
+local unquoted=nolquoted*((C((1-norquoted)^1)*args)/replacekeyunquoted)*norquoted
 local optional=noloptional*((C((1-nomoptional)^1)*nomoptional*C((1-noroptional)^1)*args)/replaceoptional)*noroptional
+local formatted=nosingle*((Cs(nolformatted*(1-norformatted )^1)*norformatted*C((1-nosingle)^1)*args)/replaceformatted)*nosingle
 local any=P(1)
-   replacer=Cs((unquoted+quoted+escape+optional+key+any)^0)
+   replacer=Cs((unquoted+quoted+formatted+escape+optional+key+any)^0)
 local function replace(str,mapping,how,recurse)
  if mapping and str then
   return lpegmatch(replacer,str,1,mapping,how or "lua",recurse or false) or str

Modified: trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-extended.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-extended.lua	2019-11-05 21:35:56 UTC (rev 52647)
+++ trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-extended.lua	2019-11-05 21:36:14 UTC (rev 52648)
@@ -30,8 +30,8 @@
 
 local lualibs_extended_module = {
   name          = "lualibs-extended",
-  version       = "2.67",       --TAGVERSION
-  date          = "2019-08-11", --TAGDATE
+  version       = "2.68",       --TAGVERSION
+  date          = "2019-11-05", --TAGDATE
   description   = "ConTeXt Lua libraries -- extended collection.",
   author        = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux & Philipp Gesang",
   copyright     = "PRAGMA ADE / ConTeXt Development Team",
@@ -111,11 +111,11 @@
 
 local loaded = false
 if lualibs.prefer_merged then
-  info"Loading merged package for collection ^^e2^^80^^9cextended^^e2^^80^^9d."
+  info"Loading merged package for collection “extended”."
   loaded = loadmodule('lualibs-extended-merged.lua')
 else
   info"Ignoring merged packages."
-  info"Falling back to individual libraries from collection ^^e2^^80^^9cextended^^e2^^80^^9d."
+  info"Falling back to individual libraries from collection “extended”."
 end
 
 if loaded == false then

Modified: trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-gzip.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-gzip.lua	2019-11-05 21:35:56 UTC (rev 52647)
+++ trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-gzip.lua	2019-11-05 21:36:14 UTC (rev 52648)
@@ -5,50 +5,113 @@
     license   = "see context related readme files"
 }
 
-if not gzip then
+if gzip then
 
-    -- no fallback yet
+    local suffix, suffixes = file.suffix, file.suffixes
 
-    return
+    function gzip.load(filename)
+        local f = io.open(filename,"rb")
+        if not f then
+            -- invalid file
+        elseif suffix(filename) == "gz" then
+            f:close()
+            local g = gzip.open(filename,"rb")
+            if g then
+                local str = g:read("*all")
+                g:close()
+                return str
+            end
+        else
+            local str = f:read("*all")
+            f:close()
+            return str
+        end
+    end
 
+    function gzip.save(filename,data)
+        if suffix(filename) ~= "gz" then
+            filename = filename .. ".gz"
+        end
+        local f = io.open(filename,"wb")
+        if f then
+            local s = zlib.compress(data or "",9,nil,15+16)
+            f:write(s)
+            f:close()
+            return #s
+        end
+    end
+
+    function gzip.suffix(filename)
+        local suffix, extra = suffixes(filename)
+        local gzipped = extra == "gz"
+        return suffix, gzipped
+    end
+
+else
+
+    -- todo: fallback on flate
+
 end
 
-local suffix, suffixes = file.suffix, file.suffixes
+if flate then
 
-function gzip.load(filename)
-    local f = io.open(filename,"rb")
-    if not f then
-        -- invalid file
-    elseif suffix(filename) == "gz" then
-        f:close()
-        local g = gzip.open(filename,"rb")
-        if g then
-            local str = g:read("*all")
-            g:close()
-            return str
+    local type = type
+    local find = string.find
+
+    local compress   = flate.gz_compress
+    local decompress = flate.gz_decompress
+
+    local absmax     = 128*1024*1024
+    local initial    =       64*1024
+    local identifier = "^\x1F\x8B\x08"
+
+    function gzip.compressed(s)
+        return s and find(s,identifier)
+    end
+
+    function gzip.compress(s,level)
+        if s and not find(s,identifier) then -- the find check might go away
+            if not level then
+                level = 3
+            elseif level <= 0 then
+                return s
+            elseif level > 9 then
+                level = 9
+            end
+            return compress(s,level) or s
         end
-    else
-        local str = f:read("*all")
-        f:close()
-        return str
     end
-end
 
-function gzip.save(filename,data)
-    if suffix(filename) ~= "gz" then
-        filename = filename .. ".gz"
+    function gzip.decompress(s,size,iterate)
+        if s and find(s,identifier) then
+            if type(size) ~= "number" then
+                size = initial
+            end
+            if size > absmax then
+                size = absmax
+            end
+            if type(iterate) == "number" then
+                max = size * iterate
+            elseif iterate == nil or iterate == true then
+                iterate = true
+                max     = absmax
+            end
+            if max > absmax then
+                max = absmax
+            end
+            while true do
+                local d = decompress(s,size)
+                if d then
+                    return d
+                end
+                size = 2 * size
+                if not iterate or size > max then
+                    return false
+                end
+            end
+        else
+            return s
+        end
     end
-    local f = io.open(filename,"wb")
-    if f then
-        local s = zlib.compress(data or "",9,nil,15+16)
-        f:write(s)
-        f:close()
-        return #s
-    end
-end
 
-function gzip.suffix(filename)
-    local suffix, extra = suffixes(filename)
-    local gzipped = extra == "gz"
-    return suffix, gzipped
 end

Modified: trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-lpeg.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-lpeg.lua	2019-11-05 21:35:56 UTC (rev 52647)
+++ trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-lpeg.lua	2019-11-05 21:36:14 UTC (rev 52648)
@@ -295,7 +295,7 @@
 --     return P { P(pattern) + 1 * V(1) }
 -- end
 
-function anywhere(pattern) -- faster
+local function anywhere(pattern) -- faster
     return (1-P(pattern))^0 * P(pattern)
 end
 

Modified: trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-lua.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-lua.lua	2019-11-05 21:35:56 UTC (rev 52647)
+++ trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-lua.lua	2019-11-05 21:36:14 UTC (rev 52648)
@@ -35,6 +35,12 @@
     LUAVERSION   = 5.2
 end
 
+-- this is lmtx only:
+
+if lua and lua.openfile then
+    io.open = lua.openfile
+end
+
 -- lpeg
 
 if not lpeg then

Modified: trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-table.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-table.lua	2019-11-05 21:35:56 UTC (rev 52647)
+++ trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-table.lua	2019-11-05 21:36:14 UTC (rev 52648)
@@ -287,6 +287,37 @@
     return nothing
 end
 
+-- local function iterate(t,i)
+--     local i = i + 1
+--     if i <= t.n then
+--         local k = t[i]
+--         return i, k, t.t[k]
+--     end
+-- end
+--
+-- local function indexedhash(t,cmp)
+--     if t then
+--         local s
+--         if cmp then
+--             -- it would be nice if the sort function would accept a third argument (or nicer, an optional first)
+--             s = sortedhashkeys(t,function(a,b) return cmp(t,a,b) end)
+--         else
+--             s = sortedkeys(t) -- the robust one
+--         end
+--         local m = #s
+--         if m == 1 then
+--             return next, t
+--         elseif m > 0 then
+--             s.n = m
+--             s.t = t
+--             return iterate, s, 0
+--         end
+--     end
+--     return nothing
+-- end
+--
+-- -- for i, k, v in indexedhash(t) do print(k,v,s) end
+
 table.sortedhash  = sortedhash
 table.sortedpairs = sortedhash -- obsolete
 

Modified: trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-unicode.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-unicode.lua	2019-11-05 21:35:56 UTC (rev 52647)
+++ trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-unicode.lua	2019-11-05 21:36:14 UTC (rev 52648)
@@ -1081,56 +1081,62 @@
     return endian and utf32_to_utf8_be_t(t) or utf32_to_utf8_le_t(t) or t
 end
 
-local function little(b)
-    if b < 0x10000 then
-        return char(b%256,rshift(b,8))
-    else
-        b = b - 0x10000
-        local b1 = rshift(b,10) + 0xD800
-        local b2 = b%1024 + 0xDC00
-        return char(b1%256,rshift(b1,8),b2%256,rshift(b2,8))
+if bit32 then
+
+    local rshift  = bit32.rshift
+
+    local function little(b)
+        if b < 0x10000 then
+            return char(b%256,rshift(b,8))
+        else
+            b = b - 0x10000
+            local b1 = rshift(b,10) + 0xD800
+            local b2 = b%1024 + 0xDC00
+            return char(b1%256,rshift(b1,8),b2%256,rshift(b2,8))
+        end
     end
-end
 
-local function big(b)
-    if b < 0x10000 then
-        return char(rshift(b,8),b%256)
-    else
-        b = b - 0x10000
-        local b1 = rshift(b,10) + 0xD800
-        local b2 = b%1024 + 0xDC00
-        return char(rshift(b1,8),b1%256,rshift(b2,8),b2%256)
+    local function big(b)
+        if b < 0x10000 then
+            return char(rshift(b,8),b%256)
+        else
+            b = b - 0x10000
+            local b1 = rshift(b,10) + 0xD800
+            local b2 = b%1024 + 0xDC00
+            return char(rshift(b1,8),b1%256,rshift(b2,8),b2%256)
+        end
     end
-end
 
-local l_remap = Cs((p_utf8byte/little+P(1)/"")^0)
-local b_remap = Cs((p_utf8byte/big   +P(1)/"")^0)
+    local l_remap = Cs((p_utf8byte/little+P(1)/"")^0)
+    local b_remap = Cs((p_utf8byte/big   +P(1)/"")^0)
 
-local function utf8_to_utf16_be(str,nobom)
-    if nobom then
-        return lpegmatch(b_remap,str)
-    else
-        return char(254,255) .. lpegmatch(b_remap,str)
+    local function utf8_to_utf16_be(str,nobom)
+        if nobom then
+            return lpegmatch(b_remap,str)
+        else
+            return char(254,255) .. lpegmatch(b_remap,str)
+        end
     end
-end
 
-local function utf8_to_utf16_le(str,nobom)
-    if nobom then
-        return lpegmatch(l_remap,str)
-    else
-        return char(255,254) .. lpegmatch(l_remap,str)
+    local function utf8_to_utf16_le(str,nobom)
+        if nobom then
+            return lpegmatch(l_remap,str)
+        else
+            return char(255,254) .. lpegmatch(l_remap,str)
+        end
     end
-end
 
-utf.utf8_to_utf16_be = utf8_to_utf16_be
-utf.utf8_to_utf16_le = utf8_to_utf16_le
+    utf.utf8_to_utf16_be = utf8_to_utf16_be
+    utf.utf8_to_utf16_le = utf8_to_utf16_le
 
-function utf.utf8_to_utf16(str,littleendian,nobom)
-    if littleendian then
-        return utf8_to_utf16_le(str,nobom)
-    else
-        return utf8_to_utf16_be(str,nobom)
+    function utf.utf8_to_utf16(str,littleendian,nobom)
+        if littleendian then
+            return utf8_to_utf16_le(str,nobom)
+        else
+            return utf8_to_utf16_be(str,nobom)
+        end
     end
+
 end
 
 local pattern = Cs (

Modified: trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-lua.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-lua.lua	2019-11-05 21:35:56 UTC (rev 52647)
+++ trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-lua.lua	2019-11-05 21:36:14 UTC (rev 52648)
@@ -28,6 +28,13 @@
 local strippedchunks           = { } -- allocate()
 luautilities.strippedchunks    = strippedchunks
 
+if not LUATEXENGINE then
+    --- probably mtxrun ...
+    LUATEXENGINE    = status.luatex_engine and string.lower(status.luatex_engine)
+    JITSUPPORTED    = LUATEXENGINE == "luajittex" or jit
+    CONTEXTLMTXMODE = CONTEXTLMTXMODE or (LUATEXENGINE == "luametatex" and 1) or 0
+end
+
 luautilities.suffixes = {
     tma = "tma",
     tmc = (CONTEXTLMTXMODE and CONTEXTLMTXMODE > 0 and "tmd") or (jit and "tmb") or "tmc",
@@ -37,7 +44,8 @@
     luv = "luv",
     luj = "luj",
     tua = "tua",
-    tuc = "tuc",
+ -- tuc = "tuc",
+    tuc = (CONTEXTLMTXMODE and CONTEXTLMTXMODE > 0 and "tud") or (jit and "tub") or "tuc",
 }
 
 -- environment.loadpreprocessedfile can be set to a preprocessor

Modified: trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-str.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-str.lua	2019-11-05 21:35:56 UTC (rev 52647)
+++ trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-str.lua	2019-11-05 21:36:14 UTC (rev 52648)
@@ -633,7 +633,7 @@
     stripzeros      = patterns.stripzeros,
     escapedquotes   = string.escapedquotes,
 
-    FORMAT          = string.f9,
+    FORMAT          = string.f6,
 }
 
 -- -- --
@@ -908,7 +908,7 @@
     return format("(a%s and 'TRUE' or 'FALSE')",n)
 end
 
-local format_n = function() -- strips leading and trailing zeros and removes .0
+local format_n = function() -- strips leading and trailing zeros and removes .0, beware: can produce e notation
     n = n + 1
     return format("((a%s %% 1 == 0) and format('%%i',a%s) or tostring(a%s))",n,n,n)
 end
@@ -938,13 +938,30 @@
 --     end
 -- end
 
-local format_N = function(f) -- strips leading and trailing zeros
-    n = n + 1
-    -- stripzero (singular) as we only have a number
-    if not f or f == "" then
-        f = ".9"
-    end -- always a leading number !
-    return format("(((a%s %% 1 == 0) and format('%%i',a%s)) or lpegmatch(stripzero,format('%%%sf',a%s)))",n,n,f,n)
+local format_N  if environment.FORMAT then
+
+    format_N = function(f)
+        n = n + 1
+        if not f or f == "" then
+            return format("FORMAT(a%s,'%%.9f')",n)
+        elseif f == ".6" then
+            return format("FORMAT(a%s)",n)
+        else
+            return format("FORMAT(a%s,'%%%sf')",n,f)
+        end
+    end
+
+else
+
+    format_N = function(f) -- strips leading and trailing zeros
+        n = n + 1
+        -- stripzero (singular) as we only have a number
+        if not f or f == "" then
+            f = ".9"
+        end -- always a leading number !
+        return format("(((a%s %% 1 == 0) and format('%%i',a%s)) or lpegmatch(stripzero,format('%%%sf',a%s)))",n,n,f,n)
+    end
+
 end
 
 local format_a = function(f)

Modified: trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-tab.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-tab.lua	2019-11-05 21:35:56 UTC (rev 52647)
+++ trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-tab.lua	2019-11-05 21:36:14 UTC (rev 52648)
@@ -341,7 +341,21 @@
         m = m + 1
         r[m] = "{"
         if n > 0 then
-            for i=0,n do
+            local v = t[0]
+            if v then
+                local tv = type(v)
+                if tv == "string" then
+                    m = m + 1 r[m] = f_indexed_string(0,v)
+                elseif tv == "number" then
+                    m = m + 1 r[m] = f_indexed_number(0,v)
+                elseif tv == "table" then
+                    m = m + 1 r[m] = f_indexed_table(0)
+                    fastserialize(v)
+                elseif tv == "boolean" then
+                    m = m + 1 r[m] = f_indexed_boolean(0,v)
+                end
+            end
+            for i=1,n do
                 local v  = t[i]
                 local tv = type(v)
                 if tv == "string" then
@@ -355,6 +369,8 @@
                 end
             end
         end
+        -- hm, can't we avoid this ... lua should have a way to check if there
+        -- is a hash part
         for k, v in next, t do
             local tk = type(k)
             if tk == "number" then
@@ -411,7 +427,7 @@
     return code
 end
 
--- inspect(table.fastserialize { a = 1, b = { 4, { 5, 6 } }, c = { d = 7, e = 'f"g\nh' } })
+-- inspect(table.fastserialize { a = 1, b = { [0]=4, { 5, 6 } }, c = { d = 7, e = 'f"g\nh' } })
 
 function table.load(filename,loader)
     if filename then

Modified: trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-tpl.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-tpl.lua	2019-11-05 21:35:56 UTC (rev 52647)
+++ trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-tpl.lua	2019-11-05 21:36:14 UTC (rev 52648)
@@ -20,6 +20,8 @@
 local format, sub, byte = string.format, string.sub, string.byte
 local P, C, R, Cs, Cc, Carg, lpegmatch, lpegpatterns = lpeg.P, lpeg.C, lpeg.R, lpeg.Cs, lpeg.Cc, lpeg.Carg, lpeg.match, lpeg.patterns
 
+local formatters = string.formatters
+
 -- todo: make installable template.new
 
 local replacer
@@ -133,35 +135,43 @@
     return v and v ~= "" and lpegmatch(replacer,r,1,t,how or "lua",recurse or false) or ""
 end
 
-local single      = P("%")  -- test %test% test     : resolves test
-local double      = P("%%") -- test 10%% test       : %% becomes %
-local lquoted     = P("%[") -- test '%[test]%' test : resolves to test with escaped "'s
-local rquoted     = P("]%") --
-local lquotedq    = P("%(") -- test %(test)% test   : resolves to 'test' with escaped "'s
-local rquotedq    = P(")%") --
+local function replaceformatted(l,m,r,t,how,recurse)
+    local v = t[r]
+    return v and formatters[l](v)
+end
 
-local escape      = double   / '%%'
-local nosingle    = single   / ''
-local nodouble    = double   / ''
-local nolquoted   = lquoted  / ''
-local norquoted   = rquoted  / ''
-local nolquotedq  = lquotedq / ''
-local norquotedq  = rquotedq / ''
+local single       = P("%")  -- test %test% test     : resolves test
+local double       = P("%%") -- test 10%% test       : %% becomes %
+local lquoted      = P("%[") -- test '%[test]%' test : resolves to test with escaped "'s
+local rquoted      = P("]%") --
+local lquotedq     = P("%(") -- test %(test)% test   : resolves to 'test' with escaped "'s
+local rquotedq     = P(")%") --
 
-local noloptional = P("%?") / ''
-local noroptional = P("?%") / ''
-local nomoptional = P(":")  / ''
+local escape       = double   / '%%'
+local nosingle     = single   / ''
+local nodouble     = double   / ''
+local nolquoted    = lquoted  / ''
+local norquoted    = rquoted  / ''
+local nolquotedq   = lquotedq / ''
+local norquotedq   = rquotedq / ''
 
+local nolformatted = P(":") / "%%"
+local norformatted = P(":") / ""
 
-local args        = Carg(1) * Carg(2) * Carg(3)
-local key         = nosingle    * ((C((1-nosingle   )^1) * args) / replacekey        ) * nosingle
-local quoted      = nolquotedq  * ((C((1-norquotedq )^1) * args) / replacekeyquoted  ) * norquotedq
-local unquoted    = nolquoted   * ((C((1-norquoted  )^1) * args) / replacekeyunquoted) * norquoted
-local optional    = noloptional * ((C((1-nomoptional)^1) * nomoptional * C((1-noroptional)^1) * args) / replaceoptional) *  noroptional
-local any         = P(1)
+local noloptional  = P("%?") / ''
+local noroptional  = P("?%") / ''
+local nomoptional  = P(":")  / ''
 
-      replacer    = Cs((unquoted + quoted + escape + optional + key + any)^0)
+local args         = Carg(1) * Carg(2) * Carg(3)
+local key          = nosingle * ((C((1-nosingle)^1) * args) / replacekey) * nosingle
+local quoted       = nolquotedq * ((C((1-norquotedq)^1) * args) / replacekeyquoted) * norquotedq
+local unquoted     = nolquoted * ((C((1-norquoted)^1) * args) / replacekeyunquoted) * norquoted
+local optional     = noloptional * ((C((1-nomoptional)^1) * nomoptional * C((1-noroptional)^1) * args) / replaceoptional) *  noroptional
+local formatted    = nosingle * ((Cs(nolformatted * (1-norformatted )^1) * norformatted * C((1-nosingle)^1) * args) / replaceformatted) * nosingle
+local any          = P(1)
 
+      replacer     = Cs((unquoted + quoted + formatted + escape + optional + key + any)^0)
+
 local function replace(str,mapping,how,recurse)
     if mapping and str then
         return lpegmatch(replacer,str,1,mapping,how or "lua",recurse or false) or str
@@ -179,6 +189,8 @@
 -- print(replace([[test %[x]% test]],{ x = [[a "x"  a]]}))
 -- print(replace([[test %(x)% test]],{ x = [[a "x"  a]]}))
 -- print(replace([[convert %?x: -x "%x%" ?% %?y: -y "%y%" ?%]],{ x = "yes" }))
+-- print(replace("test %:0.3N:x% test",{ x = 123.45 }))
+-- print(replace("test %:0.3N:x% test",{ x = 12345 }))
 
 templates.replace = replace
 

Modified: trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs.lua	2019-11-05 21:35:56 UTC (rev 52647)
+++ trunk/Master/texmf-dist/tex/luatex/lualibs/lualibs.lua	2019-11-05 21:36:14 UTC (rev 52648)
@@ -25,8 +25,8 @@
 
 lualibs.module_info = {
   name          = "lualibs",
-  version       = "2.67",       --TAGVERSION
-    date        = "2019-08-11", --TAGDATE
+  version       = "2.68",       --TAGVERSION
+    date        = "2019-11-05", --TAGDATE
   description   = "ConTeXt Lua standard libraries.",
   author        = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux & Philipp Gesang",
   copyright     = "PRAGMA ADE / ConTeXt Development Team",
@@ -90,7 +90,7 @@
   if not t then t = "library" end
   local filepath  = find_file(name, "lua")
   if not filepath or filepath == "" then
-    warn(stringformat("Could not locate %s ^^e2^^80^^9c%s^^e2^^80^^9d.", t, name))
+    warn(stringformat("Could not locate %s “%s”.", t, name))
     return false
   end
   dofile(filepath)



More information about the tex-live-commits mailing list