From 74502160056d9c1df64f653bf2364efbb2e7a56b Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 11 Apr 2013 14:18:19 +0200 Subject: add support for merge files; split into basic/extended --- lualibs.lua | 84 +++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 60 insertions(+), 24 deletions(-) (limited to 'lualibs.lua') diff --git a/lualibs.lua b/lualibs.lua index cf9b039..79e17fd 100644 --- a/lualibs.lua +++ b/lualibs.lua @@ -18,37 +18,73 @@ module('lualibs', package.seeall) local lualibs_module = { name = "lualibs", - version = 0.97, - date = "2012/10/19", + version = 1.01, + date = "2013/04/10", description = "Lua additional functions.", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux", copyright = "PRAGMA ADE / ConTeXt Development Team", license = "See ConTeXt's mreadme.pdf for the license", } +local lpeg, kpse = lpeg, kpse + +local dofile = dofile +local lpegmatch = lpeg.match +local stringformat = string.format + +local find_file, error, warn, info if luatexbase and luatexbase.provides_module then - luatexbase.provides_module(lualibs_module) + error, warn, info = luatexbase.provides_module(lualibs_module) +else + error, warn, info = texio.write_nl, texio.write_nl, texio.write_nl -- stub +end +if luatexbase and luatexbase.find_file then + find_file = luatexbase.find_file +else + kpse.set_program_name"luatex" + find_file = kpse.find_file end -require("lualibs-string") -require("lualibs-lpeg") -require("lualibs-boolean") -require("lualibs-number") -require("lualibs-math") -require("lualibs-table") -require("lualibs-io") -require("lualibs-os") -require("lualibs-file") -require("lualibs-md5") -require("lualibs-dir") -require("lualibs-unicode") -require("lualibs-url") -require("lualibs-set") -require("lualibs-util-lua") -require("lualibs-util-sto") -require("lualibs-util-mrg") -require("lualibs-util-dim") -require("lualibs-util-str") -require("lualibs-util-tab") -require("lualibs-util-jsn") + +loadmodule = _ENV.loadmodule or function (name, t) + if not t then t = "library" end + local filepath = kpse.find_file(name, "lua") + if not filepath or filepath == "" then + warn(stringformat("Could not locate %s “%s”.", t, name)) + return false + end + dofile(filepath) + return true +end + +local merged_suffix = "-merged.lua" + +local p_suffix = lpeg.P".lua" * lpeg.P(-1) +local p_nosuffix = (1 - p_suffix)^0 +local p_hassuffix = (p_nosuffix) * p_suffix +local p_stripsuffix = lpeg.C(p_nosuffix) * p_suffix + +local loadmerged = function (basename) + basename = lualibs_module.name .. "-" .. basename + if not lpegmatch(p_hassuffix, basename) then -- force .lua suffix + basename = basename .. ".lua" + end + local mergedname = lpegmatch(p_stripsuffix, basename) .. merged_suffix + local res = loadmodule(mergedname, "merged package") + if not res then -- package not present, load individual libs + info(stringformat("Falling back to “%s”.", basename)) + res = loadmodule(basename, "metapackage") + end + if res == false then + error(stringformat("Could not load metapackage “%s”.", basename)) + end +end + +loadmerged"basic.lua" +--inspect(table.keys(table)) +--inspect(table.keys(string)) +loadmerged"extended.lua" + +io.write"\n" -- +-- vim:tw=71:sw=2:ts=2:expandtab -- End of File `lualibs.lua'. -- cgit v1.2.3 From 11cc58366d0e7ae42e6779e26ad460b1ac182dc5 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 11 Apr 2013 14:31:26 +0200 Subject: add opt-out for merged packages --- lualibs.lua | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) (limited to 'lualibs.lua') diff --git a/lualibs.lua b/lualibs.lua index 79e17fd..a38f974 100644 --- a/lualibs.lua +++ b/lualibs.lua @@ -1,31 +1,18 @@ --- -- This is file `lualibs.lua', --- generated with the docstrip utility. --- --- The original source files were: --- --- lualibs.dtx (with options: `lua') --- This is a generated file. --- --- Copyright (C) 2009 by PRAGMA ADE / ConTeXt Development Team --- --- See ConTeXt's mreadme.pdf for the license. --- --- This work consists of the main source file lualibs.dtx --- and the derived file lualibs.lua. --- module('lualibs', package.seeall) local lualibs_module = { - name = "lualibs", - version = 1.01, - date = "2013/04/10", - description = "Lua additional functions.", - author = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux", - copyright = "PRAGMA ADE / ConTeXt Development Team", - license = "See ConTeXt's mreadme.pdf for the license", + name = "lualibs", + version = 1.01, + date = "2013/04/10", + description = "Lua additional functions.", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL & Elie Roux", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "See ConTeXt's mreadme.pdf for the license", } +local prefer_merged = true -- | false --- TODO should be set in some global config + local lpeg, kpse = lpeg, kpse local dofile = dofile @@ -68,8 +55,13 @@ local loadmerged = function (basename) if not lpegmatch(p_hassuffix, basename) then -- force .lua suffix basename = basename .. ".lua" end - local mergedname = lpegmatch(p_stripsuffix, basename) .. merged_suffix - local res = loadmodule(mergedname, "merged package") + local res + if prefer_merged then + local mergedname = lpegmatch(p_stripsuffix, basename) .. merged_suffix + res = loadmodule(mergedname, "merged package") + else + info"Ignoring merged packages." + end if not res then -- package not present, load individual libs info(stringformat("Falling back to “%s”.", basename)) res = loadmodule(basename, "metapackage") @@ -87,4 +79,4 @@ loadmerged"extended.lua" io.write"\n" -- -- vim:tw=71:sw=2:ts=2:expandtab --- End of File `lualibs.lua'. +-- End of File `lualibs-basic.lua'. -- cgit v1.2.3 From 88b50eb56c6effbf943ce2fd9afbfe41a5cec45e Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 11 Apr 2013 15:15:12 +0200 Subject: add extended sequence --- lualibs.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lualibs.lua') diff --git a/lualibs.lua b/lualibs.lua index a38f974..7255147 100644 --- a/lualibs.lua +++ b/lualibs.lua @@ -32,7 +32,7 @@ else find_file = kpse.find_file end -loadmodule = _ENV.loadmodule or function (name, t) +loadmodule = _G.loadmodule or function (name, t) if not t then t = "library" end local filepath = kpse.find_file(name, "lua") if not filepath or filepath == "" then @@ -71,11 +71,19 @@ local loadmerged = function (basename) end end +--[[doc-- +The separation of the “basic” from the “extended” sets coincides with +the split into luat-bas.mkiv and luat-lib.mkiv. +--doc]]-- loadmerged"basic.lua" --inspect(table.keys(table)) --inspect(table.keys(string)) loadmerged"extended.lua" +--- merge generates wrong syntax for this one, so we load it separately +--- http://www.ntg.nl/pipermail/ntg-context/2013/072336.html +--loadmodule"util-dim" + io.write"\n" -- -- vim:tw=71:sw=2:ts=2:expandtab -- cgit v1.2.3 From a82b2398f53a404a7dab6f6bba6e123dcaf62d8a Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 11 Apr 2013 23:31:23 +0200 Subject: clean stubs after Hans fixed upstream --- lualibs.lua | 6 ------ 1 file changed, 6 deletions(-) (limited to 'lualibs.lua') diff --git a/lualibs.lua b/lualibs.lua index 7255147..13fefff 100644 --- a/lualibs.lua +++ b/lualibs.lua @@ -80,11 +80,5 @@ loadmerged"basic.lua" --inspect(table.keys(string)) loadmerged"extended.lua" ---- merge generates wrong syntax for this one, so we load it separately ---- http://www.ntg.nl/pipermail/ntg-context/2013/072336.html ---loadmodule"util-dim" - -io.write"\n" --- -- vim:tw=71:sw=2:ts=2:expandtab -- End of File `lualibs-basic.lua'. -- cgit v1.2.3 From 7cead7f43cd14b36b30c42544ef1a458df8fdf5a Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sat, 13 Apr 2013 18:56:37 +0200 Subject: configuration by global --- lualibs.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lualibs.lua') diff --git a/lualibs.lua b/lualibs.lua index 13fefff..ec02a5a 100644 --- a/lualibs.lua +++ b/lualibs.lua @@ -11,7 +11,16 @@ local lualibs_module = { license = "See ConTeXt's mreadme.pdf for the license", } -local prefer_merged = true -- | false --- TODO should be set in some global config +--- TODO should be set in some global config +local prefer_merged = true ---false +local load_extended = true ---false + +if config and config.lualibs then + local cl_prefer_merged = config.lualibs.prefer_merged + local cl_load_extended = config.lualibs.load_extended + if cl_prefer_merged ~= nil then prefer_merged = cl_prefer_merged end + if cl_load_extended ~= nil then load_extended = cl_load_extended end +end local lpeg, kpse = lpeg, kpse @@ -78,7 +87,9 @@ the split into luat-bas.mkiv and luat-lib.mkiv. loadmerged"basic.lua" --inspect(table.keys(table)) --inspect(table.keys(string)) -loadmerged"extended.lua" +if load_extended then + loadmerged"extended.lua" +end -- vim:tw=71:sw=2:ts=2:expandtab -- End of File `lualibs-basic.lua'. -- cgit v1.2.3 From 419e509d1b2760c0f84bd825ed6a0cb107cee45f Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sat, 13 Apr 2013 19:22:17 +0200 Subject: fix fake Context layer --- lualibs.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lualibs.lua') diff --git a/lualibs.lua b/lualibs.lua index ec02a5a..cd0034e 100644 --- a/lualibs.lua +++ b/lualibs.lua @@ -87,7 +87,7 @@ the split into luat-bas.mkiv and luat-lib.mkiv. loadmerged"basic.lua" --inspect(table.keys(table)) --inspect(table.keys(string)) -if load_extended then +if load_extended == true then loadmerged"extended.lua" end -- cgit v1.2.3 From 120ce3327618dea784a0482f1db6295b4168062c Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 14 Apr 2013 02:19:52 +0200 Subject: work around merging restrictions --- lualibs.lua | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) (limited to 'lualibs.lua') diff --git a/lualibs.lua b/lualibs.lua index cd0034e..59d7907 100644 --- a/lualibs.lua +++ b/lualibs.lua @@ -12,7 +12,7 @@ local lualibs_module = { } --- TODO should be set in some global config -local prefer_merged = true ---false +prefer_merged = true ---false local load_extended = true ---false if config and config.lualibs then @@ -59,36 +59,13 @@ local p_nosuffix = (1 - p_suffix)^0 local p_hassuffix = (p_nosuffix) * p_suffix local p_stripsuffix = lpeg.C(p_nosuffix) * p_suffix -local loadmerged = function (basename) - basename = lualibs_module.name .. "-" .. basename - if not lpegmatch(p_hassuffix, basename) then -- force .lua suffix - basename = basename .. ".lua" - end - local res - if prefer_merged then - local mergedname = lpegmatch(p_stripsuffix, basename) .. merged_suffix - res = loadmodule(mergedname, "merged package") - else - info"Ignoring merged packages." - end - if not res then -- package not present, load individual libs - info(stringformat("Falling back to “%s”.", basename)) - res = loadmodule(basename, "metapackage") - end - if res == false then - error(stringformat("Could not load metapackage “%s”.", basename)) - end -end - --[[doc-- The separation of the “basic” from the “extended” sets coincides with the split into luat-bas.mkiv and luat-lib.mkiv. --doc]]-- -loadmerged"basic.lua" ---inspect(table.keys(table)) ---inspect(table.keys(string)) +loadmodule"lualibs-basic.lua" if load_extended == true then - loadmerged"extended.lua" + loadmodule"lualibs-extended.lua" end -- vim:tw=71:sw=2:ts=2:expandtab -- cgit v1.2.3 From 9d3e292ead8e354c836d0c4dcd25e0b4aa03486c Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 14 Apr 2013 19:23:40 +0200 Subject: add compatibility for luaotfload v.1 --- lualibs.lua | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'lualibs.lua') diff --git a/lualibs.lua b/lualibs.lua index 59d7907..4f354b5 100644 --- a/lualibs.lua +++ b/lualibs.lua @@ -52,18 +52,13 @@ loadmodule = _G.loadmodule or function (name, t) return true end -local merged_suffix = "-merged.lua" - -local p_suffix = lpeg.P".lua" * lpeg.P(-1) -local p_nosuffix = (1 - p_suffix)^0 -local p_hassuffix = (p_nosuffix) * p_suffix -local p_stripsuffix = lpeg.C(p_nosuffix) * p_suffix - --[[doc-- The separation of the “basic” from the “extended” sets coincides with the split into luat-bas.mkiv and luat-lib.mkiv. --doc]]-- loadmodule"lualibs-basic.lua" +loadmodule"lualibs-compat.lua" --- restore stuff gone since v1.* + if load_extended == true then loadmodule"lualibs-extended.lua" end -- cgit v1.2.3 From 1e04ecc2c4918448e8ff30a2e6363025267cac79 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 21 Apr 2013 00:55:45 +0200 Subject: add rudimentary verbosity switch --- lualibs.lua | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'lualibs.lua') diff --git a/lualibs.lua b/lualibs.lua index 4f354b5..f126fb7 100644 --- a/lualibs.lua +++ b/lualibs.lua @@ -11,16 +11,13 @@ local lualibs_module = { license = "See ConTeXt's mreadme.pdf for the license", } ---- TODO should be set in some global config -prefer_merged = true ---false -local load_extended = true ---false +_G.config = _G.config or { } +_G.config.lualibs = _G.config.lualibs or { } +local lualibs = _G.config.lualibs -if config and config.lualibs then - local cl_prefer_merged = config.lualibs.prefer_merged - local cl_load_extended = config.lualibs.load_extended - if cl_prefer_merged ~= nil then prefer_merged = cl_prefer_merged end - if cl_load_extended ~= nil then load_extended = cl_load_extended end -end +if lualibs.prefer_merged == nil then lualibs.prefer_merged = true end +if lualibs.load_extended == nil then lualibs.load_extended = true end +lualibs.verbose = lualibs.verbose == true or false local lpeg, kpse = lpeg, kpse @@ -29,11 +26,24 @@ local lpegmatch = lpeg.match local stringformat = string.format local find_file, error, warn, info -if luatexbase and luatexbase.provides_module then - error, warn, info = luatexbase.provides_module(lualibs_module) -else - error, warn, info = texio.write_nl, texio.write_nl, texio.write_nl -- stub +do + local _error, _warn, _info + if luatexbase and luatexbase.provides_module then + _error, _warn, _info = luatexbase.provides_module(lualibs_module) + else + _error, _warn, _info = texio.write_nl, texio.write_nl, texio.write_nl -- stub + end + + -- if lualibs.verbose then + if lualibs.verbose then + error, warn, info = _error, _warn, _info + else + local dummylogger = function ( ) end + error, warn, info = _error, dummylogger, dummylogger + end + lualibs.error, lualibs.warn, lualibs.info = error, warn, info end + if luatexbase and luatexbase.find_file then find_file = luatexbase.find_file else @@ -51,6 +61,7 @@ loadmodule = _G.loadmodule or function (name, t) dofile(filepath) return true end +lualibs.loadmodule = loadmodule --[[doc-- The separation of the “basic” from the “extended” sets coincides with -- cgit v1.2.3