diff options
author | Hans Hagen <pragma@wxs.nl> | 2013-03-05 16:40:00 +0100 |
---|---|---|
committer | Hans Hagen <pragma@wxs.nl> | 2013-03-05 16:40:00 +0100 |
commit | 7be0d39244155e874321d77ef81078c5bd2817a9 (patch) | |
tree | 0c09404e97c825961c5ee25a31ecab080eff54e6 /scripts | |
parent | 4eeccc18e84e817ecf7045bcb0a8d35875006f42 (diff) | |
download | context-7be0d39244155e874321d77ef81078c5bd2817a9.tar.gz |
beta 2013.03.05 16:40
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/context/lua/mtxlibs.lua | 239 | ||||
-rw-r--r-- | scripts/context/lua/mtxrun.lua | 20 | ||||
-rw-r--r-- | scripts/context/stubs/mswin/mtxrun.lua | 20 | ||||
-rwxr-xr-x | scripts/context/stubs/unix/mtxrun | 20 |
4 files changed, 266 insertions, 33 deletions
diff --git a/scripts/context/lua/mtxlibs.lua b/scripts/context/lua/mtxlibs.lua new file mode 100644 index 000000000..59cfa3dc2 --- /dev/null +++ b/scripts/context/lua/mtxlibs.lua @@ -0,0 +1,239 @@ +if not modules then modules = { } end modules ['mtxlibs'] = { + version = 1.001, + comment = "a reasonable subset of mtxrun preloaded libraries", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +-- This file can be used to load a the (relevant) helper libraries that are also used +-- in ConTeXt. You can use it as: +-- +-- -- if needed (outside texlua): +-- +-- -- require("lpeg") -- mandate +-- -- require("md5") -- handy +-- -- require("lfs") -- recommended +-- -- require("slunicode") -- sort of obsolete +-- +-- -- the library: +-- +-- require("mtxlibs") +-- +-- An alternative is to merge all libraries into this one so that you don't have to +-- distribute them. +-- +-- mtxlibs --selfmerge +-- +-- If you need additional libraries, you can do something like this: +-- +-- lua mtxlibs.lua --selfmerge my-web-project.lua trac-lmx util-jsn +-- lua mtxlibs.lua --selfmerge my-sql-project.lua util-sql util-sql-imp-library util-sql-imp-client +-- +-- That way you only need to update one file in a project and are not dependent on changes +-- in the core ConTeXT libraries. The libraries are maintained as part of ConTeXt and used +-- in projects so relative stable. The code works in Lua 5.1 as well as in 5.2. Not all +-- functionality makes sense for users who are not familiar with ConTeXt but for instance +-- trackers and loggers are included because that way we have can provide users with a +-- consistent ecosystem. +-- +-- Much of the provided functionality is described in cld-mkiv.pdf and related manuals, on +-- contextgarden.net as well in articles. The XML subsystem is described in its own manual. +-- Templates and SQL (not preloaded) is also has its own manual. +-- +-- The next section contains the merged code, with each block ending uop in its own +-- closure. The code gets somewhat compacted to save space and speed up loading. +-- +-- There are some dependencies between the several modules. Also, quite some functions are added +-- to the regular Lua namespaces. In due time I'll isolate them in their own namespaces but with +-- the for context handy option to expose them in the normal ones. I might make the dependencies +-- less but it probably makes no sense to waste time on them. + +if not lpeg then require("lpeg") end +-- not md5 then require("md5") end -- once we have the libs +-- not lfs then require("lfs") end -- once we have the libs + +-- begin library merge + +-- end library merge + +local format, gsub, gmatch, match, find = string.format, string.gsub, string.gmatch, string.match, string.find +local concat = table.concat + +local ownname = arg and arg[0] or 'mtxlibs.lua' +local ownpath = gsub(match(ownname,"^(.+)[\\/].-$") or ".","\\","/") +local owntree = ownpath + +local ownlibs = { + + "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", -- limited functionality when no lfs + "l-md5.lua", -- not loaded when no md5 library + "l-url.lua", + "l-dir.lua", -- limited functionality when no lfs + "l-boolean.lua", + "l-unicode.lua", -- nowadays independent of slunicode + "l-math.lua", + + "util-tab.lua", + "util-sto.lua", + "util-str.lua", + "util-mrg.lua", + -- "util-lua.lua", -- no need for compiling + "util-prs.lua", + -- "util-fmt.lua", -- no need for table formatters + -- "util-deb.lua", -- no need for debugging (and tracing) + + "trac-inf.lua", + "trac-set.lua", + "trac-log.lua", + -- "trac-pro.lua", -- not relevant outside context + + "util-tpl.lua", + + "util-env.lua", + -- "luat-env.lua", -- not relevant outside context + + "lxml-tab.lua", + "lxml-lpt.lua", + "lxml-mis.lua", + "lxml-aux.lua", + "lxml-xml.lua", + +} + +package.path = "t:/sources/?.lua;t:/sources/?;" .. package.path + +local ownlist = { + '.', + ownpath , + ownpath .. "/../sources", -- HH's development path + owntree .. "/../../texmf-local/tex/context/base", + owntree .. "/../../texmf-context/tex/context/base", + owntree .. "/../../texmf-dist/tex/context/base", + owntree .. "/../../texmf/tex/context/base", + owntree .. "/../../../texmf-local/tex/context/base", + owntree .. "/../../../texmf-context/tex/context/base", + owntree .. "/../../../texmf-dist/tex/context/base", + owntree .. "/../../../texmf/tex/context/base", +} + +if ownpath == "." then table.remove(ownlist,1) end + +own = { + name = ownname, + path = ownpath, + tree = owntree, + list = ownlist, + libs = ownlibs, +} + +local function locate_libs() + local name = ownlibs[1] + local done = false + for i=1,#ownlist do + local path = ownlist[i] + local filename = path .. "/" .. name + local f = io.open(filename) + if f then + f:close() + package.path = package.path .. ";" .. path .. "/?.lua" -- in case l-* does a require + done = path + break + end + end + locate_libs = function() return done end + return done +end + +local function load_libs() + local found = locate_libs() + if found then + for i=1,#ownlibs do + local basename = ownlibs[i] + local filename = found .. "/" .. basename + local codeblob = loadfile(filename) + if codeblob then + package.preload[basename] = codeblob() or true + end + end + end +end + +if not unicode then + load_libs() +end + +local merger = utilities and utilities.merger + +if not merger then + return +end + +local arguments = environment.arguments +local files = environment.files + +if environment.ownname ~= "mtxlibs.lua" then + return +end + +local helpinfo = [[ +usage: mtxlibs [options] + +--merge +--merge targetfile extralibs +--selfclean + +and in a lua file: + +require("mtxlibs") +]] + +local application = logs.application { + name = "mtxlibs", + banner = "ConTeXt Basic Lua Libraries 1.00", + helpinfo = helpinfo, +} + +local report = application.report + +if arguments.selfmerge then + + report("merging libraries") + local found = locate_libs() + if found then + local target = files[1] + if target == ownname then + report("target cannot be this file") + return + elseif target then + report("target: %s",target) + for i=1,#files do + ownlibs[#ownlibs+1] = file.addsuffix(files[i],"lua") + end + end + merger.selfmerge(ownname,ownlibs,{ found },target) + report("done") + else + report("no libraries found") + end + +elseif arguments.selfclean then + + report("cleaning libraries") + merger.selfclean(ownname) + report("done") + +elseif arguments.help or files[1] == "help" then + + application.help() + +end diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index 3281ba11f..c5bcd7ef5 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -3661,7 +3661,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-boolean"] = package.loaded["l-boolean"] or true --- original size: 1822, stripped down to: 1544 +-- original size: 1781, stripped down to: 1503 if not modules then modules={} end modules ['l-boolean']={ version=1.001, @@ -3676,7 +3676,7 @@ local boolean=boolean function boolean.tonumber(b) if b then return 1 else return 0 end end -function toboolean(str,tolerant) +function toboolean(str,tolerant) if str==nil then return false elseif str==false then @@ -3699,18 +3699,16 @@ function toboolean(str,tolerant) end string.toboolean=toboolean function string.booleanstring(str) - if str==nil then - return false - elseif str==false then + if str=="0" then return false - elseif str==true then - return true - elseif str=="true" then + elseif str=="1" then return true - elseif str=="false" then + elseif str=="" then return false - elseif str==0 then + elseif str=="false" then return false + elseif str=="true" then + return true elseif (tonumber(str) or 0)>0 then return true else @@ -15081,7 +15079,7 @@ 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-tab.lua util-sto.lua util-str.lua util-mrg.lua util-lua.lua util-prs.lua util-fmt.lua util-deb.lua trac-inf.lua trac-set.lua trac-log.lua trac-pro.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 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 luat-sta.lua luat-fmt.lua -- skipped libraries : - --- original bytes : 602447 +-- original bytes : 602406 -- stripped bytes : 204162 -- end library merge diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index 3281ba11f..c5bcd7ef5 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -3661,7 +3661,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-boolean"] = package.loaded["l-boolean"] or true --- original size: 1822, stripped down to: 1544 +-- original size: 1781, stripped down to: 1503 if not modules then modules={} end modules ['l-boolean']={ version=1.001, @@ -3676,7 +3676,7 @@ local boolean=boolean function boolean.tonumber(b) if b then return 1 else return 0 end end -function toboolean(str,tolerant) +function toboolean(str,tolerant) if str==nil then return false elseif str==false then @@ -3699,18 +3699,16 @@ function toboolean(str,tolerant) end string.toboolean=toboolean function string.booleanstring(str) - if str==nil then - return false - elseif str==false then + if str=="0" then return false - elseif str==true then - return true - elseif str=="true" then + elseif str=="1" then return true - elseif str=="false" then + elseif str=="" then return false - elseif str==0 then + elseif str=="false" then return false + elseif str=="true" then + return true elseif (tonumber(str) or 0)>0 then return true else @@ -15081,7 +15079,7 @@ 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-tab.lua util-sto.lua util-str.lua util-mrg.lua util-lua.lua util-prs.lua util-fmt.lua util-deb.lua trac-inf.lua trac-set.lua trac-log.lua trac-pro.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 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 luat-sta.lua luat-fmt.lua -- skipped libraries : - --- original bytes : 602447 +-- original bytes : 602406 -- stripped bytes : 204162 -- end library merge diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index 3281ba11f..c5bcd7ef5 100755 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -3661,7 +3661,7 @@ do -- create closure to overcome 200 locals limit package.loaded["l-boolean"] = package.loaded["l-boolean"] or true --- original size: 1822, stripped down to: 1544 +-- original size: 1781, stripped down to: 1503 if not modules then modules={} end modules ['l-boolean']={ version=1.001, @@ -3676,7 +3676,7 @@ local boolean=boolean function boolean.tonumber(b) if b then return 1 else return 0 end end -function toboolean(str,tolerant) +function toboolean(str,tolerant) if str==nil then return false elseif str==false then @@ -3699,18 +3699,16 @@ function toboolean(str,tolerant) end string.toboolean=toboolean function string.booleanstring(str) - if str==nil then - return false - elseif str==false then + if str=="0" then return false - elseif str==true then - return true - elseif str=="true" then + elseif str=="1" then return true - elseif str=="false" then + elseif str=="" then return false - elseif str==0 then + elseif str=="false" then return false + elseif str=="true" then + return true elseif (tonumber(str) or 0)>0 then return true else @@ -15081,7 +15079,7 @@ 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-tab.lua util-sto.lua util-str.lua util-mrg.lua util-lua.lua util-prs.lua util-fmt.lua util-deb.lua trac-inf.lua trac-set.lua trac-log.lua trac-pro.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 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 luat-sta.lua luat-fmt.lua -- skipped libraries : - --- original bytes : 602447 +-- original bytes : 602406 -- stripped bytes : 204162 -- end library merge |