diff options
Diffstat (limited to 'Master/texmf-dist/tex/luatex/lualibs/lualibs-basic-merged.lua')
-rw-r--r-- | Master/texmf-dist/tex/luatex/lualibs/lualibs-basic-merged.lua | 294 |
1 files changed, 167 insertions, 127 deletions
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-basic-merged.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-basic-merged.lua index db130567123..d94b696b3d9 100644 --- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-basic-merged.lua +++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-basic-merged.lua @@ -1,6 +1,6 @@ -- merged file : lualibs-basic-merged.lua -- parent file : lualibs-basic.lua --- merge date : Thu Oct 18 23:57:42 2018 +-- merge date : Tue Dec 25 16:21:45 2018 do -- begin closure to overcome local limits and interference @@ -871,64 +871,6 @@ function lpeg.counter(pattern,action) return function(str) n=0;lpegmatch(pattern,str);return n end end end -utf=utf or (unicode and unicode.utf8) or {} -local utfcharacters=utf and utf.characters or string.utfcharacters -local utfgmatch=utf and utf.gmatch -local utfchar=utf and utf.char -lpeg.UP=lpeg.P -if utfcharacters then - function lpeg.US(str) - local p=P(false) - for uc in utfcharacters(str) do - p=p+P(uc) - end - return p - end -elseif utfgmatch then - function lpeg.US(str) - local p=P(false) - for uc in utfgmatch(str,".") do - p=p+P(uc) - end - return p - end -else - function lpeg.US(str) - local p=P(false) - local f=function(uc) - p=p+P(uc) - end - lpegmatch((utf8char/f)^0,str) - return p - end -end -local range=utf8byte*utf8byte+Cc(false) -function lpeg.UR(str,more) - local first,last - if type(str)=="number" then - first=str - last=more or first - else - first,last=lpegmatch(range,str) - if not last then - return P(str) - end - end - if first==last then - return P(str) - elseif utfchar and (last-first<8) then - local p=P(false) - for i=first,last do - p=p+P(utfchar(i)) - end - return p - else - local f=function(b) - return b>=first and b<=last - end - return utf8byte/f - end -end function lpeg.is_lpeg(p) return p and lpegtype(p)=="pattern" end @@ -1424,7 +1366,6 @@ local table,string=table,string local concat,sort,insert,remove=table.concat,table.sort,table.insert,table.remove local format,lower,dump=string.format,string.lower,string.dump local getmetatable,setmetatable=getmetatable,setmetatable -local getinfo=debug.getinfo local lpegmatch,patterns=lpeg.match,lpeg.patterns local floor=math.floor local stripper=patterns.stripper @@ -1986,20 +1927,23 @@ local function do_serialize(root,name,depth,level,indexed) end elseif tv=="function" then if functions then - local f=getinfo(v).what=="C" and dump(dummy) or dump(v) - if tk=="number" then - if hexify then - handle(format("%s [0x%X]=load(%q),",depth,k,f)) + local getinfo=debug and debug.getinfo + if getinfo then + local f=getinfo(v).what=="C" and dump(dummy) or dump(v) + if tk=="number" then + if hexify then + handle(format("%s [0x%X]=load(%q),",depth,k,f)) + else + handle(format("%s [%s]=load(%q),",depth,k,f)) + end + elseif tk=="boolean" then + handle(format("%s [%s]=load(%q),",depth,k and "true" or "false",f)) + elseif tk~="string" then + elseif noquotes and not reserved[k] and lpegmatch(propername,k) then + handle(format("%s %s=load(%q),",depth,k,f)) else - handle(format("%s [%s]=load(%q),",depth,k,f)) + handle(format("%s [%q]=load(%q),",depth,k,f)) end - elseif tk=="boolean" then - handle(format("%s [%s]=load(%q),",depth,k and "true" or "false",f)) - elseif tk~="string" then - elseif noquotes and not reserved[k] and lpegmatch(propername,k) then - handle(format("%s %s=load(%q),",depth,k,f)) - else - handle(format("%s [%q]=load(%q),",depth,k,f)) end end else @@ -2590,11 +2534,14 @@ if bit32 then "0","0","0","0","0","0","0","0", "0","0","0","0","0","0","0","0", } - function number.tobitstring(b,m) - local n=32 - for i=0,31 do + function number.tobitstring(b,m,w) + if not w then + w=32 + end + local n=w + for i=0,w-1 do local v=bextract(b,i) - local k=32-i + local k=w-i if v==1 then n=k t[k]="1" @@ -2602,12 +2549,14 @@ if bit32 then t[k]="0" end end - if m then + if w then + return concat(t,"",1,w) + elseif m then m=33-m*8 if m<1 then m=1 end - return concat(t,"",m) + return concat(t,"",1,m) elseif n<8 then return concat(t) elseif n<16 then @@ -3136,6 +3085,61 @@ local find,format,gsub,upper,gmatch=string.find,string.format,string.gsub,string local concat=table.concat local random,ceil,randomseed=math.random,math.ceil,math.randomseed local rawget,rawset,type,getmetatable,setmetatable,tonumber,tostring=rawget,rawset,type,getmetatable,setmetatable,tonumber,tostring +do + local selfdir=os.selfdir + if selfdir=="" then + selfdir=nil + end + if not selfdir then + if arg then + for i=1,#arg do + local a=arg[i] + if find(a,"^%-%-[c:]*texmfbinpath=") then + selfdir=gsub(a,"^.-=","") + break + end + end + end + if not selfdir then + selfdir=os.selfbin or "luatex" + if find(selfdir,"[/\\]") then + selfdir=gsub(selfdir,"[/\\][^/\\]*$","") + elseif os.getenv then + local path=os.getenv("PATH") + local name=gsub(selfdir,"^.*[/\\][^/\\]","") + local patt="[^:]+" + if os.type=="windows" then + patt="[^;]+" + name=name..".exe" + end + local isfile + if lfs then + local attributes=lfs.attributes + isfile=function(name) + local a=attributes(name,"mode") + return a=="file" or a=="link" or nil + end + else + local open=io.open + isfile=function(name) + local f=open(name) + if f then + f:close() + return true + end + end + end + for p in gmatch(path,patt) do + if isfile(p.."/"..name) then + selfdir=p + break + end + end + end + end + os.selfdir=selfdir or "." + end +end math.initialseed=tonumber(string.sub(string.reverse(tostring(ceil(socket and socket.gettime()*10000 or time()))),1,6)) randomseed(math.initialseed) if not os.__getenv__ then @@ -4551,9 +4555,14 @@ if not modules then modules={} end modules ['l-unicode']={ copyright="PRAGMA ADE / ConTeXt Development Team", license="see context related readme files" } -utf=utf or (unicode and unicode.utf8) or {} -utf.characters=utf.characters or string.utfcharacters -utf.values=utf.values or string.utfvalues +utf=utf or {} +if not string.utfcharacters then + local gmatch=string.gmatch + function string.characters(str) + return gmatch(str,".[\128-\191]*") + end +end +utf.characters=string.utfcharacters local type=type local char,byte,format,sub,gmatch=string.char,string.byte,string.format,string.sub,string.gmatch local concat=table.concat @@ -4564,19 +4573,15 @@ local tabletopattern=lpeg.utfchartabletopattern local bytepairs=string.bytepairs local finder=lpeg.finder local replacer=lpeg.replacer -local utfvalues=utf.values -local utfgmatch=utf.gmatch local p_utftype=patterns.utftype local p_utfstricttype=patterns.utfstricttype local p_utfoffset=patterns.utfoffset -local p_utf8char=patterns.utf8character +local p_utf8character=patterns.utf8character +local p_utf8char=patterns.utf8char local p_utf8byte=patterns.utf8byte local p_utfbom=patterns.utfbom local p_newline=patterns.newline local p_whitespace=patterns.whitespace -if not unicode then - unicode={ utf=utf } -end if not utf.char then utf.char=string.utfcharacter or (utf8 and utf8.char) if not utf.char then @@ -4641,9 +4646,8 @@ end if not utf.byte then utf.byte=string.utfvalue or (utf8 and utf8.codepoint) if not utf.byte then - local utf8byte=patterns.utf8byte function utf.byte(c) - return lpegmatch(utf8byte,c) + return lpegmatch(p_utf8byte,c) end end end @@ -4744,10 +4748,10 @@ if not utf.sub then return true end end - local pattern_zero=Cmt(p_utf8char,slide_zero)^0 - local pattern_one=Cmt(p_utf8char,slide_one )^0 - local pattern_two=Cmt(p_utf8char,slide_two )^0 - local pattern_first=C(patterns.utf8character) + local pattern_zero=Cmt(p_utf8character,slide_zero)^0 + local pattern_one=Cmt(p_utf8character,slide_one )^0 + local pattern_two=Cmt(p_utf8character,slide_two )^0 + local pattern_first=C(p_utf8character) function utf.sub(str,start,stop) if not start then return str @@ -4822,15 +4826,15 @@ function utf.remapper(mapping,option,action) return "" else if not pattern then - pattern=Cs((tabletopattern(mapping)/action+p_utf8char)^0) + pattern=Cs((tabletopattern(mapping)/action+p_utf8character)^0) end return lpegmatch(pattern,str) end end elseif option=="pattern" then - return Cs((tabletopattern(mapping)/action+p_utf8char)^0) + return Cs((tabletopattern(mapping)/action+p_utf8character)^0) else - local pattern=Cs((tabletopattern(mapping)/action+p_utf8char)^0) + local pattern=Cs((tabletopattern(mapping)/action+p_utf8character)^0) return function(str) if not str or str=="" then return "" @@ -4841,9 +4845,9 @@ function utf.remapper(mapping,option,action) end elseif variant=="function" then if option=="pattern" then - return Cs((p_utf8char/mapping+p_utf8char)^0) + return Cs((p_utf8character/mapping+p_utf8character)^0) else - local pattern=Cs((p_utf8char/mapping+p_utf8char)^0) + local pattern=Cs((p_utf8character/mapping+p_utf8character)^0) return function(str) if not str or str=="" then return "" @@ -4879,9 +4883,9 @@ function utf.subtituter(t) end end local utflinesplitter=p_utfbom^-1*lpeg.tsplitat(p_newline) -local utfcharsplitter_ows=p_utfbom^-1*Ct(C(p_utf8char)^0) -local utfcharsplitter_iws=p_utfbom^-1*Ct((p_whitespace^1+C(p_utf8char))^0) -local utfcharsplitter_raw=Ct(C(p_utf8char)^0) +local utfcharsplitter_ows=p_utfbom^-1*Ct(C(p_utf8character)^0) +local utfcharsplitter_iws=p_utfbom^-1*Ct((p_whitespace^1+C(p_utf8character))^0) +local utfcharsplitter_raw=Ct(C(p_utf8character)^0) patterns.utflinesplitter=utflinesplitter function utf.splitlines(str) return lpegmatch(utflinesplitter,str or "") @@ -4918,7 +4922,7 @@ local more=0 local p_utf16_to_utf8_be=C(1)*C(1)/function(left,right) local now=256*byte(left)+byte(right) if more>0 then - now=(more-0xD800)*0x400+(now-0xDC00)+0x10000 + now=(more-0xD800)*0x400+(now-0xDC00)+0x10000 more=0 return utfchar(now) elseif now>=0xD800 and now<=0xDBFF then @@ -4931,7 +4935,7 @@ end local p_utf16_to_utf8_le=C(1)*C(1)/function(right,left) local now=256*byte(left)+byte(right) if more>0 then - now=(more-0xD800)*0x400+(now-0xDC00)+0x10000 + now=(more-0xD800)*0x400+(now-0xDC00)+0x10000 more=0 return utfchar(now) elseif now>=0xD800 and now<=0xDBFF then @@ -5128,20 +5132,8 @@ function utf.toeight(str) return str end end -local p_nany=p_utf8char/"" -if utfgmatch then - function utf.count(str,what) - if type(what)=="string" then - local n=0 - for _ in utfgmatch(str,what) do - n=n+1 - end - return n - else - return #lpegmatch(Cs((P(what)/" "+p_nany)^0),str) - end - end -else +do + local p_nany=p_utf8character/"" local cache={} function utf.count(str,what) if type(what)=="string" then @@ -5156,17 +5148,11 @@ else end end end -if not utf.characters then - function utf.characters(str) - return gmatch(str,".[\128-\191]*") - end - string.utfcharacters=utf.characters -end -if not utf.values then +if not string.utfvalues then local find=string.find local dummy=function() end - function utf.values(str) + function string.utfvalues(str) local n=#str if n==0 then return dummy @@ -5183,8 +5169,8 @@ if not utf.values then end end end - string.utfvalues=utf.values end +utf.values=string.utfvalues function utf.chrlen(u) return (u<0x80 and 1) or @@ -5197,7 +5183,7 @@ end if bit32 then local extract=bit32.extract local char=string.char - function unicode.toutf32string(n) + function utf.toutf32string(n) if n<=0xFF then return char(n).."\000\000\000" @@ -5232,6 +5218,60 @@ function string.utfpadd(s,n) end return s end +do + local utfcharacters=utf.characters or string.utfcharacters + local utfchar=utf.char or string.utfcharacter + lpeg.UP=P + if utfcharacters then + function lpeg.US(str) + local p=P(false) + for uc in utfcharacters(str) do + p=p+P(uc) + end + return p + end + else + function lpeg.US(str) + local p=P(false) + local f=function(uc) + p=p+P(uc) + end + lpegmatch((p_utf8char/f)^0,str) + return p + end + end + local range=p_utf8byte*p_utf8byte+Cc(false) + function lpeg.UR(str,more) + local first,last + if type(str)=="number" then + first=str + last=more or first + else + first,last=lpegmatch(range,str) + if not last then + return P(str) + end + end + if first==last then + return P(str) + end + if not utfchar then + utfchar=utf.char + end + if utfchar and (last-first<8) then + local p=P(false) + for i=first,last do + p=p+P(utfchar(i)) + end + return p + else + local f=function(b) + return b>=first and b<=last + end + return p_utf8byte/f + end + end +end end -- closure |