diff options
author | Marius <mariausol@gmail.com> | 2013-04-17 18:40:27 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2013-04-17 18:40:27 +0300 |
commit | afecddbdf8473a0cd3b9b9107d6fb4cd991224a5 (patch) | |
tree | dcfcb24a9918b9dcaa9569955442bdc16d3ba568 | |
parent | 2bce12e0c387ba3a0e084bf0c44c23af1f93642e (diff) | |
download | context-afecddbdf8473a0cd3b9b9107d6fb4cd991224a5.tar.gz |
beta 2013.04.17 17:29
23 files changed, 1336 insertions, 918 deletions
diff --git a/scripts/context/lua/mtxlibs.lua b/scripts/context/lua/mtxlibs.lua index 60889acde..a34ba139a 100644 --- a/scripts/context/lua/mtxlibs.lua +++ b/scripts/context/lua/mtxlibs.lua @@ -68,6 +68,7 @@ local owntree = ownpath local ownlibs = { "l-lua.lua", + "l-package.lua", "l-lpeg.lua", "l-function.lua", "l-string.lua", diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index ae08dc556..7f1464fbc 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -56,7 +56,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-lua"] = package.loaded["l-lua"] or true --- original size: 10352, stripped down to: 5955 +-- original size: 3123, stripped down to: 1694 if not modules then modules={} end modules ['l-lua']={ version=1.001, @@ -136,51 +136,108 @@ function optionalrequire(...) return result end end + + +end -- of closure + +do -- create closure to overcome 200 locals limit + +package.loaded["l-package"] = package.loaded["l-package"] or true + +-- original size: 9641, stripped down to: 7101 + +if not modules then modules={} end modules ['l-package']={ + 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 type=type local gsub,format=string.gsub,string.format +local P,S,Cs,lpegmatch=lpeg.P,lpeg.S,lpeg.Cs,lpeg.match local package=package local searchers=package.searchers or package.loaders -local libpaths=nil -local clibpaths=nil -local libhash={} -local clibhash={} -local libextras={} -local clibextras={} local filejoin=file and file.join or function(path,name) return path.."/"..name end local isreadable=file and file.is_readable or function(name) local f=io.open(name) if f then f:close() return true end end local addsuffix=file and file.addsuffix or function(name,suffix) return name.."."..suffix end local function cleanpath(path) return path end +local pattern=Cs((((1-S("\\/"))^0*(S("\\/")^1/"/"))^0*(P(".")^1/"/"+P(1))^1)*-1) +local function lualibfile(name) + return lpegmatch(pattern,name) or name +end local helpers=package.helpers or { - libpaths=function() return {} end, - clibpaths=function() return {} end, cleanpath=cleanpath, + lualibfile=lualibfile, trace=false, report=function(...) print(format(...)) end, + builtin={ + ["preload table"]=package.searchers[1], + ["path specification"]=package.searchers[2], + ["cpath specification"]=package.searchers[3], + ["all in one fallback"]=package.searchers[4], + }, + methods={}, + sequence={ + "already loaded", + "preload table", + "lua extra list", + "lib extra list", + "path specification", + "cpath specification", + "all in one fallback", + "not loaded", + } } package.helpers=helpers -local function getlibpaths() - return libpaths or helpers.libpaths(libhash) +local methods=helpers.methods +local builtin=helpers.builtin +local extraluapaths={} +local extralibpaths={} +local luapaths=nil +local libpaths=nil +local function getextraluapaths() + return extraluapaths +end +local function getextralibpaths() + return extralibpaths +end +local function getluapaths() + luapaths=luapaths or file.splitpath(package.path,";") + return luapaths end -local function getclibpaths() - return clibpaths or helpers.clibpaths(clibhash) +local function getlibpaths() + libpaths=libpaths or file.splitpath(package.cpath,";") + return libpaths end +package.luapaths=getluapaths package.libpaths=getlibpaths -package.clibpaths=getclibpaths -local function addpath(what,paths,extras,hash,...) +package.extraluapaths=getextraluapaths +package.extralibpaths=getextralibpaths +local hashes={ + lua={}, + lib={}, +} +local function registerpath(tag,what,target,...) local pathlist={... } local cleanpath=helpers.cleanpath local trace=helpers.trace local report=helpers.report + local hash=hashes[what] local function add(path) local path=cleanpath(path) if not hash[path] then + target[#target+1]=path + hash[path]=true + if trace then + report("registered %s path %s: %s",tag,#target,path) + end + else if trace then - report("extra %s path: %s",what,path) + report("duplicate %s path: %s",tag,path) end - paths [#paths+1]=path - extras[#extras+1]=path end end for p=1,#pathlist do @@ -193,21 +250,15 @@ local function addpath(what,paths,extras,hash,...) add(path) end end - return paths,extras + return paths end -function package.extralibpath(...) - libpaths,libextras=addpath("lua",getlibpaths(),libextras,libhash,...) -end -function package.extraclibpath(...) - clibpaths,clibextras=addpath("lib",getclibpaths(),clibextras,clibhash,...) +helpers.registerpath=registerpath +function package.extraluapath(...) + registerpath("extra lua","lua",extraluapaths,...) end -if not searchers[-2] then - searchers[-2]=searchers[2] -end -searchers[2]=function(name) - return helpers.loaded(name) +function package.extralibpath(...) + registerpath("extra lib","lib",extralibpaths,...) end -searchers[3]=nil local function loadedaslib(resolved,rawname) local init="luaopen_"..gsub(rawname,"%.","_") if helpers.trace then @@ -215,12 +266,7 @@ local function loadedaslib(resolved,rawname) end return package.loadlib(resolved,init) end -local function loadedbylua(name) - if helpers.trace then - helpers.report("locating '%s' using normal loader",name) - end - return true,searchers[-2](name) -end +helpers.loadedaslib=loadedaslib local function loadedbypath(name,rawname,paths,islib,what) local trace=helpers.trace local report=helpers.report @@ -231,63 +277,135 @@ local function loadedbypath(name,rawname,paths,islib,what) local path=paths[p] local resolved=filejoin(path,name) if trace then - report("checking for '%s' using '%s' path '%s'",name,what,path) + report("checking '%s' using '%s' path '%s'",name,what,path) end if isreadable(resolved) then if trace then - report("lib '%s' located on '%s'",name,resolved) + report("'%s' located on '%s'",name,resolved) end + local result=nil if islib then - return true,loadedaslib(resolved,rawname) + result=loadedaslib(resolved,rawname) else - return true,loadfile(resolved) + result=loadfile(resolved) + end + if result then + result() end + return true,result end end end -local function notloaded(name) - if helpers.trace then - helpers.report("unable to locate library '%s'",name) +helpers.loadedbypath=loadedbypath +methods["already loaded"]=function(name) + local result=package.loaded[name] + if result then + return true,result end end -helpers.loadedaslib=loadedaslib -helpers.loadedbylua=loadedbylua -helpers.loadedbypath=loadedbypath -helpers.notloaded=notloaded -function helpers.loaded(name) - local thename=gsub(name,"%.","/") +methods["preload table"]=function(name) + local result=builtin["preload table"](name) + if type(result)=="function" then + return true,result + end +end +methods["lua extra list"]=function(name) + local thename=lualibfile(name) local luaname=addsuffix(thename,"lua") - local libname=addsuffix(thename,os.libsuffix or "so") - local libpaths=getlibpaths() - local clibpaths=getclibpaths() - local done,result=loadedbypath(luaname,name,libpaths,false,"lua") + local luapaths=getextraluapaths() + local done,result=loadedbypath(luaname,name,luapaths,false,"lua") if done then - return result + return true,result end - local done,result=loadedbypath(luaname,name,clibpaths,false,"lua") +end +methods["lib extra list"]=function(name) + local thename=lualibfile(name) + local libname=addsuffix(thename,os.libsuffix) + local libpaths=getextralibpaths() + local done,result=loadedbypath(libname,name,libpaths,true,"lib") if done then - return result + return true,result end - local done,result=loadedbypath(libname,name,clibpaths,true,"lib") - if done then - return result +end +local shown=false +methods["path specification"]=function(name) + if not shown and helpers.trace then + local luapaths=getluapaths() + if #luapaths>0 then + helpers.report("using %s built in lua paths",#luapaths) + else + helpers.report("no built in lua paths defined") + end + shown=true end - local done,result=loadedbylua(name) - if done then - return result + local result=builtin["path specification"](name) + if type(result)=="function" then + return true,result() + end +end +local shown=false +methods["cpath specification"]=function(name) + if not shown and helpers.trace then + local libpaths=getlibpaths() + if #libpaths>0 then + helpers.report("using %s built in lib paths",#libpaths) + else + helpers.report("no built in lib paths defined") + end + shown=true + end + local result=builtin["cpath specification"](name) + if type(result)=="function" then + return true,result() + end +end +methods["all in one fallback"]=function(name) + local result=builtin["all in one fallback"](name) + if type(result)=="function" then + return true,result() + end +end +methods["not loaded"]=function(name) + if helpers.trace then + helpers.report("unable to locate '%s'",name) + end +end +function helpers.loaded(name) + local sequence=helpers.sequence + for i=1,#sequence do + local step=sequence[i] + if helpers.trace then + helpers.report("locating '%s' using method '%s'",name,step) + end + local done,result=methods[step](name) + if done then + if helpers.trace then + helpers.report("'%s' located via method '%s' returns '%s'",name,step,type(result)) + end + if result then + package.loaded[name]=result + end + return result + end end - return notloaded(name) + return nil end function helpers.unload(name) if helpers.trace then if package.loaded[name] then - helpers.report("unloading library '%s', %s",name,"done") + helpers.report("unloading '%s', %s",name,"done") else - helpers.report("unloading library '%s', %s",name,"not loaded") + helpers.report("unloading '%s', %s",name,"not loaded") end end - package.loaded[name]=nil + package.loaded[name]=nil end +searchers[1]=nil +searchers[2]=nil +searchers[3]=nil +searchers[4]=nil +helpers.savedrequire=helpers.savedrequire or require +require=helpers.loaded end -- of closure @@ -15113,7 +15231,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-lua"] = package.loaded["data-lua"] or true --- original size: 4861, stripped down to: 3693 +-- original size: 5080, stripped down to: 3874 if not modules then modules={} end modules ['data-lua']={ version=1.001, @@ -15127,52 +15245,56 @@ local gsub=string.gsub local concat=table.concat local addsuffix=file.addsuffix local P,S,Cs,lpegmatch=lpeg.P,lpeg.S,lpeg.Cs,lpeg.match -local libsuffixes={ 'tex','lua' } -local clibsuffixes={ 'lib' } -local libformats={ 'TEXINPUTS','LUAINPUTS' } -local clibformats={ 'CLUAINPUTS' } -local helpers=package.helpers +local luasuffixes={ 'tex','lua' } +local libsuffixes={ 'lib' } +local luaformats={ 'TEXINPUTS','LUAINPUTS' } +local libformats={ 'CLUAINPUTS' } +local helpers=package.helpers or {} +local methods=helpers.methods or {} trackers.register("resolvers.libraries",function(v) helpers.trace=v end) trackers.register("resolvers.locating",function(v) helpers.trace=v end) helpers.report=logs.reporter("resolvers","libraries") +helpers.sequence={ + "already loaded", + "preload table", + "lua variable format", + "lib variable format", + "lua extra list", + "lib extra list", + "path specification", + "cpath specification", + "all in one fallback", + "not loaded", +} local pattern=Cs(P("!")^0/""*(P("/")*P(-1)/"/"+P("/")^1/"/"+1)^0) -local function cleanpath(path) +function helpers.cleanpath(path) return resolvers.resolve(lpegmatch(pattern,path)) end -helpers.cleanpath=cleanpath local loadedaslib=helpers.loadedaslib -local loadedbylua=helpers.loadedbylua local loadedbypath=helpers.loadedbypath -local notloaded=helpers.notloaded -local getlibpaths=package.libpaths -local getclibpaths=package.clibpaths -function helpers.libpaths(libhash) - local libpaths={} - for i=1,#libformats do - local paths=resolvers.expandedpathlistfromvariable(libformats[i]) - for i=1,#paths do - local path=cleanpath(paths[i]) - if not libhash[path] then - libpaths[#libpaths+1]=path - libhash[path]=true - end +local getextraluapaths=package.extraluapaths +local getextralibpaths=package.extralibpaths +local registerpath=helpers.registerpath +local lualibfile=helpers.lualibfile +local luaformatpaths +local libformatpaths +local function getluaformatpaths() + if not luaformatpaths then + luaformatpaths={} + for i=1,#luaformats do + registerpath("lua format","lua",luaformatpaths,resolvers.expandedpathlistfromvariable(luaformats[i])) end end - return libpaths + return luaformatpaths end -function helpers.clibpaths(clibhash) - local clibpaths={} - for i=1,#clibformats do - local paths=resolvers.expandedpathlistfromvariable(clibformats[i]) - for i=1,#paths do - local path=cleanpath(paths[i]) - if not clibhash[path] then - clibpaths[#clibpaths+1]=path - clibhash[path]=true - end +local function getlibformatpaths() + if not libformatpaths then + libformatpaths={} + for i=1,#libformats do + registerpath("lib format","lib",libformatpaths,resolvers.expandedpathlistfromvariable(libformats[i])) end end - return clibpaths + return libformatpaths end local function loadedbyformat(name,rawname,suffixes,islib) local trace=helpers.trace @@ -15190,51 +15312,54 @@ local function loadedbyformat(name,rawname,suffixes,islib) if trace then report("lib %a located on %a",name,resolved) end + local result=nil if islib then - return true,loadedaslib(resolved,rawname) + result=loadedaslib(resolved,rawname) else - return true,loadfile(resolved) + result=loadfile(resolved) + end + if result then + return true,result() end end end end helpers.loadedbyformat=loadedbyformat -local pattern=Cs((((1-S("\\/"))^0*(S("\\/")^1/"/"))^0*(P(".")^1/"/"+P(1))^1)*-1) -local function lualibfile(name) - return lpegmatch(pattern,name) or name -end -helpers.lualibfile=lualibfile -function helpers.loaded(name) +local shown=false +methods["lua variable format"]=function(name) + if not shown and helpers.trace then + local luapaths=getluaformatpaths() + if #luapaths>0 then + helpers.report("using %s lua format paths",#luapaths) + else + helpers.report("no lua format paths defined") + end + shown=true + end local thename=lualibfile(name) local luaname=addsuffix(thename,"lua") - local libname=addsuffix(thename,os.libsuffix) - local libpaths=getlibpaths() - local clibpaths=getclibpaths() - local done,result=loadedbyformat(luaname,name,libsuffixes,false) + local done,result=loadedbyformat(luaname,name,luasuffixes,false) if done then - return result + return true,result end - local done,result=loadedbyformat(libname,name,clibsuffixes,true) - if done then - return result - end - local done,result=loadedbypath(luaname,name,libpaths,false,"lua") - if done then - return result - end - local done,result=loadedbypath(luaname,name,clibpaths,false,"lua") - if done then - return result - end - local done,result=loadedbypath(libname,name,clibpaths,true,"lib") - if done then - return result +end +local shown=false +methods["lib variable format"]=function(name) + if not shown and helpers.trace then + local libpaths=getlibformatpaths() + if #libpaths>0 then + helpers.report("using %s lib format paths",#libpaths) + else + helpers.report("no lib format paths defined") + end + shown=true end - local done,result=loadedbylua(name) + local thename=lualibfile(name) + local libname=addsuffix(thename,os.libsuffix) + local done,result=loadedbyformat(libname,name,libsuffixes,true) if done then - return result + return true,result end - return notloaded(name) end resolvers.loadlualib=require @@ -15445,7 +15570,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-lib"] = package.loaded["util-lib"] or true --- original size: 10985, stripped down to: 5458 +-- original size: 11094, stripped down to: 5516 if not modules then modules={} end modules ['util-lib']={ version=1.001, @@ -15462,16 +15587,17 @@ local report_swiglib=logs.reporter("swiglib") local trace_swiglib=false trackers.register("resolvers.swiglib",function(v) trace_swiglib=v end) local done=false local function requireswiglib(required,version) + local trace_swiglib=trace_swiglib or package.helpers.trace local library=loaded[required] if library==nil then - local required_full=gsub(required,"%.","/") + local required_full=gsub(required,"%.","/") local required_path=pathpart(required_full) local required_base=nameonly(required_full) local required_name=required_base.."."..os.libsuffix local version=type(version)=="string" and version~="" and version or false local engine=environment.ownmain or false if trace_swiglib and not done then - local list=resolvers.expandedpathlistfromvariable("lib") + local list=resolvers.expandedpathlistfromvariable("lib") for i=1,#list do report_swiglib("tds path %i: %s",i,list[i]) end @@ -15553,7 +15679,7 @@ local function requireswiglib(required,version) end if not found_library then if trace_swiglib then - report_swiglib("not found: %a",asked_library) + report_swiglib("not found: %a",required) end library=false else @@ -15854,10 +15980,10 @@ end end -- of closure --- used libraries : l-lua.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-mrg.lua util-tpl.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua +-- used libraries : l-lua.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-mrg.lua util-tpl.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua -- skipped libraries : - --- original bytes : 662959 --- stripped bytes : 243507 +-- original bytes : 665699 +-- stripped bytes : 243168 -- end library merge @@ -15881,6 +16007,7 @@ local owntree = environment and environment.ownpath or ownpath local ownlibs = { -- order can be made better 'l-lua.lua', + 'l-package.lua', 'l-lpeg.lua', 'l-function.lua', 'l-string.lua', diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index ae08dc556..7f1464fbc 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -56,7 +56,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-lua"] = package.loaded["l-lua"] or true --- original size: 10352, stripped down to: 5955 +-- original size: 3123, stripped down to: 1694 if not modules then modules={} end modules ['l-lua']={ version=1.001, @@ -136,51 +136,108 @@ function optionalrequire(...) return result end end + + +end -- of closure + +do -- create closure to overcome 200 locals limit + +package.loaded["l-package"] = package.loaded["l-package"] or true + +-- original size: 9641, stripped down to: 7101 + +if not modules then modules={} end modules ['l-package']={ + 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 type=type local gsub,format=string.gsub,string.format +local P,S,Cs,lpegmatch=lpeg.P,lpeg.S,lpeg.Cs,lpeg.match local package=package local searchers=package.searchers or package.loaders -local libpaths=nil -local clibpaths=nil -local libhash={} -local clibhash={} -local libextras={} -local clibextras={} local filejoin=file and file.join or function(path,name) return path.."/"..name end local isreadable=file and file.is_readable or function(name) local f=io.open(name) if f then f:close() return true end end local addsuffix=file and file.addsuffix or function(name,suffix) return name.."."..suffix end local function cleanpath(path) return path end +local pattern=Cs((((1-S("\\/"))^0*(S("\\/")^1/"/"))^0*(P(".")^1/"/"+P(1))^1)*-1) +local function lualibfile(name) + return lpegmatch(pattern,name) or name +end local helpers=package.helpers or { - libpaths=function() return {} end, - clibpaths=function() return {} end, cleanpath=cleanpath, + lualibfile=lualibfile, trace=false, report=function(...) print(format(...)) end, + builtin={ + ["preload table"]=package.searchers[1], + ["path specification"]=package.searchers[2], + ["cpath specification"]=package.searchers[3], + ["all in one fallback"]=package.searchers[4], + }, + methods={}, + sequence={ + "already loaded", + "preload table", + "lua extra list", + "lib extra list", + "path specification", + "cpath specification", + "all in one fallback", + "not loaded", + } } package.helpers=helpers -local function getlibpaths() - return libpaths or helpers.libpaths(libhash) +local methods=helpers.methods +local builtin=helpers.builtin +local extraluapaths={} +local extralibpaths={} +local luapaths=nil +local libpaths=nil +local function getextraluapaths() + return extraluapaths +end +local function getextralibpaths() + return extralibpaths +end +local function getluapaths() + luapaths=luapaths or file.splitpath(package.path,";") + return luapaths end -local function getclibpaths() - return clibpaths or helpers.clibpaths(clibhash) +local function getlibpaths() + libpaths=libpaths or file.splitpath(package.cpath,";") + return libpaths end +package.luapaths=getluapaths package.libpaths=getlibpaths -package.clibpaths=getclibpaths -local function addpath(what,paths,extras,hash,...) +package.extraluapaths=getextraluapaths +package.extralibpaths=getextralibpaths +local hashes={ + lua={}, + lib={}, +} +local function registerpath(tag,what,target,...) local pathlist={... } local cleanpath=helpers.cleanpath local trace=helpers.trace local report=helpers.report + local hash=hashes[what] local function add(path) local path=cleanpath(path) if not hash[path] then + target[#target+1]=path + hash[path]=true + if trace then + report("registered %s path %s: %s",tag,#target,path) + end + else if trace then - report("extra %s path: %s",what,path) + report("duplicate %s path: %s",tag,path) end - paths [#paths+1]=path - extras[#extras+1]=path end end for p=1,#pathlist do @@ -193,21 +250,15 @@ local function addpath(what,paths,extras,hash,...) add(path) end end - return paths,extras + return paths end -function package.extralibpath(...) - libpaths,libextras=addpath("lua",getlibpaths(),libextras,libhash,...) -end -function package.extraclibpath(...) - clibpaths,clibextras=addpath("lib",getclibpaths(),clibextras,clibhash,...) +helpers.registerpath=registerpath +function package.extraluapath(...) + registerpath("extra lua","lua",extraluapaths,...) end -if not searchers[-2] then - searchers[-2]=searchers[2] -end -searchers[2]=function(name) - return helpers.loaded(name) +function package.extralibpath(...) + registerpath("extra lib","lib",extralibpaths,...) end -searchers[3]=nil local function loadedaslib(resolved,rawname) local init="luaopen_"..gsub(rawname,"%.","_") if helpers.trace then @@ -215,12 +266,7 @@ local function loadedaslib(resolved,rawname) end return package.loadlib(resolved,init) end -local function loadedbylua(name) - if helpers.trace then - helpers.report("locating '%s' using normal loader",name) - end - return true,searchers[-2](name) -end +helpers.loadedaslib=loadedaslib local function loadedbypath(name,rawname,paths,islib,what) local trace=helpers.trace local report=helpers.report @@ -231,63 +277,135 @@ local function loadedbypath(name,rawname,paths,islib,what) local path=paths[p] local resolved=filejoin(path,name) if trace then - report("checking for '%s' using '%s' path '%s'",name,what,path) + report("checking '%s' using '%s' path '%s'",name,what,path) end if isreadable(resolved) then if trace then - report("lib '%s' located on '%s'",name,resolved) + report("'%s' located on '%s'",name,resolved) end + local result=nil if islib then - return true,loadedaslib(resolved,rawname) + result=loadedaslib(resolved,rawname) else - return true,loadfile(resolved) + result=loadfile(resolved) + end + if result then + result() end + return true,result end end end -local function notloaded(name) - if helpers.trace then - helpers.report("unable to locate library '%s'",name) +helpers.loadedbypath=loadedbypath +methods["already loaded"]=function(name) + local result=package.loaded[name] + if result then + return true,result end end -helpers.loadedaslib=loadedaslib -helpers.loadedbylua=loadedbylua -helpers.loadedbypath=loadedbypath -helpers.notloaded=notloaded -function helpers.loaded(name) - local thename=gsub(name,"%.","/") +methods["preload table"]=function(name) + local result=builtin["preload table"](name) + if type(result)=="function" then + return true,result + end +end +methods["lua extra list"]=function(name) + local thename=lualibfile(name) local luaname=addsuffix(thename,"lua") - local libname=addsuffix(thename,os.libsuffix or "so") - local libpaths=getlibpaths() - local clibpaths=getclibpaths() - local done,result=loadedbypath(luaname,name,libpaths,false,"lua") + local luapaths=getextraluapaths() + local done,result=loadedbypath(luaname,name,luapaths,false,"lua") if done then - return result + return true,result end - local done,result=loadedbypath(luaname,name,clibpaths,false,"lua") +end +methods["lib extra list"]=function(name) + local thename=lualibfile(name) + local libname=addsuffix(thename,os.libsuffix) + local libpaths=getextralibpaths() + local done,result=loadedbypath(libname,name,libpaths,true,"lib") if done then - return result + return true,result end - local done,result=loadedbypath(libname,name,clibpaths,true,"lib") - if done then - return result +end +local shown=false +methods["path specification"]=function(name) + if not shown and helpers.trace then + local luapaths=getluapaths() + if #luapaths>0 then + helpers.report("using %s built in lua paths",#luapaths) + else + helpers.report("no built in lua paths defined") + end + shown=true end - local done,result=loadedbylua(name) - if done then - return result + local result=builtin["path specification"](name) + if type(result)=="function" then + return true,result() + end +end +local shown=false +methods["cpath specification"]=function(name) + if not shown and helpers.trace then + local libpaths=getlibpaths() + if #libpaths>0 then + helpers.report("using %s built in lib paths",#libpaths) + else + helpers.report("no built in lib paths defined") + end + shown=true + end + local result=builtin["cpath specification"](name) + if type(result)=="function" then + return true,result() + end +end +methods["all in one fallback"]=function(name) + local result=builtin["all in one fallback"](name) + if type(result)=="function" then + return true,result() + end +end +methods["not loaded"]=function(name) + if helpers.trace then + helpers.report("unable to locate '%s'",name) + end +end +function helpers.loaded(name) + local sequence=helpers.sequence + for i=1,#sequence do + local step=sequence[i] + if helpers.trace then + helpers.report("locating '%s' using method '%s'",name,step) + end + local done,result=methods[step](name) + if done then + if helpers.trace then + helpers.report("'%s' located via method '%s' returns '%s'",name,step,type(result)) + end + if result then + package.loaded[name]=result + end + return result + end end - return notloaded(name) + return nil end function helpers.unload(name) if helpers.trace then if package.loaded[name] then - helpers.report("unloading library '%s', %s",name,"done") + helpers.report("unloading '%s', %s",name,"done") else - helpers.report("unloading library '%s', %s",name,"not loaded") + helpers.report("unloading '%s', %s",name,"not loaded") end end - package.loaded[name]=nil + package.loaded[name]=nil end +searchers[1]=nil +searchers[2]=nil +searchers[3]=nil +searchers[4]=nil +helpers.savedrequire=helpers.savedrequire or require +require=helpers.loaded end -- of closure @@ -15113,7 +15231,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-lua"] = package.loaded["data-lua"] or true --- original size: 4861, stripped down to: 3693 +-- original size: 5080, stripped down to: 3874 if not modules then modules={} end modules ['data-lua']={ version=1.001, @@ -15127,52 +15245,56 @@ local gsub=string.gsub local concat=table.concat local addsuffix=file.addsuffix local P,S,Cs,lpegmatch=lpeg.P,lpeg.S,lpeg.Cs,lpeg.match -local libsuffixes={ 'tex','lua' } -local clibsuffixes={ 'lib' } -local libformats={ 'TEXINPUTS','LUAINPUTS' } -local clibformats={ 'CLUAINPUTS' } -local helpers=package.helpers +local luasuffixes={ 'tex','lua' } +local libsuffixes={ 'lib' } +local luaformats={ 'TEXINPUTS','LUAINPUTS' } +local libformats={ 'CLUAINPUTS' } +local helpers=package.helpers or {} +local methods=helpers.methods or {} trackers.register("resolvers.libraries",function(v) helpers.trace=v end) trackers.register("resolvers.locating",function(v) helpers.trace=v end) helpers.report=logs.reporter("resolvers","libraries") +helpers.sequence={ + "already loaded", + "preload table", + "lua variable format", + "lib variable format", + "lua extra list", + "lib extra list", + "path specification", + "cpath specification", + "all in one fallback", + "not loaded", +} local pattern=Cs(P("!")^0/""*(P("/")*P(-1)/"/"+P("/")^1/"/"+1)^0) -local function cleanpath(path) +function helpers.cleanpath(path) return resolvers.resolve(lpegmatch(pattern,path)) end -helpers.cleanpath=cleanpath local loadedaslib=helpers.loadedaslib -local loadedbylua=helpers.loadedbylua local loadedbypath=helpers.loadedbypath -local notloaded=helpers.notloaded -local getlibpaths=package.libpaths -local getclibpaths=package.clibpaths -function helpers.libpaths(libhash) - local libpaths={} - for i=1,#libformats do - local paths=resolvers.expandedpathlistfromvariable(libformats[i]) - for i=1,#paths do - local path=cleanpath(paths[i]) - if not libhash[path] then - libpaths[#libpaths+1]=path - libhash[path]=true - end +local getextraluapaths=package.extraluapaths +local getextralibpaths=package.extralibpaths +local registerpath=helpers.registerpath +local lualibfile=helpers.lualibfile +local luaformatpaths +local libformatpaths +local function getluaformatpaths() + if not luaformatpaths then + luaformatpaths={} + for i=1,#luaformats do + registerpath("lua format","lua",luaformatpaths,resolvers.expandedpathlistfromvariable(luaformats[i])) end end - return libpaths + return luaformatpaths end -function helpers.clibpaths(clibhash) - local clibpaths={} - for i=1,#clibformats do - local paths=resolvers.expandedpathlistfromvariable(clibformats[i]) - for i=1,#paths do - local path=cleanpath(paths[i]) - if not clibhash[path] then - clibpaths[#clibpaths+1]=path - clibhash[path]=true - end +local function getlibformatpaths() + if not libformatpaths then + libformatpaths={} + for i=1,#libformats do + registerpath("lib format","lib",libformatpaths,resolvers.expandedpathlistfromvariable(libformats[i])) end end - return clibpaths + return libformatpaths end local function loadedbyformat(name,rawname,suffixes,islib) local trace=helpers.trace @@ -15190,51 +15312,54 @@ local function loadedbyformat(name,rawname,suffixes,islib) if trace then report("lib %a located on %a",name,resolved) end + local result=nil if islib then - return true,loadedaslib(resolved,rawname) + result=loadedaslib(resolved,rawname) else - return true,loadfile(resolved) + result=loadfile(resolved) + end + if result then + return true,result() end end end end helpers.loadedbyformat=loadedbyformat -local pattern=Cs((((1-S("\\/"))^0*(S("\\/")^1/"/"))^0*(P(".")^1/"/"+P(1))^1)*-1) -local function lualibfile(name) - return lpegmatch(pattern,name) or name -end -helpers.lualibfile=lualibfile -function helpers.loaded(name) +local shown=false +methods["lua variable format"]=function(name) + if not shown and helpers.trace then + local luapaths=getluaformatpaths() + if #luapaths>0 then + helpers.report("using %s lua format paths",#luapaths) + else + helpers.report("no lua format paths defined") + end + shown=true + end local thename=lualibfile(name) local luaname=addsuffix(thename,"lua") - local libname=addsuffix(thename,os.libsuffix) - local libpaths=getlibpaths() - local clibpaths=getclibpaths() - local done,result=loadedbyformat(luaname,name,libsuffixes,false) + local done,result=loadedbyformat(luaname,name,luasuffixes,false) if done then - return result + return true,result end - local done,result=loadedbyformat(libname,name,clibsuffixes,true) - if done then - return result - end - local done,result=loadedbypath(luaname,name,libpaths,false,"lua") - if done then - return result - end - local done,result=loadedbypath(luaname,name,clibpaths,false,"lua") - if done then - return result - end - local done,result=loadedbypath(libname,name,clibpaths,true,"lib") - if done then - return result +end +local shown=false +methods["lib variable format"]=function(name) + if not shown and helpers.trace then + local libpaths=getlibformatpaths() + if #libpaths>0 then + helpers.report("using %s lib format paths",#libpaths) + else + helpers.report("no lib format paths defined") + end + shown=true end - local done,result=loadedbylua(name) + local thename=lualibfile(name) + local libname=addsuffix(thename,os.libsuffix) + local done,result=loadedbyformat(libname,name,libsuffixes,true) if done then - return result + return true,result end - return notloaded(name) end resolvers.loadlualib=require @@ -15445,7 +15570,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-lib"] = package.loaded["util-lib"] or true --- original size: 10985, stripped down to: 5458 +-- original size: 11094, stripped down to: 5516 if not modules then modules={} end modules ['util-lib']={ version=1.001, @@ -15462,16 +15587,17 @@ local report_swiglib=logs.reporter("swiglib") local trace_swiglib=false trackers.register("resolvers.swiglib",function(v) trace_swiglib=v end) local done=false local function requireswiglib(required,version) + local trace_swiglib=trace_swiglib or package.helpers.trace local library=loaded[required] if library==nil then - local required_full=gsub(required,"%.","/") + local required_full=gsub(required,"%.","/") local required_path=pathpart(required_full) local required_base=nameonly(required_full) local required_name=required_base.."."..os.libsuffix local version=type(version)=="string" and version~="" and version or false local engine=environment.ownmain or false if trace_swiglib and not done then - local list=resolvers.expandedpathlistfromvariable("lib") + local list=resolvers.expandedpathlistfromvariable("lib") for i=1,#list do report_swiglib("tds path %i: %s",i,list[i]) end @@ -15553,7 +15679,7 @@ local function requireswiglib(required,version) end if not found_library then if trace_swiglib then - report_swiglib("not found: %a",asked_library) + report_swiglib("not found: %a",required) end library=false else @@ -15854,10 +15980,10 @@ end end -- of closure --- used libraries : l-lua.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-mrg.lua util-tpl.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua +-- used libraries : l-lua.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-mrg.lua util-tpl.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua -- skipped libraries : - --- original bytes : 662959 --- stripped bytes : 243507 +-- original bytes : 665699 +-- stripped bytes : 243168 -- end library merge @@ -15881,6 +16007,7 @@ local owntree = environment and environment.ownpath or ownpath local ownlibs = { -- order can be made better 'l-lua.lua', + 'l-package.lua', 'l-lpeg.lua', 'l-function.lua', 'l-string.lua', diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index ae08dc556..7f1464fbc 100644 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -56,7 +56,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-lua"] = package.loaded["l-lua"] or true --- original size: 10352, stripped down to: 5955 +-- original size: 3123, stripped down to: 1694 if not modules then modules={} end modules ['l-lua']={ version=1.001, @@ -136,51 +136,108 @@ function optionalrequire(...) return result end end + + +end -- of closure + +do -- create closure to overcome 200 locals limit + +package.loaded["l-package"] = package.loaded["l-package"] or true + +-- original size: 9641, stripped down to: 7101 + +if not modules then modules={} end modules ['l-package']={ + 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 type=type local gsub,format=string.gsub,string.format +local P,S,Cs,lpegmatch=lpeg.P,lpeg.S,lpeg.Cs,lpeg.match local package=package local searchers=package.searchers or package.loaders -local libpaths=nil -local clibpaths=nil -local libhash={} -local clibhash={} -local libextras={} -local clibextras={} local filejoin=file and file.join or function(path,name) return path.."/"..name end local isreadable=file and file.is_readable or function(name) local f=io.open(name) if f then f:close() return true end end local addsuffix=file and file.addsuffix or function(name,suffix) return name.."."..suffix end local function cleanpath(path) return path end +local pattern=Cs((((1-S("\\/"))^0*(S("\\/")^1/"/"))^0*(P(".")^1/"/"+P(1))^1)*-1) +local function lualibfile(name) + return lpegmatch(pattern,name) or name +end local helpers=package.helpers or { - libpaths=function() return {} end, - clibpaths=function() return {} end, cleanpath=cleanpath, + lualibfile=lualibfile, trace=false, report=function(...) print(format(...)) end, + builtin={ + ["preload table"]=package.searchers[1], + ["path specification"]=package.searchers[2], + ["cpath specification"]=package.searchers[3], + ["all in one fallback"]=package.searchers[4], + }, + methods={}, + sequence={ + "already loaded", + "preload table", + "lua extra list", + "lib extra list", + "path specification", + "cpath specification", + "all in one fallback", + "not loaded", + } } package.helpers=helpers -local function getlibpaths() - return libpaths or helpers.libpaths(libhash) +local methods=helpers.methods +local builtin=helpers.builtin +local extraluapaths={} +local extralibpaths={} +local luapaths=nil +local libpaths=nil +local function getextraluapaths() + return extraluapaths +end +local function getextralibpaths() + return extralibpaths +end +local function getluapaths() + luapaths=luapaths or file.splitpath(package.path,";") + return luapaths end -local function getclibpaths() - return clibpaths or helpers.clibpaths(clibhash) +local function getlibpaths() + libpaths=libpaths or file.splitpath(package.cpath,";") + return libpaths end +package.luapaths=getluapaths package.libpaths=getlibpaths -package.clibpaths=getclibpaths -local function addpath(what,paths,extras,hash,...) +package.extraluapaths=getextraluapaths +package.extralibpaths=getextralibpaths +local hashes={ + lua={}, + lib={}, +} +local function registerpath(tag,what,target,...) local pathlist={... } local cleanpath=helpers.cleanpath local trace=helpers.trace local report=helpers.report + local hash=hashes[what] local function add(path) local path=cleanpath(path) if not hash[path] then + target[#target+1]=path + hash[path]=true + if trace then + report("registered %s path %s: %s",tag,#target,path) + end + else if trace then - report("extra %s path: %s",what,path) + report("duplicate %s path: %s",tag,path) end - paths [#paths+1]=path - extras[#extras+1]=path end end for p=1,#pathlist do @@ -193,21 +250,15 @@ local function addpath(what,paths,extras,hash,...) add(path) end end - return paths,extras + return paths end -function package.extralibpath(...) - libpaths,libextras=addpath("lua",getlibpaths(),libextras,libhash,...) -end -function package.extraclibpath(...) - clibpaths,clibextras=addpath("lib",getclibpaths(),clibextras,clibhash,...) +helpers.registerpath=registerpath +function package.extraluapath(...) + registerpath("extra lua","lua",extraluapaths,...) end -if not searchers[-2] then - searchers[-2]=searchers[2] -end -searchers[2]=function(name) - return helpers.loaded(name) +function package.extralibpath(...) + registerpath("extra lib","lib",extralibpaths,...) end -searchers[3]=nil local function loadedaslib(resolved,rawname) local init="luaopen_"..gsub(rawname,"%.","_") if helpers.trace then @@ -215,12 +266,7 @@ local function loadedaslib(resolved,rawname) end return package.loadlib(resolved,init) end -local function loadedbylua(name) - if helpers.trace then - helpers.report("locating '%s' using normal loader",name) - end - return true,searchers[-2](name) -end +helpers.loadedaslib=loadedaslib local function loadedbypath(name,rawname,paths,islib,what) local trace=helpers.trace local report=helpers.report @@ -231,63 +277,135 @@ local function loadedbypath(name,rawname,paths,islib,what) local path=paths[p] local resolved=filejoin(path,name) if trace then - report("checking for '%s' using '%s' path '%s'",name,what,path) + report("checking '%s' using '%s' path '%s'",name,what,path) end if isreadable(resolved) then if trace then - report("lib '%s' located on '%s'",name,resolved) + report("'%s' located on '%s'",name,resolved) end + local result=nil if islib then - return true,loadedaslib(resolved,rawname) + result=loadedaslib(resolved,rawname) else - return true,loadfile(resolved) + result=loadfile(resolved) + end + if result then + result() end + return true,result end end end -local function notloaded(name) - if helpers.trace then - helpers.report("unable to locate library '%s'",name) +helpers.loadedbypath=loadedbypath +methods["already loaded"]=function(name) + local result=package.loaded[name] + if result then + return true,result end end -helpers.loadedaslib=loadedaslib -helpers.loadedbylua=loadedbylua -helpers.loadedbypath=loadedbypath -helpers.notloaded=notloaded -function helpers.loaded(name) - local thename=gsub(name,"%.","/") +methods["preload table"]=function(name) + local result=builtin["preload table"](name) + if type(result)=="function" then + return true,result + end +end +methods["lua extra list"]=function(name) + local thename=lualibfile(name) local luaname=addsuffix(thename,"lua") - local libname=addsuffix(thename,os.libsuffix or "so") - local libpaths=getlibpaths() - local clibpaths=getclibpaths() - local done,result=loadedbypath(luaname,name,libpaths,false,"lua") + local luapaths=getextraluapaths() + local done,result=loadedbypath(luaname,name,luapaths,false,"lua") if done then - return result + return true,result end - local done,result=loadedbypath(luaname,name,clibpaths,false,"lua") +end +methods["lib extra list"]=function(name) + local thename=lualibfile(name) + local libname=addsuffix(thename,os.libsuffix) + local libpaths=getextralibpaths() + local done,result=loadedbypath(libname,name,libpaths,true,"lib") if done then - return result + return true,result end - local done,result=loadedbypath(libname,name,clibpaths,true,"lib") - if done then - return result +end +local shown=false +methods["path specification"]=function(name) + if not shown and helpers.trace then + local luapaths=getluapaths() + if #luapaths>0 then + helpers.report("using %s built in lua paths",#luapaths) + else + helpers.report("no built in lua paths defined") + end + shown=true end - local done,result=loadedbylua(name) - if done then - return result + local result=builtin["path specification"](name) + if type(result)=="function" then + return true,result() + end +end +local shown=false +methods["cpath specification"]=function(name) + if not shown and helpers.trace then + local libpaths=getlibpaths() + if #libpaths>0 then + helpers.report("using %s built in lib paths",#libpaths) + else + helpers.report("no built in lib paths defined") + end + shown=true + end + local result=builtin["cpath specification"](name) + if type(result)=="function" then + return true,result() + end +end +methods["all in one fallback"]=function(name) + local result=builtin["all in one fallback"](name) + if type(result)=="function" then + return true,result() + end +end +methods["not loaded"]=function(name) + if helpers.trace then + helpers.report("unable to locate '%s'",name) + end +end +function helpers.loaded(name) + local sequence=helpers.sequence + for i=1,#sequence do + local step=sequence[i] + if helpers.trace then + helpers.report("locating '%s' using method '%s'",name,step) + end + local done,result=methods[step](name) + if done then + if helpers.trace then + helpers.report("'%s' located via method '%s' returns '%s'",name,step,type(result)) + end + if result then + package.loaded[name]=result + end + return result + end end - return notloaded(name) + return nil end function helpers.unload(name) if helpers.trace then if package.loaded[name] then - helpers.report("unloading library '%s', %s",name,"done") + helpers.report("unloading '%s', %s",name,"done") else - helpers.report("unloading library '%s', %s",name,"not loaded") + helpers.report("unloading '%s', %s",name,"not loaded") end end - package.loaded[name]=nil + package.loaded[name]=nil end +searchers[1]=nil +searchers[2]=nil +searchers[3]=nil +searchers[4]=nil +helpers.savedrequire=helpers.savedrequire or require +require=helpers.loaded end -- of closure @@ -15113,7 +15231,7 @@ do -- create closure to overcome 200 locals limit package.loaded["data-lua"] = package.loaded["data-lua"] or true --- original size: 4861, stripped down to: 3693 +-- original size: 5080, stripped down to: 3874 if not modules then modules={} end modules ['data-lua']={ version=1.001, @@ -15127,52 +15245,56 @@ local gsub=string.gsub local concat=table.concat local addsuffix=file.addsuffix local P,S,Cs,lpegmatch=lpeg.P,lpeg.S,lpeg.Cs,lpeg.match -local libsuffixes={ 'tex','lua' } -local clibsuffixes={ 'lib' } -local libformats={ 'TEXINPUTS','LUAINPUTS' } -local clibformats={ 'CLUAINPUTS' } -local helpers=package.helpers +local luasuffixes={ 'tex','lua' } +local libsuffixes={ 'lib' } +local luaformats={ 'TEXINPUTS','LUAINPUTS' } +local libformats={ 'CLUAINPUTS' } +local helpers=package.helpers or {} +local methods=helpers.methods or {} trackers.register("resolvers.libraries",function(v) helpers.trace=v end) trackers.register("resolvers.locating",function(v) helpers.trace=v end) helpers.report=logs.reporter("resolvers","libraries") +helpers.sequence={ + "already loaded", + "preload table", + "lua variable format", + "lib variable format", + "lua extra list", + "lib extra list", + "path specification", + "cpath specification", + "all in one fallback", + "not loaded", +} local pattern=Cs(P("!")^0/""*(P("/")*P(-1)/"/"+P("/")^1/"/"+1)^0) -local function cleanpath(path) +function helpers.cleanpath(path) return resolvers.resolve(lpegmatch(pattern,path)) end -helpers.cleanpath=cleanpath local loadedaslib=helpers.loadedaslib -local loadedbylua=helpers.loadedbylua local loadedbypath=helpers.loadedbypath -local notloaded=helpers.notloaded -local getlibpaths=package.libpaths -local getclibpaths=package.clibpaths -function helpers.libpaths(libhash) - local libpaths={} - for i=1,#libformats do - local paths=resolvers.expandedpathlistfromvariable(libformats[i]) - for i=1,#paths do - local path=cleanpath(paths[i]) - if not libhash[path] then - libpaths[#libpaths+1]=path - libhash[path]=true - end +local getextraluapaths=package.extraluapaths +local getextralibpaths=package.extralibpaths +local registerpath=helpers.registerpath +local lualibfile=helpers.lualibfile +local luaformatpaths +local libformatpaths +local function getluaformatpaths() + if not luaformatpaths then + luaformatpaths={} + for i=1,#luaformats do + registerpath("lua format","lua",luaformatpaths,resolvers.expandedpathlistfromvariable(luaformats[i])) end end - return libpaths + return luaformatpaths end -function helpers.clibpaths(clibhash) - local clibpaths={} - for i=1,#clibformats do - local paths=resolvers.expandedpathlistfromvariable(clibformats[i]) - for i=1,#paths do - local path=cleanpath(paths[i]) - if not clibhash[path] then - clibpaths[#clibpaths+1]=path - clibhash[path]=true - end +local function getlibformatpaths() + if not libformatpaths then + libformatpaths={} + for i=1,#libformats do + registerpath("lib format","lib",libformatpaths,resolvers.expandedpathlistfromvariable(libformats[i])) end end - return clibpaths + return libformatpaths end local function loadedbyformat(name,rawname,suffixes,islib) local trace=helpers.trace @@ -15190,51 +15312,54 @@ local function loadedbyformat(name,rawname,suffixes,islib) if trace then report("lib %a located on %a",name,resolved) end + local result=nil if islib then - return true,loadedaslib(resolved,rawname) + result=loadedaslib(resolved,rawname) else - return true,loadfile(resolved) + result=loadfile(resolved) + end + if result then + return true,result() end end end end helpers.loadedbyformat=loadedbyformat -local pattern=Cs((((1-S("\\/"))^0*(S("\\/")^1/"/"))^0*(P(".")^1/"/"+P(1))^1)*-1) -local function lualibfile(name) - return lpegmatch(pattern,name) or name -end -helpers.lualibfile=lualibfile -function helpers.loaded(name) +local shown=false +methods["lua variable format"]=function(name) + if not shown and helpers.trace then + local luapaths=getluaformatpaths() + if #luapaths>0 then + helpers.report("using %s lua format paths",#luapaths) + else + helpers.report("no lua format paths defined") + end + shown=true + end local thename=lualibfile(name) local luaname=addsuffix(thename,"lua") - local libname=addsuffix(thename,os.libsuffix) - local libpaths=getlibpaths() - local clibpaths=getclibpaths() - local done,result=loadedbyformat(luaname,name,libsuffixes,false) + local done,result=loadedbyformat(luaname,name,luasuffixes,false) if done then - return result + return true,result end - local done,result=loadedbyformat(libname,name,clibsuffixes,true) - if done then - return result - end - local done,result=loadedbypath(luaname,name,libpaths,false,"lua") - if done then - return result - end - local done,result=loadedbypath(luaname,name,clibpaths,false,"lua") - if done then - return result - end - local done,result=loadedbypath(libname,name,clibpaths,true,"lib") - if done then - return result +end +local shown=false +methods["lib variable format"]=function(name) + if not shown and helpers.trace then + local libpaths=getlibformatpaths() + if #libpaths>0 then + helpers.report("using %s lib format paths",#libpaths) + else + helpers.report("no lib format paths defined") + end + shown=true end - local done,result=loadedbylua(name) + local thename=lualibfile(name) + local libname=addsuffix(thename,os.libsuffix) + local done,result=loadedbyformat(libname,name,libsuffixes,true) if done then - return result + return true,result end - return notloaded(name) end resolvers.loadlualib=require @@ -15445,7 +15570,7 @@ do -- create closure to overcome 200 locals limit package.loaded["util-lib"] = package.loaded["util-lib"] or true --- original size: 10985, stripped down to: 5458 +-- original size: 11094, stripped down to: 5516 if not modules then modules={} end modules ['util-lib']={ version=1.001, @@ -15462,16 +15587,17 @@ local report_swiglib=logs.reporter("swiglib") local trace_swiglib=false trackers.register("resolvers.swiglib",function(v) trace_swiglib=v end) local done=false local function requireswiglib(required,version) + local trace_swiglib=trace_swiglib or package.helpers.trace local library=loaded[required] if library==nil then - local required_full=gsub(required,"%.","/") + local required_full=gsub(required,"%.","/") local required_path=pathpart(required_full) local required_base=nameonly(required_full) local required_name=required_base.."."..os.libsuffix local version=type(version)=="string" and version~="" and version or false local engine=environment.ownmain or false if trace_swiglib and not done then - local list=resolvers.expandedpathlistfromvariable("lib") + local list=resolvers.expandedpathlistfromvariable("lib") for i=1,#list do report_swiglib("tds path %i: %s",i,list[i]) end @@ -15553,7 +15679,7 @@ local function requireswiglib(required,version) end if not found_library then if trace_swiglib then - report_swiglib("not found: %a",asked_library) + report_swiglib("not found: %a",required) end library=false else @@ -15854,10 +15980,10 @@ end end -- of closure --- used libraries : l-lua.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-mrg.lua util-tpl.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua +-- used libraries : l-lua.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-mrg.lua util-tpl.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua -- skipped libraries : - --- original bytes : 662959 --- stripped bytes : 243507 +-- original bytes : 665699 +-- stripped bytes : 243168 -- end library merge @@ -15881,6 +16007,7 @@ local owntree = environment and environment.ownpath or ownpath local ownlibs = { -- order can be made better 'l-lua.lua', + 'l-package.lua', 'l-lpeg.lua', 'l-function.lua', 'l-string.lua', diff --git a/tex/context/base/cont-new.mkiv b/tex/context/base/cont-new.mkiv index 8466f5301..17f7b3d08 100644 --- a/tex/context/base/cont-new.mkiv +++ b/tex/context/base/cont-new.mkiv @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2013.04.16 18:49} +\newcontextversion{2013.04.17 17:29} %D This file is loaded at runtime, thereby providing an excellent place for %D hacks, patches, extensions and new features. diff --git a/tex/context/base/context-version.pdf b/tex/context/base/context-version.pdf Binary files differindex 98f60c42f..eb9088ef9 100644 --- a/tex/context/base/context-version.pdf +++ b/tex/context/base/context-version.pdf diff --git a/tex/context/base/context-version.png b/tex/context/base/context-version.png Binary files differindex 9c794d4ab..83a3164fd 100644 --- a/tex/context/base/context-version.png +++ b/tex/context/base/context-version.png diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv index 357723f69..5fece4a9b 100644 --- a/tex/context/base/context.mkiv +++ b/tex/context/base/context.mkiv @@ -25,7 +25,7 @@ %D up and the dependencies are more consistent. \edef\contextformat {\jobname} -\edef\contextversion{2013.04.16 18:49} +\edef\contextversion{2013.04.17 17:29} \edef\contextkind {beta} %D For those who want to use this: diff --git a/tex/context/base/data-lua.lua b/tex/context/base/data-lua.lua index 7e3d92585..14aebf959 100644 --- a/tex/context/base/data-lua.lua +++ b/tex/context/base/data-lua.lua @@ -16,61 +16,65 @@ local addsuffix = file.addsuffix local P, S, Cs, lpegmatch = lpeg.P, lpeg.S, lpeg.Cs, lpeg.match -local libsuffixes = { 'tex', 'lua' } -local clibsuffixes = { 'lib' } -local libformats = { 'TEXINPUTS', 'LUAINPUTS' } -local clibformats = { 'CLUAINPUTS' } -local helpers = package.helpers +local luasuffixes = { 'tex', 'lua' } +local libsuffixes = { 'lib' } +local luaformats = { 'TEXINPUTS', 'LUAINPUTS' } +local libformats = { 'CLUAINPUTS' } +local helpers = package.helpers or { } +local methods = helpers.methods or { } trackers.register("resolvers.libraries", function(v) helpers.trace = v end) trackers.register("resolvers.locating", function(v) helpers.trace = v end) helpers.report = logs.reporter("resolvers","libraries") +helpers.sequence = { + "already loaded", + "preload table", + "lua variable format", + "lib variable format", + "lua extra list", + "lib extra list", + "path specification", + "cpath specification", + "all in one fallback", + "not loaded", +} + local pattern = Cs(P("!")^0 / "" * (P("/") * P(-1) / "/" + P("/")^1 / "/" + 1)^0) -local function cleanpath(path) -- hm, don't we have a helper for this? +function helpers.cleanpath(path) -- hm, don't we have a helper for this? return resolvers.resolve(lpegmatch(pattern,path)) end -helpers.cleanpath = cleanpath - -local loadedaslib = helpers.loadedaslib -local loadedbylua = helpers.loadedbylua -local loadedbypath = helpers.loadedbypath -local notloaded = helpers.notloaded - -local getlibpaths = package.libpaths -local getclibpaths = package.clibpaths - -function helpers.libpaths(libhash) - local libpaths = { } - for i=1,#libformats do - local paths = resolvers.expandedpathlistfromvariable(libformats[i]) - for i=1,#paths do - local path = cleanpath(paths[i]) - if not libhash[path] then - libpaths[#libpaths+1] = path - libhash[path] = true - end +local loadedaslib = helpers.loadedaslib +local loadedbypath = helpers.loadedbypath +local getextraluapaths = package.extraluapaths +local getextralibpaths = package.extralibpaths +local registerpath = helpers.registerpath +local lualibfile = helpers.lualibfile + +local luaformatpaths +local libformatpaths + +local function getluaformatpaths() + if not luaformatpaths then + luaformatpaths = { } + for i=1,#luaformats do + registerpath("lua format","lua",luaformatpaths,resolvers.expandedpathlistfromvariable(luaformats[i])) end end - return libpaths + return luaformatpaths end -function helpers.clibpaths(clibhash) - local clibpaths = { } - for i=1,#clibformats do - local paths = resolvers.expandedpathlistfromvariable(clibformats[i]) - for i=1,#paths do - local path = cleanpath(paths[i]) - if not clibhash[path] then - clibpaths[#clibpaths+1] = path - clibhash[path] = true - end +local function getlibformatpaths() + if not libformatpaths then + libformatpaths = { } + for i=1,#libformats do + registerpath("lib format","lib",libformatpaths,resolvers.expandedpathlistfromvariable(libformats[i])) end end - return clibpaths + return libformatpaths end local function loadedbyformat(name,rawname,suffixes,islib) @@ -89,10 +93,14 @@ local function loadedbyformat(name,rawname,suffixes,islib) if trace then report("lib %a located on %a",name,resolved) end + local result = nil if islib then - return true, loadedaslib(resolved,rawname) + result = loadedaslib(resolved,rawname) else - return true, loadfile(resolved) + result = loadfile(resolved) + end + if result then + return true, result() end end end @@ -100,16 +108,6 @@ end helpers.loadedbyformat = loadedbyformat --- alternatively we could set the package.searchers - -local pattern = Cs((((1-S("\\/"))^0 * (S("\\/")^1/"/"))^0 * (P(".")^1/"/"+P(1))^1) * -1) - -local function lualibfile(name) - return lpegmatch(pattern,name) or name -end - -helpers.lualibfile = lualibfile - -- print(lualibfile("bar")) -- print(lualibfile("foo.bar")) -- print(lualibfile("crap/foo...bar")) @@ -119,41 +117,49 @@ helpers.lualibfile = lualibfile -- alternatively we could split in path and base and temporary set the libpath to path -function helpers.loaded(name) - local thename = lualibfile(name) - local luaname = addsuffix(thename,"lua") - local libname = addsuffix(thename,os.libsuffix) - local libpaths = getlibpaths() - local clibpaths = getclibpaths() - local done, result = loadedbyformat(luaname,name,libsuffixes,false) - if done then - return result - end - local done, result = loadedbyformat(libname,name,clibsuffixes,true) - if done then - return result - end - local done, result = loadedbypath(luaname,name,libpaths,false,"lua") - if done then - return result +-- we could build a list of relevant paths but for tracing it's better to have the +-- whole lot (ok, we could skip the duplicates) + +local shown = false + +methods["lua variable format"] = function(name) + if not shown and helpers.trace then + local luapaths = getluaformatpaths() -- triggers building + if #luapaths > 0 then + helpers.report("using %s lua format paths",#luapaths) + else + helpers.report("no lua format paths defined") + end + shown = true end - local done, result = loadedbypath(luaname,name,clibpaths,false,"lua") + local thename = lualibfile(name) + local luaname = addsuffix(thename,"lua") + local done, result = loadedbyformat(luaname,name,luasuffixes,false) if done then - return result + return true, result end - local done, result = loadedbypath(libname,name,clibpaths,true,"lib") - if done then - return result +end + +local shown = false + +methods["lib variable format"] = function(name) + if not shown and helpers.trace then + local libpaths = getlibformatpaths() -- triggers building + if #libpaths > 0 then + helpers.report("using %s lib format paths",#libpaths) + else + helpers.report("no lib format paths defined") + end + shown = true end - local done, result = loadedbylua(name) + local thename = lualibfile(name) + local libname = addsuffix(thename,os.libsuffix) + local done, result = loadedbyformat(libname,name,libsuffixes,true) if done then - return result + return true, result end - return notloaded(name) end --- package.searchers[3] = nil -- get rid of the built in one (done in l-lua) - -- package.extraclibpath(environment.ownpath) resolvers.loadlualib = require diff --git a/tex/context/base/font-mis.lua b/tex/context/base/font-mis.lua index 247b0f641..c22548ac5 100644 --- a/tex/context/base/font-mis.lua +++ b/tex/context/base/font-mis.lua @@ -22,7 +22,7 @@ local handlers = fonts.handlers handlers.otf = handlers.otf or { } local otf = handlers.otf -otf.version = otf.version or 2.741 +otf.version = otf.version or 2.742 otf.cache = otf.cache or containers.define("fonts", "otf", otf.version, true) function otf.loadcached(filename,format,sub) diff --git a/tex/context/base/font-otf.lua b/tex/context/base/font-otf.lua index b8abd590a..8a6183180 100644 --- a/tex/context/base/font-otf.lua +++ b/tex/context/base/font-otf.lua @@ -23,6 +23,7 @@ local lpegmatch = lpeg.match local reversed, concat, remove = table.reversed, table.concat, table.remove local ioflush = io.flush local fastcopy, tohash, derivetable = table.fastcopy, table.tohash, table.derive +local formatters = string.formatters local allocate = utilities.storage.allocate local registertracker = trackers.register @@ -47,7 +48,7 @@ local otf = fonts.handlers.otf otf.glists = { "gsub", "gpos" } -otf.version = 2.741 -- beware: also sync font-mis.lua +otf.version = 2.742 -- beware: also sync font-mis.lua otf.cache = containers.define("fonts", "otf", otf.version, true) local fontdata = fonts.hashes.identifiers @@ -1172,7 +1173,20 @@ local function t_hashed(t,cache) end end -local s_hashed = t_hashed +-- local s_hashed = t_hashed + +local function s_hashed(t,cache) + if t then + local ht = { } + local tf = t[1] + for i=1,#tf do + ht[i] = { [tf[i]] = true } + end + return ht + else + return nil + end +end local function r_uncover(splitter,cache,cover,replacements) if cover == "" then @@ -1307,6 +1321,9 @@ actions["reorganize lookups"] = function(data,filename,raw) -- we could check fo end end elseif format == "glyphs" then + -- I could store these more efficient (as not we use a nested tables for before, + -- after and current but this features happens so seldom that I don't bother + -- about it right now. for i=1,#rules do local rule = rules[i] local glyphs = rule.glyphs diff --git a/tex/context/base/l-lua.lua b/tex/context/base/l-lua.lua index 51816400e..fc05afa67 100644 --- a/tex/context/base/l-lua.lua +++ b/tex/context/base/l-lua.lua @@ -6,7 +6,7 @@ if not modules then modules = { } end modules ['l-lua'] = { license = "see context related readme files" } --- compatibility hacks ... try to avoid usage +-- compatibility hacksand helpers local major, minor = string.match(_VERSION,"^[^%d]+(%d+)%.(%d+).*$") @@ -148,257 +148,3 @@ function optionalrequire(...) return result end end - --- Code moved from data-lua and changed into a plug-in. - --- We overload the regular loader. We do so because we operate mostly in --- tds and use our own loader code. Alternatively we could use a more --- extensive definition of package.path and package.cpath but even then --- we're not done. Also, we now have better tracing. --- --- -- local mylib = require("libtest") --- -- local mysql = require("luasql.mysql") - -local type = type -local gsub, format = string.gsub, string.format - -local package = package -local searchers = package.searchers or package.loaders - -local libpaths = nil -local clibpaths = nil -local libhash = { } -local clibhash = { } -local libextras = { } -local clibextras = { } - --- dummies - -local filejoin = file and file.join or function(path,name) return path .. "/" .. name end -local isreadable = file and file.is_readable or function(name) local f = io.open(name) if f then f:close() return true end end -local addsuffix = file and file.addsuffix or function(name,suffix) return name .. "." .. suffix end - --- - -local function cleanpath(path) -- hm, don't we have a helper for this? - return path -end - -local helpers = package.helpers or { - libpaths = function() return { } end, - clibpaths = function() return { } end, - cleanpath = cleanpath, - trace = false, - report = function(...) print(format(...)) end, -} -package.helpers = helpers - -local function getlibpaths() - return libpaths or helpers.libpaths(libhash) -end - -local function getclibpaths() - return clibpaths or helpers.clibpaths(clibhash) -end - -package.libpaths = getlibpaths -package.clibpaths = getclibpaths - -local function addpath(what,paths,extras,hash,...) - local pathlist = { ... } - local cleanpath = helpers.cleanpath - local trace = helpers.trace - local report = helpers.report - -- - local function add(path) - local path = cleanpath(path) - if not hash[path] then - if trace then - report("extra %s path: %s",what,path) - end - paths [#paths +1] = path - extras[#extras+1] = path - end - end - -- - for p=1,#pathlist do - local path = pathlist[p] - if type(path) == "table" then - for i=1,#path do - add(path[i]) - end - else - add(path) - end - end - return paths, extras -end - -function package.extralibpath(...) - libpaths, libextras = addpath("lua", getlibpaths(), libextras, libhash,...) -end - -function package.extraclibpath(...) - clibpaths, clibextras = addpath("lib",getclibpaths(),clibextras,clibhash,...) -end - --- function package.extralibpath(...) --- libpaths = getlibpaths() --- local pathlist = { ... } --- local cleanpath = helpers.cleanpath --- local trace = helpers.trace --- local report = helpers.report --- -- --- local function add(path) --- local path = cleanpath(path) --- if not libhash[path] then --- if trace then --- report("extra lua path: %s",path) --- end --- libextras[#libextras+1] = path --- libpaths [#libpaths +1] = path --- end --- end --- -- --- for p=1,#pathlist do --- local path = pathlist[p] --- if type(path) == "table" then --- for i=1,#path do --- add(path[i]) --- end --- else --- add(path) --- end --- end --- end - --- function package.extraclibpath(...) --- clibpaths = getclibpaths() --- local pathlist = { ... } --- local cleanpath = helpers.cleanpath --- local trace = helpers.trace --- local report = helpers.report --- -- --- local function add(path) --- local path = cleanpath(path) --- if not clibhash[path] then --- if trace then --- report("extra lib path: %s",path) --- end --- clibextras[#clibextras+1] = path --- clibpaths [#clibpaths +1] = path --- end --- end --- -- --- for p=1,#pathlist do --- local path = pathlist[p] --- if type(path) == "table" then --- for i=1,#path do --- add(path[i]) --- end --- else --- add(path) --- end --- end --- end - -if not searchers[-2] then - -- use package-path and package-cpath - searchers[-2] = searchers[2] -end - -searchers[2] = function(name) - return helpers.loaded(name) -end - -searchers[3] = nil -- get rid of the built in one - -local function loadedaslib(resolved,rawname) - -- local init = "luaopen_" .. string.match(rawname,".-([^%.]+)$") - local init = "luaopen_"..gsub(rawname,"%.","_") - if helpers.trace then - helpers.report("calling loadlib with '%s' with init '%s'",resolved,init) - end - return package.loadlib(resolved,init) -end - -local function loadedbylua(name) - if helpers.trace then - helpers.report("locating '%s' using normal loader",name) - end - return true, searchers[-2](name) -- the original -end - -local function loadedbypath(name,rawname,paths,islib,what) - local trace = helpers.trace - local report = helpers.report - if trace then - report("locating '%s' as '%s' on '%s' paths",rawname,name,what) - end - for p=1,#paths do - local path = paths[p] - local resolved = filejoin(path,name) - if trace then -- mode detail - report("checking for '%s' using '%s' path '%s'",name,what,path) - end - if isreadable(resolved) then - if trace then - report("lib '%s' located on '%s'",name,resolved) - end - if islib then - return true, loadedaslib(resolved,rawname) - else - return true, loadfile(resolved) - end - end - end -end - -local function notloaded(name) - if helpers.trace then - helpers.report("unable to locate library '%s'",name) - end -end - -helpers.loadedaslib = loadedaslib -helpers.loadedbylua = loadedbylua -helpers.loadedbypath = loadedbypath -helpers.notloaded = notloaded - --- alternatively we could set the package.searchers - -function helpers.loaded(name) - local thename = gsub(name,"%.","/") - local luaname = addsuffix(thename,"lua") - local libname = addsuffix(thename,os.libsuffix or "so") -- brrr - local libpaths = getlibpaths() - local clibpaths = getclibpaths() - local done, result = loadedbypath(luaname,name,libpaths,false,"lua") - if done then - return result - end - local done, result = loadedbypath(luaname,name,clibpaths,false,"lua") - if done then - return result - end - local done, result = loadedbypath(libname,name,clibpaths,true,"lib") - if done then - return result - end - local done, result = loadedbylua(name) - if done then - return result - end - return notloaded(name) -end - -function helpers.unload(name) - if helpers.trace then - if package.loaded[name] then - helpers.report("unloading library '%s', %s",name,"done") - else - helpers.report("unloading library '%s', %s",name,"not loaded") - end - end - package.loaded[name] = nil -end diff --git a/tex/context/base/l-package.lua b/tex/context/base/l-package.lua new file mode 100644 index 000000000..a695531c9 --- /dev/null +++ b/tex/context/base/l-package.lua @@ -0,0 +1,338 @@ +if not modules then modules = { } end modules ['l-package'] = { + 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" +} + +-- Code moved from data-lua and changed into a plug-in. + +-- We overload the regular loader. We do so because we operate mostly in +-- tds and use our own loader code. Alternatively we could use a more +-- extensive definition of package.path and package.cpath but even then +-- we're not done. Also, we now have better tracing. +-- +-- -- local mylib = require("libtest") +-- -- local mysql = require("luasql.mysql") + +local type = type +local gsub, format = string.gsub, string.format + +local P, S, Cs, lpegmatch = lpeg.P, lpeg.S, lpeg.Cs, lpeg.match + +local package = package +local searchers = package.searchers or package.loaders + +-- dummies + +local filejoin = file and file.join or function(path,name) return path .. "/" .. name end +local isreadable = file and file.is_readable or function(name) local f = io.open(name) if f then f:close() return true end end +local addsuffix = file and file.addsuffix or function(name,suffix) return name .. "." .. suffix end + +-- + +-- local separator, concatinator, placeholder, pathofexecutable, ignorebefore = string.match(package.config,"(.-)\n(.-)\n(.-)\n(.-)\n(.-)\n") +-- +-- local config = { +-- separator = separator, -- \ or / +-- concatinator = concatinator, -- ; +-- placeholder = placeholder, -- ? becomes name +-- pathofexecutable = pathofexecutable, -- ! becomes executables dir (on windows) +-- ignorebefore = ignorebefore, -- - remove all before this when making lua_open +-- } + +-- + +local function cleanpath(path) -- hm, don't we have a helper for this? + return path +end + +local pattern = Cs((((1-S("\\/"))^0 * (S("\\/")^1/"/"))^0 * (P(".")^1/"/"+P(1))^1) * -1) + +local function lualibfile(name) + return lpegmatch(pattern,name) or name +end + +local helpers = package.helpers or { + cleanpath = cleanpath, + lualibfile = lualibfile, + trace = false, + report = function(...) print(format(...)) end, + builtin = { + ["preload table"] = package.searchers[1], -- special case, built-in libs + ["path specification"] = package.searchers[2], + ["cpath specification"] = package.searchers[3], + ["all in one fallback"] = package.searchers[4], -- special case, combined libs + }, + methods = { + }, + sequence = { + "already loaded", + "preload table", + "lua extra list", + "lib extra list", + "path specification", + "cpath specification", + "all in one fallback", + "not loaded", + } +} + +package.helpers = helpers + +local methods = helpers.methods +local builtin = helpers.builtin + +-- extra tds/ctx paths + +local extraluapaths = { } +local extralibpaths = { } +local luapaths = nil -- delayed +local libpaths = nil -- delayed + +local function getextraluapaths() + return extraluapaths +end + +local function getextralibpaths() + return extralibpaths +end + +local function getluapaths() + luapaths = luapaths or file.splitpath(package.path, ";") + return luapaths +end + +local function getlibpaths() + libpaths = libpaths or file.splitpath(package.cpath, ";") + return libpaths +end + +package.luapaths = getluapaths +package.libpaths = getlibpaths +package.extraluapaths = getextraluapaths +package.extralibpaths = getextralibpaths + +local hashes = { + lua = { }, + lib = { }, +} + +local function registerpath(tag,what,target,...) + local pathlist = { ... } + local cleanpath = helpers.cleanpath + local trace = helpers.trace + local report = helpers.report + local hash = hashes[what] + -- + local function add(path) + local path = cleanpath(path) + if not hash[path] then + target[#target+1] = path + hash[path] = true + if trace then + report("registered %s path %s: %s",tag,#target,path) + end + else + if trace then + report("duplicate %s path: %s",tag,path) + end + end + end + -- + for p=1,#pathlist do + local path = pathlist[p] + if type(path) == "table" then + for i=1,#path do + add(path[i]) + end + else + add(path) + end + end + return paths +end + +helpers.registerpath = registerpath + +function package.extraluapath(...) + registerpath("extra lua","lua",extraluapaths,...) +end + +function package.extralibpath(...) + registerpath("extra lib","lib",extralibpaths,...) +end + +-- lib loader (used elsewhere) + +local function loadedaslib(resolved,rawname) -- todo: strip all before first - + -- local init = "luaopen_" .. string.match(rawname,".-([^%.]+)$") + local init = "luaopen_"..gsub(rawname,"%.","_") + if helpers.trace then + helpers.report("calling loadlib with '%s' with init '%s'",resolved,init) + end + return package.loadlib(resolved,init) +end + +helpers.loadedaslib = loadedaslib + +-- wrapped and new loaders + +local function loadedbypath(name,rawname,paths,islib,what) + local trace = helpers.trace + local report = helpers.report + if trace then + report("locating '%s' as '%s' on '%s' paths",rawname,name,what) + end + for p=1,#paths do + local path = paths[p] + local resolved = filejoin(path,name) + if trace then -- mode detail + report("checking '%s' using '%s' path '%s'",name,what,path) + end + if isreadable(resolved) then + if trace then + report("'%s' located on '%s'",name,resolved) + end + local result = nil + if islib then + result = loadedaslib(resolved,rawname) + else + result = loadfile(resolved) + end + if result then + result() + end + return true, result + end + end +end + +helpers.loadedbypath = loadedbypath + +-- alternatively we could set the package.searchers + +methods["already loaded"] = function(name) + local result = package.loaded[name] + if result then + return true, result + end +end + +methods["preload table"] = function(name) + local result = builtin["preload table"](name) + if type(result) == "function" then + return true, result + end +end + +methods["lua extra list"] = function(name) + local thename = lualibfile(name) + local luaname = addsuffix(thename,"lua") + local luapaths = getextraluapaths() + local done, result = loadedbypath(luaname,name,luapaths,false,"lua") + if done then + return true, result + end +end + +methods["lib extra list"] = function(name) + local thename = lualibfile(name) + local libname = addsuffix(thename,os.libsuffix) + local libpaths = getextralibpaths() + local done, result = loadedbypath(libname,name,libpaths,true,"lib") + if done then + return true, result + end +end + +local shown = false + +methods["path specification"] = function(name) + if not shown and helpers.trace then + local luapaths = getluapaths() -- triggers list building + if #luapaths > 0 then + helpers.report("using %s built in lua paths",#luapaths) + else + helpers.report("no built in lua paths defined") + end + shown = true + end + local result = builtin["path specification"](name) + if type(result) == "function" then + return true, result() + end +end + +local shown = false + +methods["cpath specification"] = function(name) + if not shown and helpers.trace then + local libpaths = getlibpaths() -- triggers list building + if #libpaths > 0 then + helpers.report("using %s built in lib paths",#libpaths) + else + helpers.report("no built in lib paths defined") + end + shown = true + end + local result = builtin["cpath specification"](name) + if type(result) == "function" then + return true, result() + end +end + +methods["all in one fallback"] = function(name) + local result = builtin["all in one fallback"](name) + if type(result) == "function" then + return true, result() + end +end + +methods["not loaded"] = function(name) + if helpers.trace then + helpers.report("unable to locate '%s'",name) + end +end + +function helpers.loaded(name) + local sequence = helpers.sequence + for i=1,#sequence do + local step = sequence[i] + if helpers.trace then + helpers.report("locating '%s' using method '%s'",name,step) + end + local done, result = methods[step](name) + if done then + if helpers.trace then + helpers.report("'%s' located via method '%s' returns '%s'",name,step,type(result)) + end + if result then + package.loaded[name] = result + end + return result + end + end + return nil -- we must return a value +end + +function helpers.unload(name) + if helpers.trace then + if package.loaded[name] then + helpers.report("unloading '%s', %s",name,"done") + else + helpers.report("unloading '%s', %s",name,"not loaded") + end + end + package.loaded[name] = nil -- does that work? is readable only, maybe we need our own hash +end + +searchers[1] = nil +searchers[2] = nil +searchers[3] = nil +searchers[4] = nil + +helpers.savedrequire = helpers.savedrequire or require + +require = helpers.loaded diff --git a/tex/context/base/luat-bas.mkiv b/tex/context/base/luat-bas.mkiv index e24568b0a..ddf901424 100644 --- a/tex/context/base/luat-bas.mkiv +++ b/tex/context/base/luat-bas.mkiv @@ -14,6 +14,7 @@ \writestatus{loading}{ConTeXt Lua Macros / Basic Lua Libraries} \registerctxluafile{l-lua} {1.001} +\registerctxluafile{l-package} {1.001} \registerctxluafile{l-lpeg} {1.001} \registerctxluafile{l-function}{1.001} \registerctxluafile{l-string} {1.001} diff --git a/tex/context/base/node-pro.lua b/tex/context/base/node-pro.lua index 24351b5b8..60f2d8a72 100644 --- a/tex/context/base/node-pro.lua +++ b/tex/context/base/node-pro.lua @@ -123,6 +123,8 @@ local hpack = node.hpack function nodes.fasthpack(...) -- todo: pass explicit arguments enabled = false local hp, b = hpack(...) + hp.prev = nil + hp.next = nil enabled = true return hp, b end diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdf Binary files differindex d6ca0d33d..2930dd72e 100644 --- a/tex/context/base/status-files.pdf +++ b/tex/context/base/status-files.pdf diff --git a/tex/context/base/status-lua.pdf b/tex/context/base/status-lua.pdf Binary files differindex d6e70ce92..82c891fd6 100644 --- a/tex/context/base/status-lua.pdf +++ b/tex/context/base/status-lua.pdf diff --git a/tex/context/base/symb-imp-cc.mkiv b/tex/context/base/symb-imp-cc.mkiv index 742a19f9f..40274745b 100644 --- a/tex/context/base/symb-imp-cc.mkiv +++ b/tex/context/base/symb-imp-cc.mkiv @@ -17,27 +17,56 @@ goodies=cc-icons, unicoding=yes] -\definefontsynonym - [creativecommons] - [cc-icons*cc-icons] +\doiffontpresentelse{ccicons.otf} { % redone ctan version + \definefontsynonym + [creativecommons] + [ccicons*cc-icons] +} { % official version + \definefontsynonym + [creativecommons] + [cc-icons*cc-icons] +} \startsymbolset[cc] + \definesymbol [sa] [\getnamedglyphdirect{creativecommons}{sa}] \definesymbol [by] [\getnamedglyphdirect{creativecommons}{by}] \definesymbol [cc] [\getnamedglyphdirect{creativecommons}{cc}] \definesymbol [nd] [\getnamedglyphdirect{creativecommons}{nd}] \definesymbol [nc] [\getnamedglyphdirect{creativecommons}{nc}] + \definesymbol [ncus] [\getnamedglyphdirect{creativecommons}{nc}] + \definesymbol [nceu] [\getnamedglyphdirect{creativecommons}{nceu}] + \definesymbol [ncjp] [\getnamedglyphdirect{creativecommons}{ncjp}] + \definesymbol [pd] [\getnamedglyphdirect{creativecommons}{pd}] \definesymbol [sampling] [\getnamedglyphdirect{creativecommons}{sampling}] \definesymbol [share] [\getnamedglyphdirect{creativecommons}{share}] \definesymbol [remix] [\getnamedglyphdirect{creativecommons}{remix}] + \definesymbol [zero] [\getnamedglyphdirect{creativecommons}{zero}] \definesymbol [logo] [\getnamedglyphdirect{creativecommons}{logo}] - \definesymbol [cc-by-sa-nc] [\dontleavehmode\lower.15ex\hbox\bgroup - \getnamedglyphdirect{creativecommons}{cc}\enspace - \getnamedglyphdirect{creativecommons}{by}\enspace - \getnamedglyphdirect{creativecommons}{sa}\enspace - \getnamedglyphdirect{creativecommons}{nc}% - \egroup] + % \definesymbol [cc-by-sa-nc] [\dontleavehmode\lower.15ex\hbox\bgroup + % \getnamedglyphdirect{creativecommons}{cc}\enspace + % \getnamedglyphdirect{creativecommons}{by}\enspace + % \getnamedglyphdirect{creativecommons}{sa}\enspace + % \getnamedglyphdirect{creativecommons}{nc}% + % \egroup] + % + % % more efficient: + % + % \definesymbol [cc-by-sa-nc] [\dontleavehmode\lower.15ex\hbox\bgroup + % \directsymbol{cc}{cc}\enspace\directsymbol{cc}{by}\enspace + % \directsymbol{cc}{sa}\enspace\directsymbol{cc}{nc}% + % \egroup] + % + % % more fun: + + \unexpanded\def\creativecommons#1% + {\dontleavehmode\lower.15\exheight\hbox\bgroup + \let\inbetween\relax + \processseparatedlist[#1][-]{\inbetween\let\inbetween\enspace\directsymbol{cc}}% + \egroup} + + \definesymbol [cc-by-sa-nc] [\creativecommons{cc-by-sa-nc}] \stopsymbolset diff --git a/tex/context/base/trac-vis.lua b/tex/context/base/trac-vis.lua index 1138bacc8..df4909c3e 100644 --- a/tex/context/base/trac-vis.lua +++ b/tex/context/base/trac-vis.lua @@ -44,6 +44,7 @@ local glue_code = nodecodes.glue local penalty_code = nodecodes.penalty local whatsit_code = nodecodes.whatsit local user_code = nodecodes.user +local gluespec_code = nodecodes.gluespec local kerncodes = nodes.kerncodes local font_kern_code = kerncodes.fontkern @@ -521,8 +522,12 @@ local function ruledbox(head,current,vertical,layer,what,simple) next.prev = info end if prev then +if prev.id == gluespec_code then + -- weird, how can this happen, an inline glue-spec +else info.prev = prev prev.next = info +end end if head == current then return info, info diff --git a/tex/context/base/util-lib.lua b/tex/context/base/util-lib.lua index 7d43e6c97..2ec3d395c 100644 --- a/tex/context/base/util-lib.lua +++ b/tex/context/base/util-lib.lua @@ -90,10 +90,11 @@ local trace_swiglib = false trackers.register("resolvers.swiglib", function(v) local done = false local function requireswiglib(required,version) + local trace_swiglib = trace_swiglib or package.helpers.trace local library = loaded[required] if library == nil then -- initialize a few variables - local required_full = gsub(required,"%.","/") + local required_full = gsub(required,"%.","/") -- package.helpers.lualibfile local required_path = pathpart(required_full) local required_base = nameonly(required_full) local required_name = required_base .. "." .. os.libsuffix @@ -101,7 +102,7 @@ local function requireswiglib(required,version) local engine = environment.ownmain or false -- if trace_swiglib and not done then - local list = resolvers.expandedpathlistfromvariable("lib") + local list = resolvers.expandedpathlistfromvariable("lib") -- fresh, no reuse for i=1,#list do report_swiglib("tds path %i: %s",i,list[i]) end @@ -191,7 +192,7 @@ local function requireswiglib(required,version) -- load and initialize when found if not found_library then if trace_swiglib then - report_swiglib("not found: %a",asked_library) + report_swiglib("not found: %a",required) end library = false else diff --git a/tex/context/fonts/cc-icons.lfg b/tex/context/fonts/cc-icons.lfg index 2739918af..902de05b3 100644 --- a/tex/context/fonts/cc-icons.lfg +++ b/tex/context/fonts/cc-icons.lfg @@ -13,10 +13,14 @@ return { by = utfbyte("b"), cc = utfbyte("c"), nd = utfbyte("d"), + -- nceu = utfbyte("e"), nc = utfbyte("n"), sampling = utfbyte("m"), + -- pd = utfbyte("p"), share = utfbyte("s"), remix = utfbyte("r"), + -- ncjp = utfbyte("y"), + -- zero = utfbyte("z"), logo = utfbyte("C"), }, }, diff --git a/tex/context/fonts/ccicons.lfg b/tex/context/fonts/ccicons.lfg new file mode 100644 index 000000000..a09c78fc4 --- /dev/null +++ b/tex/context/fonts/ccicons.lfg @@ -0,0 +1,27 @@ +local utfbyte = utf.byte + +return { + name = "cc-icons", + version = "1.00", + comment = "Goodies that complement creative commons icons (ctan variant).", + author = "Hans Hagen", + copyright = "ConTeXt development team", + remapping = { + tounicode = true, + unicodes = { + sa = utfbyte("a"), + by = utfbyte("b"), + cc = utfbyte("c"), -- logo (so not the same name) + nd = utfbyte("d"), + nceu = utfbyte("e"), + nc = utfbyte("n"), + sampling = utfbyte("m"), + pd = utfbyte("p"), + share = utfbyte("s"), + remix = utfbyte("r"), + ncjp = utfbyte("y"), + zero = utfbyte("z"), + logo = 0x00A9, -- copyright + }, + }, +} diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index 8633b8e3a..62be360ed 100644 --- a/tex/generic/context/luatex/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : luatex-fonts-merged.lua -- parent file : luatex-fonts.lua --- merge date : 04/16/13 18:49:45 +-- merge date : 04/17/13 17:29:33 do -- begin closure to overcome local limits and interference @@ -82,158 +82,6 @@ function optionalrequire(...) return result end end -local type=type -local gsub,format=string.gsub,string.format -local package=package -local searchers=package.searchers or package.loaders -local libpaths=nil -local clibpaths=nil -local libhash={} -local clibhash={} -local libextras={} -local clibextras={} -local filejoin=file and file.join or function(path,name) return path.."/"..name end -local isreadable=file and file.is_readable or function(name) local f=io.open(name) if f then f:close() return true end end -local addsuffix=file and file.addsuffix or function(name,suffix) return name.."."..suffix end -local function cleanpath(path) - return path -end -local helpers=package.helpers or { - libpaths=function() return {} end, - clibpaths=function() return {} end, - cleanpath=cleanpath, - trace=false, - report=function(...) print(format(...)) end, -} -package.helpers=helpers -local function getlibpaths() - return libpaths or helpers.libpaths(libhash) -end -local function getclibpaths() - return clibpaths or helpers.clibpaths(clibhash) -end -package.libpaths=getlibpaths -package.clibpaths=getclibpaths -local function addpath(what,paths,extras,hash,...) - local pathlist={... } - local cleanpath=helpers.cleanpath - local trace=helpers.trace - local report=helpers.report - local function add(path) - local path=cleanpath(path) - if not hash[path] then - if trace then - report("extra %s path: %s",what,path) - end - paths [#paths+1]=path - extras[#extras+1]=path - end - end - for p=1,#pathlist do - local path=pathlist[p] - if type(path)=="table" then - for i=1,#path do - add(path[i]) - end - else - add(path) - end - end - return paths,extras -end -function package.extralibpath(...) - libpaths,libextras=addpath("lua",getlibpaths(),libextras,libhash,...) -end -function package.extraclibpath(...) - clibpaths,clibextras=addpath("lib",getclibpaths(),clibextras,clibhash,...) -end -if not searchers[-2] then - searchers[-2]=searchers[2] -end -searchers[2]=function(name) - return helpers.loaded(name) -end -searchers[3]=nil -local function loadedaslib(resolved,rawname) - local init="luaopen_"..gsub(rawname,"%.","_") - if helpers.trace then - helpers.report("calling loadlib with '%s' with init '%s'",resolved,init) - end - return package.loadlib(resolved,init) -end -local function loadedbylua(name) - if helpers.trace then - helpers.report("locating '%s' using normal loader",name) - end - return true,searchers[-2](name) -end -local function loadedbypath(name,rawname,paths,islib,what) - local trace=helpers.trace - local report=helpers.report - if trace then - report("locating '%s' as '%s' on '%s' paths",rawname,name,what) - end - for p=1,#paths do - local path=paths[p] - local resolved=filejoin(path,name) - if trace then - report("checking for '%s' using '%s' path '%s'",name,what,path) - end - if isreadable(resolved) then - if trace then - report("lib '%s' located on '%s'",name,resolved) - end - if islib then - return true,loadedaslib(resolved,rawname) - else - return true,loadfile(resolved) - end - end - end -end -local function notloaded(name) - if helpers.trace then - helpers.report("unable to locate library '%s'",name) - end -end -helpers.loadedaslib=loadedaslib -helpers.loadedbylua=loadedbylua -helpers.loadedbypath=loadedbypath -helpers.notloaded=notloaded -function helpers.loaded(name) - local thename=gsub(name,"%.","/") - local luaname=addsuffix(thename,"lua") - local libname=addsuffix(thename,os.libsuffix or "so") - local libpaths=getlibpaths() - local clibpaths=getclibpaths() - local done,result=loadedbypath(luaname,name,libpaths,false,"lua") - if done then - return result - end - local done,result=loadedbypath(luaname,name,clibpaths,false,"lua") - if done then - return result - end - local done,result=loadedbypath(libname,name,clibpaths,true,"lib") - if done then - return result - end - local done,result=loadedbylua(name) - if done then - return result - end - return notloaded(name) -end -function helpers.unload(name) - if helpers.trace then - if package.loaded[name] then - helpers.report("unloading library '%s', %s",name,"done") - else - helpers.report("unloading library '%s', %s",name,"not loaded") - end - end - package.loaded[name]=nil -end end -- closure @@ -5172,6 +5020,7 @@ local lpegmatch=lpeg.match local reversed,concat,remove=table.reversed,table.concat,table.remove local ioflush=io.flush local fastcopy,tohash,derivetable=table.fastcopy,table.tohash,table.derive +local formatters=string.formatters local allocate=utilities.storage.allocate local registertracker=trackers.register local registerdirective=directives.register @@ -5190,7 +5039,7 @@ local report_otf=logs.reporter("fonts","otf loading") local fonts=fonts local otf=fonts.handlers.otf otf.glists={ "gsub","gpos" } -otf.version=2.741 +otf.version=2.742 otf.cache=containers.define("fonts","otf",otf.version,true) local fontdata=fonts.hashes.identifiers local chardata=characters and characters.data @@ -6153,7 +6002,18 @@ local function t_hashed(t,cache) return nil end end -local s_hashed=t_hashed +local function s_hashed(t,cache) + if t then + local ht={} + local tf=t[1] + for i=1,#tf do + ht[i]={ [tf[i]]=true } + end + return ht + else + return nil + end +end local function r_uncover(splitter,cache,cover,replacements) if cover=="" then return nil |