From b05a48f1a220aa87d6ac208529d7975e092cec3a Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 6 May 2013 22:04:07 +0000 Subject: luatexbase (6may13) git-svn-id: svn://tug.org/texlive/trunk@30250 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/luatex/luatexbase/attr.lua | 190 ++++++++++++++++++++- Master/texmf-dist/tex/luatex/luatexbase/cctb.lua | 12 +- .../tex/luatex/luatexbase/luatexbase-attr.sty | 6 +- .../tex/luatex/luatexbase/luatexbase.loader.lua | 11 +- .../tex/luatex/luatexbase/luatexbase.sty | 2 +- Master/texmf-dist/tex/luatex/luatexbase/mcb.lua | 27 ++- .../texmf-dist/tex/luatex/luatexbase/modutils.lua | 97 +++++++++-- 7 files changed, 312 insertions(+), 33 deletions(-) (limited to 'Master/texmf-dist/tex/luatex/luatexbase') diff --git a/Master/texmf-dist/tex/luatex/luatexbase/attr.lua b/Master/texmf-dist/tex/luatex/luatexbase/attr.lua index e21e47d0c11..3f66fd78e9d 100644 --- a/Master/texmf-dist/tex/luatex/luatexbase/attr.lua +++ b/Master/texmf-dist/tex/luatex/luatexbase/attr.lua @@ -8,8 +8,48 @@ -- -- See the aforementioned source file(s) for copyright and licensing information. -- -module('luatexbase', package.seeall) -attributes = {} +--- locals +local copynode = node.copy +local newnode = node.new +local nodesubtype = node.subtype +local nodetype = node.id +local stringfind = string.find +local stringformat = string.format +local tableunpack = unpack or table.unpack +local texiowrite_nl = texio.write_nl +local texiowrite = texio.write +--- luatex internal types +local whatsit_t = nodetype"whatsit" +local user_defined_t = nodesubtype"user_defined" +local unassociated = "__unassociated" +luatexbase = luatexbase or { } +local luatexbase = luatexbase +local reporter = function (log, category, ...) + if log == true then + texiowrite_nl("log", "("..category..") ") + texiowrite("log", stringformat(...)) + else + texiowrite_nl("("..category..") ") + texiowrite(stringformat(...)) + end +end +local warning = function (...) reporter (false, "warning", ...) end +----- info = function (...) reporter (false, "info", ...) end +local log = function (...) reporter (true, "log", ...) end +luatexbase.attributes = luatexbase.attributes or { } +local attributes = luatexbase.attributes +local new_attribute +local unset_attribute +local luatex_sty_counter = 'LuT@AllocAttribute' +if tex.count[luatex_sty_counter] then + if tex.count[luatex_sty_counter] > -1 then + error("luatexbase error: attribute 0 has already been set by \newattribute" + .."macro from luatex.sty, not belonging to this package, this makes" + .."luaotfload unusable. Please report to the maintainer of luatex.sty") + else + tex.count[luatex_sty_counter] = 0 + end +end local last_alloc = 0 function new_attribute(name, silent) if last_alloc >= 65535 then @@ -19,18 +59,160 @@ function new_attribute(name, silent) error("No room for a new \\attribute", 1) end end + local lsc = tex.count[luatex_sty_counter] + if lsc and lsc > last_alloc then + last_alloc = lsc + end last_alloc = last_alloc + 1 + if lsc then + tex.setcount('global', luatex_sty_counter, last_alloc) + end attributes[name] = last_alloc unset_attribute(name) if not silent then - texio.write_nl('log', string.format( - 'luatexbase.attributes[%q] = %d', name, last_alloc)) + log('luatexbase.attributes[%q] = %d', name, last_alloc) end return last_alloc end +luatexbase.new_attribute = new_attribute local unset_value = (luatexbase.luatexversion < 37) and -1 or -2147483647 function unset_attribute(name) tex.setattribute(attributes[name], unset_value) end +luatexbase.unset_attribute = unset_attribute +--- cf. luatexref-t.pdf, sect. 8.1.4.25 +local user_whatsits = { --- (package, (name, id hash)) hash + __unassociated = { }, --- those without package name +} +local whatsit_ids = { } --- (id, (name * package)) hash +local whatsit_cap = 2^53 --- Lua numbers are doubles +local current_whatsit = 0 +local anonymous_whatsits = 0 +local anonymous_prefix = "anon" +--- string -> string -> int +local new_user_whatsit_id = function (name, package) + if name then + if not package then + package = unassociated + end + else -- anonymous + anonymous_whatsits = anonymous_whatsits + 1 + warning("defining anonymous user whatsit no. %d", anonymous_whatsits) + warning("dear package authors, please name your whatsits!") + package = unassociated + name = anonymous_prefix .. tostring(anonymous_whatsits) + end + + local whatsitdata = user_whatsits[package] + if not whatsitdata then + whatsitdata = { } + user_whatsits[package] = whatsitdata + end + + local id = whatsitdata[name] + if id then --- warning + warning("replacing whatsit %s:%s (%d)", package, name, id) + else --- new id + current_whatsit = current_whatsit + 1 + if current_whatsit >= whatsit_cap then + warning("maximum of %d integral user whatsit ids reached", + whatsit_cap) + warning("further whatsit allocation may be inconsistent") + end + id = current_whatsit + whatsitdata[name] = id + whatsit_ids[id] = { name, package } + end + log("new user-defined whatsit %d (%s:%s)", id, package, name) + return id +end +luatexbase.new_user_whatsit_id = new_user_whatsit_id +--- string -> string -> (unit -> node_t, int) +local new_user_whatsit = function (name, package) + local id = new_user_whatsit_id(name, package) + local whatsit = newnode(whatsit_t, user_defined_t) + whatsit.user_id = id + --- unit -> node_t + return function ( ) return copynode(whatsit) end, id +end +luatexbase.new_user_whatsit = new_user_whatsit +luatexbase.new_user_whatsit_factory = new_user_whatsit --- for Stephan +--- string -> string -> int +local get_user_whatsit_id = function (name, package) + if not package then + package = unassociated + end + return user_whatsits[package][name] +end +luatexbase.get_user_whatsit_id = get_user_whatsit_id +--- int | fun | node -> (string, string) +local get_user_whatsit_name = function (asked) + local id + if type(asked) == "number" then + id = asked + elseif type(asked) == "function" then + --- node generator + local n = asked() + id = n.user_id + else --- node + id = asked.user_id + end + local metadata = whatsit_ids[id] + if not metadata then -- unknown + warning("whatsit id %d unregistered; inconsistencies may arise", id) + return "", "" + end + return tableunpack(metadata) +end +luatexbase.get_user_whatsit_name = get_user_whatsit_name +--- string -> unit +local dump_registered_whatsits = function (asked_package) + local whatsit_list = { } + if asked_package then + local whatsitdata = user_whatsits[asked_package] + if not whatsitdata then + error("(no user whatsits registered for package %s)", + asked_package) + return + end + texiowrite_nl("(user whatsit allocation stats for " .. asked_package) + for name, id in next, whatsitdata do + whatsit_list[#whatsit_list+1] = + stringformat("(%s:%s %d)", asked_package, name, id) + end + else + texiowrite_nl("(user whatsit allocation stats") + texiowrite_nl(stringformat(" ((total %d)\n (anonymous %d))", + current_whatsit, anonymous_whatsits)) + for package, whatsitdata in next, user_whatsits do + for name, id in next, whatsitdata do + whatsit_list[#whatsit_list+1] = + stringformat("(%s:%s %d)", package, name, id) + end + end + end + + texiowrite_nl" (" + --- in an attempt to be clever the texio.write* functions + --- mess up line breaking, so concatenation is unusable ... + local first = true + for i=1, #whatsit_list do + if first then + first = false + else -- indent + texiowrite_nl" " + end + texiowrite(whatsit_list[i]) + end + texiowrite"))\n" +end +luatexbase.dump_registered_whatsits = dump_registered_whatsits +luatexbase.newattribute = new_attribute +luatexbase.newuserwhatsit = new_user_whatsit +luatexbase.newuserwhatsitfactory = new_user_whatsit_factory +luatexbase.newuserwhatsitid = new_user_whatsit_id +luatexbase.getuserwhatsitid = get_user_whatsit_id +luatexbase.getuserwhatsitname = get_user_whatsit_name +luatexbase.dumpregisteredwhatsits = dump_registered_whatsits -- -- End of File `attr.lua'. diff --git a/Master/texmf-dist/tex/luatex/luatexbase/cctb.lua b/Master/texmf-dist/tex/luatex/luatexbase/cctb.lua index 30ebd6aef33..48010a6b5b6 100644 --- a/Master/texmf-dist/tex/luatex/luatexbase/cctb.lua +++ b/Master/texmf-dist/tex/luatex/luatexbase/cctb.lua @@ -8,12 +8,15 @@ -- -- See the aforementioned source file(s) for copyright and licensing information. -- -module('luatexbase', package.seeall) -catcodetables = {} -function catcodetabledef_from_tex(name, number) +luatexbase = luatexbase or { } +local luatexbase = luatexbase +luatexbase.catcodetables = luatexbase.catcodetables or { } +local catcodetables = luatexbase.catcodetables +local function catcodetabledef_from_tex(name, number) catcodetables[name] = tonumber(number) end -function catcodetable_do_shortcuts() +luatexbase.catcodetabledef_from_tex = catcodetabledef_from_tex +local function catcodetable_do_shortcuts() local cat = catcodetables cat['latex'] = cat.CatcodeTableLaTeX cat['latex-package'] = cat.CatcodeTableLaTeXAtLetter @@ -24,5 +27,6 @@ function catcodetable_do_shortcuts() cat['string'] = cat.CatcodeTableString cat['other'] = cat.CatcodeTableOther end +luatexbase.catcodetable_do_shortcuts = catcodetable_do_shortcuts -- -- End of File `cctb.lua'. diff --git a/Master/texmf-dist/tex/luatex/luatexbase/luatexbase-attr.sty b/Master/texmf-dist/tex/luatex/luatexbase/luatexbase-attr.sty index fb0ab68989c..24153a73f52 100644 --- a/Master/texmf-dist/tex/luatex/luatexbase/luatexbase-attr.sty +++ b/Master/texmf-dist/tex/luatex/luatexbase/luatexbase-attr.sty @@ -49,9 +49,7 @@ \expandafter\y\csname luatexbase@attr@sty@endinput\endcsname% \begingroup \expandafter\ifx\csname ProvidesPackage\endcsname\relax - \def\x#1[#2]{% - %\immediate\write16{Package: #1 #2}} - } + \def\x#1[#2]{\immediate\write16{Package: #1 #2}} \else \let\x\ProvidesPackage \fi @@ -90,8 +88,10 @@ \begingroup\expandafter\expandafter\expandafter\endgroup \expandafter\ifx\csname RequirePackage\endcsname\relax \input luatexbase-loader.sty + \input luatex.sty \else \RequirePackage{luatexbase-loader} + \RequirePackage{luatex} \fi \luatexbase@directlua{require('luatexbase.attr')} \def\newluatexattribute#1{% diff --git a/Master/texmf-dist/tex/luatex/luatexbase/luatexbase.loader.lua b/Master/texmf-dist/tex/luatex/luatexbase/luatexbase.loader.lua index c10febfda88..fce0ab79ea4 100644 --- a/Master/texmf-dist/tex/luatex/luatexbase/luatexbase.loader.lua +++ b/Master/texmf-dist/tex/luatex/luatexbase/luatexbase.loader.lua @@ -8,8 +8,13 @@ -- -- See the aforementioned source file(s) for copyright and licensing information. -- -module('luatexbase', package.seeall) +luatexbase = luatexbase or { } +local luatexbase = luatexbase kpse.set_program_name("luatex") +local print_included_path = false +if token then + print_included_path = true +end local lua_suffixes = { ".luc", ".luctex", ".texluc", ".lua", ".luatex", ".texlua", } @@ -50,7 +55,9 @@ local function load_module(mod) if not loader then return "\n\t[luatexbase.loader] Loading error:\n\t"..error end - texio.write_nl("("..file..")") + if print_included_path then + texio.write_nl("("..file..")") + end return loader end package.searchers[2] = load_module diff --git a/Master/texmf-dist/tex/luatex/luatexbase/luatexbase.sty b/Master/texmf-dist/tex/luatex/luatexbase/luatexbase.sty index 5960b44bda7..e03fdafc49a 100644 --- a/Master/texmf-dist/tex/luatex/luatexbase/luatexbase.sty +++ b/Master/texmf-dist/tex/luatex/luatexbase/luatexbase.sty @@ -49,7 +49,7 @@ \let\x\ProvidesPackage \fi \expandafter\endgroup -\x{luatexbase}[2013/04/13 v0.5 Module utilities for LuaTeX] +\x{luatexbase}[2013/05/04 v0.6 Module utilities for LuaTeX] \begingroup\expandafter\expandafter\expandafter\endgroup \expandafter\ifx\csname RequirePackage\endcsname\relax \input ifluatex.sty diff --git a/Master/texmf-dist/tex/luatex/luatexbase/mcb.lua b/Master/texmf-dist/tex/luatex/luatexbase/mcb.lua index 08dc3a2abe4..e1c7ac80c3c 100644 --- a/Master/texmf-dist/tex/luatex/luatexbase/mcb.lua +++ b/Master/texmf-dist/tex/luatex/luatexbase/mcb.lua @@ -8,8 +8,9 @@ -- -- See the aforementioned source file(s) for copyright and licensing information. -- -module('luatexbase', package.seeall) -local err, warning, info = luatexbase.provides_module({ +luatexbase = luatexbase or { } +local luatexbase = luatexbase +local err, warning, info, log = luatexbase.provides_module({ name = "luatexbase-mcb", version = 0.5, date = "2013/04/13", @@ -18,6 +19,12 @@ local err, warning, info = luatexbase.provides_module({ copyright = "Hans Hagen, Elie Roux, Manuel Pegourie-Gonnard and Philipp Gesang", license = "CC0", }) +local add_to_callback +local call_callback +local create_callback +local priority_in_callback +local remove_from_callback +local reset_callback local callbacklist = callbacklist or { } local list, data, first, simple = 1, 2, 3, 4 local types = { @@ -174,9 +181,10 @@ function add_to_callback (name,func,description,priority) warning("several functions in '%s',\n" .."only one will be active.", name) end - info("inserting '%s'\nat position %s in '%s'", + log("inserting '%s'\nat position %s in '%s'", description, priority, name) end +luatexbase.add_to_callback = add_to_callback function remove_from_callback (name, description) if not name or name == "" then err("unable to remove function:\nno proper callback name passed") @@ -208,7 +216,7 @@ function remove_from_callback (name, description) return end table.remove(l, index) - info("removing '%s'\nfrom '%s'", description, name) + log("removing '%s'\nfrom '%s'", description, name) if #l == 0 then callbacklist[name] = nil if not lua_callbacks_defaults[name] then @@ -217,6 +225,7 @@ function remove_from_callback (name, description) end return end +luatexbase.remove_from_callback = remove_from_callback function reset_callback (name, make_false) if not name or name == "" then err("unable to reset:\nno proper callback name passed") @@ -225,17 +234,18 @@ function reset_callback (name, make_false) err("unable to reset '%s':\nis not a valid callback", name) return end - info("resetting callback '%s'", name) + log("resetting callback '%s'", name) callbacklist[name] = nil if not lua_callbacks_defaults[name] then if make_false == true then - info("setting '%s' to false", name) + log("setting '%s' to false", name) register_callback(name, false) else register_callback(name, nil) end end end +luatexbase.reset_callback = reset_callback function priority_in_callback (name, description) if not name or name == "" or not callbacktypes[name] @@ -251,6 +261,7 @@ function priority_in_callback (name, description) end return false end +luatexbase.priority_in_callback = priority_in_callback function create_callback(name, ctype, default) if not name then err("unable to call callback:\nno proper name passed", name) @@ -270,10 +281,11 @@ function create_callback(name, ctype, default) err("unable to create callback '%s':\ntype '%s' undefined", name, ctype) return nil end - info("creating '%s' type %s", name, ctype) + log("creating '%s' type %s", name, ctype) lua_callbacks_defaults[name] = default callbacktypes[name] = ctype end +luatexbase.create_callback = create_callback function call_callback(name, ...) if not name then err("unable to call callback:\nno proper name passed", name) @@ -296,5 +308,6 @@ function call_callback(name, ...) end return f(...) end +luatexbase.call_callback = call_callback -- -- End of File `mcb.lua'. diff --git a/Master/texmf-dist/tex/luatex/luatexbase/modutils.lua b/Master/texmf-dist/tex/luatex/luatexbase/modutils.lua index d3a4d541e1e..1df34a4edba 100644 --- a/Master/texmf-dist/tex/luatex/luatexbase/modutils.lua +++ b/Master/texmf-dist/tex/luatex/luatexbase/modutils.lua @@ -8,10 +8,13 @@ -- -- See the aforementioned source file(s) for copyright and licensing information. -- -module("luatexbase", package.seeall) +luatexbase = luatexbase or { } +local luatexbase = luatexbase +local string_gsub = string.gsub local modules = modules or {} local function date_to_int(date) - local numbers = string.gsub(date, "(%d+)/(%d+)/(%d+)", "%1%2%3") + if date == '' then return -1 end + local numbers = string_gsub(date, "(%d+)/(%d+)/(%d+)", "%1%2%3") return tonumber(numbers) end local function msg_format(msg_type, mod_name, ...) @@ -22,43 +25,48 @@ end local function module_error_int(mod, ...) error(msg_format('error', mod, ...), 3) end -function module_error(mod, ...) +local function module_error(mod, ...) module_error_int(mod, ...) end -function module_warning(mod, ...) +luatexbase.module_error = module_error +local function module_warning(mod, ...) for _, line in ipairs(msg_format('warning', mod, ...):explode('\n')) do texio.write_nl(line) end end -function module_info(mod, ...) +luatexbase.module_warning = module_warning +local function module_info(mod, ...) for _, line in ipairs(msg_format('info', mod, ...):explode('\n')) do texio.write_nl(line) end end -function module_log(mod, msg, ...) +luatexbase.module_info = module_info +local function module_log(mod, msg, ...) texio.write_nl('log', mod..': '..msg:format(...)) end -function errwarinf(name) +luatexbase.module_log = module_log +local function errwarinf(name) return function(...) module_error_int(name, ...) end, function(...) module_warning(name, ...) end, function(...) module_info(name, ...) end, function(...) module_log(name, ...) end end +luatexbase.errwarinf = errwarinf local err, warn = errwarinf('luatexbase.modutils') -function require_module(name, req_date) +local function require_module(name, req_date) require(name) local info = modules[name] if not info then warn("module '%s' was not properly identified", name) - elseif req_date and info.version then - if not (info.date and date_to_int(info.date) > date_to_int(req_date)) - then + elseif req_date and info.date then + if date_to_int(info.date) < date_to_int(req_date) then warn("module '%s' required in version '%s'\n" .. "but found in version '%s'", name, req_date, info.date) end end end -function provides_module(info) +luatexbase.require_module = require_module +local function provides_module(info) if not (info and info.name) then err('provides_module: missing information') end @@ -67,5 +75,70 @@ function provides_module(info) modules[info.name] = info return errwarinf(info.name) end +luatexbase.provides_module = provides_module +local fastcopy +fastcopy = table.fastcopy or function(old) + if old then + local new = { } + for k,v in next, old do + if type(v) == "table" then + new[k] = fastcopy(v) + else + new[k] = v + end + end + local mt = getmetatable(old) + if mt then + setmetatable(new,mt) + end + return new + else + return { } + end +end +local function get_module_info(name) + local module_table = modules[name] + if not module_table then + return nil + else + return fastcopy(module_table) + end +end +luatexbase.get_module_info = get_module_info +function get_module_version(name) + local module_table = modules[name] + if not module_table then + return nil + else + return module_table.version + end +end +luatexbase.get_module_version = get_module_version +function get_module_date(name) + local module_table = modules[name] + if not module_table then + return nil + else + return module_table.date + end +end +luatexbase.get_module_date = get_module_date +function get_module_date_int(name) + local module_table = modules[name] + if not module_table then + return nil + else + return module_table.date and date_to_int(module_table.date) + end +end +luatexbase.get_module_date_int = get_module_date_int +function is_module_loaded(name) + if modules[name] then + return true + else + return false + end +end +luatexbase.is_module_loaded = is_module_loaded -- -- End of File `modutils.lua'. -- cgit v1.2.3