summaryrefslogtreecommitdiff
path: root/Master/texmf-dist
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-05-06 22:04:07 +0000
committerKarl Berry <karl@freefriends.org>2013-05-06 22:04:07 +0000
commitb05a48f1a220aa87d6ac208529d7975e092cec3a (patch)
tree6194223d0c9df70e26cc14c9e5b2bc48bed94efe /Master/texmf-dist
parent40da39964dbacc76ec9472dbd23fedbc5cb16d46 (diff)
luatexbase (6may13)
git-svn-id: svn://tug.org/texlive/trunk@30250 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r--Master/texmf-dist/doc/luatex/luatexbase/NEWS (renamed from Master/texmf-dist/doc/luatex/luatexbase/Changes)16
-rw-r--r--Master/texmf-dist/doc/luatex/luatexbase/README20
-rw-r--r--Master/texmf-dist/doc/luatex/luatexbase/TODO4
-rw-r--r--Master/texmf-dist/doc/luatex/luatexbase/luatexbase-attr.pdfbin442757 -> 469216 bytes
-rw-r--r--Master/texmf-dist/doc/luatex/luatexbase/luatexbase-cctb.pdfbin498825 -> 499123 bytes
-rw-r--r--Master/texmf-dist/doc/luatex/luatexbase/luatexbase-compat.pdfbin497667 -> 497806 bytes
-rw-r--r--Master/texmf-dist/doc/luatex/luatexbase/luatexbase-loader.pdfbin443842 -> 444644 bytes
-rw-r--r--Master/texmf-dist/doc/luatex/luatexbase/luatexbase-mcb.pdfbin513883 -> 514214 bytes
-rw-r--r--Master/texmf-dist/doc/luatex/luatexbase/luatexbase-modutils.pdfbin501606 -> 494407 bytes
-rw-r--r--Master/texmf-dist/doc/luatex/luatexbase/luatexbase-regs.pdfbin487025 -> 487141 bytes
-rw-r--r--Master/texmf-dist/doc/luatex/luatexbase/luatexbase.pdfbin408215 -> 412841 bytes
-rw-r--r--Master/texmf-dist/doc/luatex/luatexbase/test-modutils.lua15
-rw-r--r--Master/texmf-dist/source/luatex/luatexbase/Makefile4
-rw-r--r--Master/texmf-dist/source/luatex/luatexbase/luatexbase-attr.dtx288
-rw-r--r--Master/texmf-dist/source/luatex/luatexbase/luatexbase-cctb.dtx12
-rw-r--r--Master/texmf-dist/source/luatex/luatexbase/luatexbase-loader.dtx18
-rw-r--r--Master/texmf-dist/source/luatex/luatexbase/luatexbase-mcb.dtx40
-rw-r--r--Master/texmf-dist/source/luatex/luatexbase/luatexbase-modutils.dtx204
-rw-r--r--Master/texmf-dist/source/luatex/luatexbase/luatexbase.dtx6
-rw-r--r--Master/texmf-dist/tex/luatex/luatexbase/attr.lua190
-rw-r--r--Master/texmf-dist/tex/luatex/luatexbase/cctb.lua12
-rw-r--r--Master/texmf-dist/tex/luatex/luatexbase/luatexbase-attr.sty6
-rw-r--r--Master/texmf-dist/tex/luatex/luatexbase/luatexbase.loader.lua11
-rw-r--r--Master/texmf-dist/tex/luatex/luatexbase/luatexbase.sty2
-rw-r--r--Master/texmf-dist/tex/luatex/luatexbase/mcb.lua27
-rw-r--r--Master/texmf-dist/tex/luatex/luatexbase/modutils.lua97
26 files changed, 850 insertions, 122 deletions
diff --git a/Master/texmf-dist/doc/luatex/luatexbase/Changes b/Master/texmf-dist/doc/luatex/luatexbase/NEWS
index 76894008bcf..cb40459f532 100644
--- a/Master/texmf-dist/doc/luatex/luatexbase/Changes
+++ b/Master/texmf-dist/doc/luatex/luatexbase/NEWS
@@ -1,5 +1,21 @@
Changes in the luatexbase package/bundle
+2013/05/04 v0.6
+ all
+ - move away from the module() function (deprecated in Lua 5.2)
+ attr
+ - hack to make luatexbase and luatex.sty compatible for attribute
+ allocation (same thing should be done for catcodetables)
+ - adding whatsit nodes allocation functions (see doc)
+ modutils
+ - adding functions to check the availability and version of a module
+ - fixing small error in module date requirement
+ - update documentation to reflect the move from module()
+ loader
+ - do not output included file paths when called by texlua
+ mcb
+ - passing most of the term output to the log
+
2013/04/13 v0.5
all
- input luatex.sty before doing anything, as luatex.sty
diff --git a/Master/texmf-dist/doc/luatex/luatexbase/README b/Master/texmf-dist/doc/luatex/luatexbase/README
index 44249108018..cb3c8bacdca 100644
--- a/Master/texmf-dist/doc/luatex/luatexbase/README
+++ b/Master/texmf-dist/doc/luatex/luatexbase/README
@@ -8,10 +8,13 @@ if desired:
– luatexbase-compat: compatibility helpers;
– luatexbase-loader: Lua module loading;
– luatexbase-regs: allocation of registers and the like;
-– luatexbase-attr: attribute allocation;
+– luatexbase-attr: attribute and whatsit node allocation;
– luatexbase-cctb: catcode table allocation;
– luatexbase-modutils: Lua module declaration; and
-- luatexbase-mcb: callbacks extensions.
+– luatexbase-mcb: callbacks extensions.
+
+The development takes place on https://github.com/lualatex/luatexbase.
+
Installation
------------
@@ -19,21 +22,16 @@ Installation
Here are the recommended installation methods (preferred first).
1. If you are using TeX Live 2010 or later, use 'tlmgr install luatexbase'.
-If your are using MiKTeX, use the MiKTeX Package Manager.
-Alternatively, try you Linux distribution's package management system.
+ If your are using MiKTeX, use the MiKTeX Package Manager.
+ Alternatively, try you Linux distribution's package management system.
-2. a. Grab luatexbase.tds.zip on the CTAN.
- b. Unzip it at the root of one or your TDS trees.
- c. You may need to update some filename database after this, see your TeX
- distribution's manual for details. (Hint: with TeX Live, run 'mktexlsr';
- with MikTeX, look for "Refresh FNDB" in the MikTeX menu.)
-
-3. a. Grab the sources from CTAN or github.
+2. a. Grab the sources from CTAN or github.
b. Run 'make install TEXMFROOT=/path/to/texmf'.
(Warning: 'make install' without giving a TEXMFROOT will
put files in './texmf', which is probably not what you want.)
c. See 2c.
+
License
-------
diff --git a/Master/texmf-dist/doc/luatex/luatexbase/TODO b/Master/texmf-dist/doc/luatex/luatexbase/TODO
index 6205464bb50..1f368269f32 100644
--- a/Master/texmf-dist/doc/luatex/luatexbase/TODO
+++ b/Master/texmf-dist/doc/luatex/luatexbase/TODO
@@ -13,7 +13,6 @@ all
or generalise use of qstest
- add debug messages to be used in the test suite?
- mark all occurences of version-dependent stuff in the code
-- quit using module() in favor of locals
- support the syntax foo = require"foo" in modutils? How?
compat
@@ -30,6 +29,7 @@ cctb
----
- support for unicode-letters?
+- make the functions compatible with luatex.sty
mcb
---
@@ -39,7 +39,7 @@ mcb
- provide a list()?
- allow temporary disabling of callbacks
- do something with open_read_file etc
-- make callback.register = luatexbase_add_to_callback
+- make callback.register = luatexbase_add_to_callback?
- check if there are functions in the callbacks before luatexbase is loaded
and import them
diff --git a/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-attr.pdf b/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-attr.pdf
index feea83dc841..6ec82dc3cb5 100644
--- a/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-attr.pdf
+++ b/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-attr.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-cctb.pdf b/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-cctb.pdf
index bf930733a05..6d56eb55d08 100644
--- a/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-cctb.pdf
+++ b/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-cctb.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-compat.pdf b/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-compat.pdf
index 93806faf68a..ed69d0ad92a 100644
--- a/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-compat.pdf
+++ b/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-compat.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-loader.pdf b/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-loader.pdf
index 6f2756530e2..eacad901c38 100644
--- a/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-loader.pdf
+++ b/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-loader.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-mcb.pdf b/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-mcb.pdf
index 41825701624..4bcb3370b12 100644
--- a/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-mcb.pdf
+++ b/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-mcb.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-modutils.pdf b/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-modutils.pdf
index 48dcf7a2794..af659f13f0d 100644
--- a/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-modutils.pdf
+++ b/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-modutils.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-regs.pdf b/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-regs.pdf
index dfd7aeec340..95ed519e71d 100644
--- a/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-regs.pdf
+++ b/Master/texmf-dist/doc/luatex/luatexbase/luatexbase-regs.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/luatex/luatexbase/luatexbase.pdf b/Master/texmf-dist/doc/luatex/luatexbase/luatexbase.pdf
index ce8391ac0b4..3075ae75c55 100644
--- a/Master/texmf-dist/doc/luatex/luatexbase/luatexbase.pdf
+++ b/Master/texmf-dist/doc/luatex/luatexbase/luatexbase.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/luatex/luatexbase/test-modutils.lua b/Master/texmf-dist/doc/luatex/luatexbase/test-modutils.lua
index f12d755ad14..45a644dfab4 100644
--- a/Master/texmf-dist/doc/luatex/luatexbase/test-modutils.lua
+++ b/Master/texmf-dist/doc/luatex/luatexbase/test-modutils.lua
@@ -14,7 +14,22 @@ local err, warn, info, log = luatexbase.provides_module {
version = 1,
description = 'dummy test package',
}
+luatexbase.provides_module {
+ name = 'test-modutils2',
+ date = '',
+ version = 1,
+ description = 'dummy test package',
+}
info('It works!\nOh, rly?\nYeah rly!')
log("I'm a one-line info.")
+info("1 = "..luatexbase.get_module_version('test-modutils'))
+if is_module_loaded('test-modutils') then
+ info("ok!")
+else
+ err("problem!")
+end
+info("2000/01/01 = "..luatexbase.get_module_info('test-modutils').date)
+info("20000101 = "..luatexbase.get_module_date_int('test-modutils'))
+info("-1 = "..luatexbase.get_module_date_int('test-modutils2'))
--
-- End of File `test-modutils.lua'.
diff --git a/Master/texmf-dist/source/luatex/luatexbase/Makefile b/Master/texmf-dist/source/luatex/luatexbase/Makefile
index 6fdc7fb4693..c3b8e894aa1 100644
--- a/Master/texmf-dist/source/luatex/luatexbase/Makefile
+++ b/Master/texmf-dist/source/luatex/luatexbase/Makefile
@@ -33,7 +33,7 @@ UNPACKEDTL = $(UNPACKED_MCB) $(UNPACKED_REGS) $(UNPACKED_ATTR) $(UNPACKED_CCTB)
$(UNPACKED_BASE)
COMPILED = $(DOC)
GENERATED = $(COMPILED) $(UNPACKED)
-SOURCE = $(DTX) $(DTXSTY) README TODO Changes Makefile
+SOURCE = $(DTX) $(DTXSTY) README TODO NEWS Makefile
# used for check
TEST_LOADER = test-loader
@@ -42,7 +42,7 @@ TEST_MCB = test-mcb-aux.tex
# Files grouped by installation location
RUNFILES = $(filter-out test-%, $(UNPACKEDTL))
-DOCFILES = $(DOC) $(filter test-%, $(UNPACKEDTL)) README TODO Changes
+DOCFILES = $(DOC) $(filter test-%, $(UNPACKEDTL)) README TODO NEWS
SRCFILES = $(DTX) Makefile
# The following definitions should be equivalent
diff --git a/Master/texmf-dist/source/luatex/luatexbase/luatexbase-attr.dtx b/Master/texmf-dist/source/luatex/luatexbase/luatexbase-attr.dtx
index 923ad973e64..aa5e987473d 100644
--- a/Master/texmf-dist/source/luatex/luatexbase/luatexbase-attr.dtx
+++ b/Master/texmf-dist/source/luatex/luatexbase/luatexbase-attr.dtx
@@ -116,7 +116,7 @@ See the aforementioned source file(s) for copyright and licensing information.
% \begin{abstract}
% In addition to the registers existing in \tex and \etex, \luatex introduces
% a new concept: attributes. This package takes care of attribute allocation
-% just like Plain TeX and LaTeX do for other registers, and also provides a
+% just like Plain \tex and \latex do for other registers, and also provides a
% Lua interface.
% \end{abstract}
%
@@ -145,7 +145,7 @@ See the aforementioned source file(s) for copyright and licensing information.
% number of the attribute associated to |\fooattr| assuming it was defined
% using |\newluatexattribute\fooattr|, something that \luatex currently
% doesn't support (you can get the current value of the associated attribute
-% as |tex.atrribute.fooattr|, but not the attribute number).
+% as |tex.attribute.fooattr|, but not the attribute number).
%
% There are several ways to work around this. For example, it is possible to
% extract the number at any time from the |\meaning| of |\fooattr|.
@@ -158,7 +158,7 @@ See the aforementioned source file(s) for copyright and licensing information.
%
% Also, two Lua functions are provided that are analogous to the above \tex
% macros (actually, the macros are wrappers around the functions):
-% |luatexbase.new_attributes|\parg{name} allocates a new attribute, without
+% |luatexbase.new_attribute|\parg{name} allocates a new attribute, without
% defining a corresponding \tex control sequence (only an entry in
% |luatexbase.attributes| is created. It usually returns the number of the
% allocated attribute. If room is missing, it raises an error, unless the
@@ -283,21 +283,23 @@ See the aforementioned source file(s) for copyright and licensing information.
% \subsubsection{Load supporting Lua module}
%
% First load \pk{luatexbase-loader} (hence \pk{luatexbase-compat}), then
-% the supporting Lua module.
+% the supporting Lua module. We make sure \verb|luatex.sty| is loaded.
%
% \begin{macrocode}
\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')}
% \end{macrocode}
%
% \subsection{User macros}
%
-% The allocaton macro is merely a wrapper around the Lua function, but
+% The allocation macro is merely a wrapper around the Lua function, but
% handles error and logging in \tex, for consistency with other allocation
% macros.
%
@@ -342,19 +344,81 @@ See the aforementioned source file(s) for copyright and licensing information.
%
% \begin{macrocode}
%<*luamodule>
-module('luatexbase', package.seeall)
+--- 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
+% \end{macrocode}
+%
+% We improvise a basic logging facility.
+%
+% \begin{macrocode}
+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
% \end{macrocode}
%
% This table holds the values of the allocated attributes, indexed by name.
%
% \begin{macrocode}
-attributes = {}
+luatexbase.attributes = luatexbase.attributes or { }
+local attributes = luatexbase.attributes
+% \end{macrocode}
+%
+% Scoping: we use locals for the attribute functions.
+%
+% \begin{macrocode}
+local new_attribute
+local unset_attribute
% \end{macrocode}
%
-% The allocaton function. Unlike other registers, allocate starting from 1.
-% Some code (eg, font handling coming from Con\tex{}t) behaves strangely
-% with \verb+\attribute0+ and since there is plenty of room here, it
-% doesn't seem bad to ``loose'' one item in order to avoid this problem.
+% In the \luatex ecosystem there are currently two functions that create a
+% new attribute.
+% One is in |oberdiek| bundle, the other is this one. We will hack a little
+% in order to make them compatible. The other function uses
+% |LuT@AllocAttribute| as attribute counter, we will keep it in sync with
+% ours. A possible problem might also appear: the other function starts
+% attribute allocation at 0, which will break luaotfload. We output an
+% error if a new attribute has already been allocated with number 0.
+%
+% \begin{macrocode}
+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
+% \end{macrocode}
+%
+% The allocation function. Unlike other registers, allocate starting from 1.
+% Some code (e.~g., font handling coming from Con\tex{}t) behaves strangely
+% with \verb+\attribute0+ set, and since there is plenty of room here, it
+% doesn't seem bad to ``lose'' one item in order to avoid this problem.
%
% \begin{macrocode}
local last_alloc = 0
@@ -366,15 +430,22 @@ 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
% \end{macrocode}
%
% Unset an attribute the correct way depending on \luatex's version.
@@ -384,6 +455,197 @@ 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
+% \end{macrocode}
+%
+% User whatsit allocation (experimental).
+%
+% \begin{macrocode}
+--- 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"
+% \end{macrocode}
+%
+% The whatsit allocation is split into two functions:
+% \verb|new_user_whatsit_id| registers a new id (an integer)
+% and returns it. It is up to the user what he actually does
+% with the return value.
+%
+% Registering whatsits without a name, though supported, is
+% not exactly good style. In these cases we generate a name
+% from a counter.
+%
+% In addition to the whatsit name, it is possible and even
+% encouraged to specify the name of the package that will be
+% using the whatsit as the second argument.
+%
+% \begin{macrocode}
+--- 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
+% \end{macrocode}
+%
+% \verb|new_user_whatsit| first registers a new id and then also
+% creates the corresponding whatsit of subtype “user defined”.
+% We return a nullary function that delivers copies of the whatsit.
+%
+% \begin{macrocode}
+--- 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
+% \end{macrocode}
+%
+% If one knows the name of a whatsit, its corresponding id
+% can be retrieved by means of \verb|get_user_whatsit_id|.
+%
+% \begin{macrocode}
+--- 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
+% \end{macrocode}
+%
+% The inverse lookup is also possible via \verb|get_user_whatsit_name|.
+% Here it finally becomes obvious why it is beneficial to supply a package
+% name -- it adds information about who created and might be relying on the
+% whatsit in question. First return value is the whatsit name, the second
+% the package identifier it was registered with.
+%
+% We issue a warning and return empty strings in case the asked whatsit is
+% unregistered.
+%
+% \begin{macrocode}
+--- 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
+% \end{macrocode}
+%
+% For the curious as well as the cautious who are interesting in
+% what they are dealing with, we add a function that outputs the
+% current allocation status to the terminal.
+%
+% \begin{macrocode}
+--- 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
+% \end{macrocode}
+% Lastly, we define a couple synonyms for convenience.
+% \begin{macrocode}
+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{macrocode}
%
% \begin{macrocode}
diff --git a/Master/texmf-dist/source/luatex/luatexbase/luatexbase-cctb.dtx b/Master/texmf-dist/source/luatex/luatexbase/luatexbase-cctb.dtx
index f869c5bfa3d..1e95379223c 100644
--- a/Master/texmf-dist/source/luatex/luatexbase/luatexbase-cctb.dtx
+++ b/Master/texmf-dist/source/luatex/luatexbase/luatexbase-cctb.dtx
@@ -649,17 +649,20 @@ See the aforementioned source file(s) for copyright and licensing information.
%
% \begin{macrocode}
%<*luamodule>
-module('luatexbase', package.seeall)
+luatexbase = luatexbase or { }
+local luatexbase = luatexbase
% \end{macrocode}
%
% The number associated to a CS name is remembered in the |catcodetables|
% table.
%
% \begin{macrocode}
-catcodetables = {}
-function catcodetabledef_from_tex(name, number)
+luatexbase.catcodetables = luatexbase.catcodetables or { }
+local catcodetables = luatexbase.catcodetables
+local function catcodetabledef_from_tex(name, number)
catcodetables[name] = tonumber(number)
end
+luatexbase.catcodetabledef_from_tex = catcodetabledef_from_tex
% \end{macrocode}
%
% The next function creates some shortcuts for better readability in lua
@@ -667,7 +670,7 @@ end
% |luatexbase.catcodetables.CatcodeTableLaTeX|.
%
% \begin{macrocode}
-function catcodetable_do_shortcuts()
+local function catcodetable_do_shortcuts()
local cat = catcodetables
cat['latex'] = cat.CatcodeTableLaTeX
cat['latex-package'] = cat.CatcodeTableLaTeXAtLetter
@@ -678,6 +681,7 @@ function catcodetable_do_shortcuts()
cat['string'] = cat.CatcodeTableString
cat['other'] = cat.CatcodeTableOther
end
+luatexbase.catcodetable_do_shortcuts = catcodetable_do_shortcuts
% \end{macrocode}
%
% \begin{macrocode}
diff --git a/Master/texmf-dist/source/luatex/luatexbase/luatexbase-loader.dtx b/Master/texmf-dist/source/luatex/luatexbase/luatexbase-loader.dtx
index 77b9b9b7773..11918a3e884 100644
--- a/Master/texmf-dist/source/luatex/luatexbase/luatexbase-loader.dtx
+++ b/Master/texmf-dist/source/luatex/luatexbase/luatexbase-loader.dtx
@@ -274,7 +274,8 @@ See the aforementioned source file(s) for copyright and licensing information.
%
% \begin{macrocode}
%<*luamodule>
-module('luatexbase', package.seeall)
+luatexbase = luatexbase or { }
+local luatexbase = luatexbase
% \end{macrocode}
%
% Just in case it's called from a \TeX Lua script...
@@ -283,6 +284,17 @@ module('luatexbase', package.seeall)
kpse.set_program_name("luatex")
% \end{macrocode}
%
+% In \LaTeX, it's traditional to print the included file paths. We don't want
+% to do this for scripts using texlua... Currently there is no perfect check
+% of texlua vs. luatex, so we check for the token table.
+%
+% \begin{macrocode}
+local print_included_path = false
+if token then
+ print_included_path = true
+end
+% \end{macrocode}
+%
% Emulate (approximatively) kpse's lua format search. More precisely,
% combine the search path of |texmfscripts| and |tex| in order to
% approximate |LUAINPUTS|. But we need to handle suffixes ourselves.
@@ -357,7 +369,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
% \end{macrocode}
diff --git a/Master/texmf-dist/source/luatex/luatexbase/luatexbase-mcb.dtx b/Master/texmf-dist/source/luatex/luatexbase/luatexbase-mcb.dtx
index 8b99a5257c7..0c04d4d346c 100644
--- a/Master/texmf-dist/source/luatex/luatexbase/luatexbase-mcb.dtx
+++ b/Master/texmf-dist/source/luatex/luatexbase/luatexbase-mcb.dtx
@@ -142,7 +142,7 @@ See the aforementioned source file(s) for copyright and licensing information.
%
% \luatex provides an extremely interesting feature, named callbacks. It
% allows to call some Lua functions at some points of the \TeX\ algorithm (a
-% \emph{callback}), like when \TeX\ breaks likes, puts vertical spaces, etc.
+% \emph{callback}), like when \TeX\ breaks lines, puts vertical spaces, etc.
% The \luatex core offers a function called \texttt{callback.register} that
% enables to register a function in a callback.
%
@@ -157,7 +157,7 @@ See the aforementioned source file(s) for copyright and licensing information.
% \begin{description}
% \item[simple] is for functions that don't return anything: they are called
% in order, all with the same argument;
-% \item[data] is for functions receiving a piece of data of nay type
+% \item[data] is for functions receiving a piece of data of any type
% except node list head (and possibly other arguments) and returning it
% (possibly modified): the functions are called in order, and each is
% passed the return value of the previous (and the other arguments
@@ -167,8 +167,8 @@ See the aforementioned source file(s) for copyright and licensing information.
% modified node list, or the boolean values |true| or |false|. The
% functions are chained the same way as for \emph{data} except that for
% the following. If
-% one function returns |false|, then |false| is immediately return and the
-% following functions are \emph{not} called. If one function returns
+% one function returns |false|, then |false| is immediately returned and
+% the following functions are \emph{not} called. If one function returns
% |true|, then the same head is passed to the next function. If all
% functions return |true|, then |true| is returned, otherwise the return
% value of the last function not returning |true| is used.
@@ -392,8 +392,9 @@ See the aforementioned source file(s) for copyright and licensing information.
% \subsubsection{Module identification}
%
% \begin{macrocode}
-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",
@@ -404,6 +405,17 @@ local err, warning, info = luatexbase.provides_module({
})
% \end{macrocode}
%
+% First we declare the function references for the entire scope.
+%
+% \begin{macrocode}
+local add_to_callback
+local call_callback
+local create_callback
+local priority_in_callback
+local remove_from_callback
+local reset_callback
+% \end{macrocode}
+%
% \subsubsection{Housekeeping}
%
% The main table: keys are callback names, and values are the associated
@@ -687,9 +699,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
% \end{macrocode}
%
% Remove a function from a callback. First check arguments.
@@ -733,7 +746,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
@@ -742,6 +755,7 @@ function remove_from_callback (name, description)
end
return
end
+luatexbase.remove_from_callback = remove_from_callback
% \end{macrocode}
%
% Remove all the functions registered in a callback. Unregisters the
@@ -756,17 +770,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
% \end{macrocode}
%
% Get a function's priority in a callback list, or false if the function is
@@ -788,6 +803,7 @@ function priority_in_callback (name, description)
end
return false
end
+luatexbase.priority_in_callback = priority_in_callback
% \end{macrocode}
%
% \subsubsection{Public functions for user-defined callbacks}
@@ -823,10 +839,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
% \end{macrocode}
%
% This function calls a callback. It can only call a callback created by
@@ -855,6 +872,7 @@ function call_callback(name, ...)
end
return f(...)
end
+luatexbase.call_callback = call_callback
% \end{macrocode}
%
% That's all folks!
diff --git a/Master/texmf-dist/source/luatex/luatexbase/luatexbase-modutils.dtx b/Master/texmf-dist/source/luatex/luatexbase/luatexbase-modutils.dtx
index 6f500da0acd..cd1458a6aa6 100644
--- a/Master/texmf-dist/source/luatex/luatexbase/luatexbase-modutils.dtx
+++ b/Master/texmf-dist/source/luatex/luatexbase/luatexbase-modutils.dtx
@@ -111,7 +111,7 @@ See the aforementioned source file(s) for copyright and licensing information.
% Grave accent \` Left brace \{ Vertical bar \|
% Right brace \} Tilde \~}
%
-% \pkdate{luatexbase-modutils}{v0.5 2013-04-13}
+% \pkdate{luatexbase-modutils}{v0.6 2013-05-04}
%
% \maketitle
%
@@ -144,17 +144,10 @@ See the aforementioned source file(s) for copyright and licensing information.
%
% \medskip
%
-% It is important to notice that Lua's standard function |module()| is
-% completely orthogonal with the present package. It has nothing to do with
-% identification and deals only with namespaces: more precisely, it
-% modifies the current environment. So, you should continue to
-% use it normally regardless of whether you chose to use this package's
-% features for identification.
-%
-% It is recommended to always use |module()| or any other method that ensure
-% the global name space remains clean. For example, you may heavily use the
-% |local| keyword and explicitly qualify the name of every non-local symbol.
-% Chapter 15 of \href{http://www.lua.org/pil/}{Programming in Lua, 1st ed.}
+% It is important to note that Lua's unction |module()| is deprecated in
+% Lua 5.2 and should be avoided. For examples of good practices for creating
+% modules, see section~\ref{template}. Chapter 15
+% of \href{http://www.lua.org/pil/15.html}{Programming in Lua, 3rd ed.}
% discusses various methods for managing packages.
%
% \subsection{\tex macros}
@@ -229,30 +222,35 @@ See the aforementioned source file(s) for copyright and licensing information.
% standard Lua function, so you may want to avoid overwriting it, hence the
% use of |err| in the above example.)
%
-% \subsection{Templates}
+% \begin{qcode}
+% local module_info = luatexbase.get_module_info(\meta{name})
+% local version = luatexbase.get_module_version(\meta{name})
+% local date = luatexbase.get_module_date(\meta{name})
+% local date_int = luatexbase.get_module_date_int(\meta{name})
+% local is_loaded = luatexbase.is_module_loaded(\meta{name})
+% \end{qcode}
+% These functions check for the availability or version of a module, and can
+% even return a copy of the |module_info| table.
%
-% Let me emphasize again that, while |luatexbase.require_module()| is meant to
-% be used as a replacement for |require()|, the function
-% |luatexbase.provides_module()| \emph{is not} a replacement for |module()|:
-% they just don't do the same thing (declaring information vs changing the
-% current name space).
+% \subsection{Templates}\label{template}
%
-% Now, here is how you module may begin:
+% Now, here is a module header template showing all the recommended elements:
% \begin{verbatim}
% local err, warn, info, log = luatexbase.provides_module({
% -- required
-% name = 'mymodule',
+% name = 'mymodule',
% -- recommended
-% date = '1970/01/01',
-% version = 0.0, -- or version = '0.0a',
-% description = 'a Lua module template',
+% date = '1970/01/01',
+% version = 0.0, -- or version = '0.0a',
+% description = 'a Lua module template',
% -- optional and ignored
-% author = 'A. U. Thor',
-% licence = 'LPPL v1.3+',
+% author = 'A. U. Thor',
+% licence = 'LPPL v1.3+',
% })
%
-% module('mynamespace', package.seeall)
-% -- or any other method (see chapter 15 of PIL for examples)
+% mynamespace = mynamespace or { }
+% local mynamespace = mynamespace
+%
% \end{verbatim}
%
% Alternatively, if you don't want to assume \pk{luatexbase-modutils} is
@@ -276,8 +274,8 @@ See the aforementioned source file(s) for copyright and licensing information.
% })
% end
%
-% module('mynamespace', package.seeall)
-% -- or any other method (see chapter 15 of PIL for examples)
+% mynamespace = mynamespace or { }
+% local mynamespace = mynamespace
%
% local function err(msg)
% -- etc.
@@ -457,7 +455,9 @@ See the aforementioned source file(s) for copyright and licensing information.
%
% \begin{macrocode}
%<*luamodule>
-module("luatexbase", package.seeall)
+luatexbase = luatexbase or { }
+local luatexbase = luatexbase
+local string_gsub = string.gsub
% \end{macrocode}
%
% \subsection{Internal functions and data}
@@ -474,7 +474,8 @@ local modules = modules or {}
%
% \begin{macrocode}
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
% \end{macrocode}
@@ -495,44 +496,49 @@ 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
+luatexbase.module_error = module_error
% \end{macrocode}
%
% Split the lines explicitly in order not to depend on the value of
% |\newlinechar|.
%
% \begin{macrocode}
-function module_warning(mod, ...)
+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
+luatexbase.module_info = module_info
% \end{macrocode}
%
% No line splitting or advanced formating here.
%
% \begin{macrocode}
-function module_log(mod, msg, ...)
+local function module_log(mod, msg, ...)
texio.write_nl('log', mod..': '..msg:format(...))
end
+luatexbase.module_log = module_log
% \end{macrocode}
%
% Produce custom versions of the reporting functions.
%
% \begin{macrocode}
-function errwarinf(name)
+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
% \end{macrocode}
%
% For our own convenience, local functions for warning and errors in the
@@ -547,19 +553,19 @@ local err, warn = errwarinf('luatexbase.modutils')
% Load a module with mandatory name checking and optional version checking.
%
% \begin{macrocode}
-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
+luatexbase.require_module = require_module
% \end{macrocode}
%
% Provide identification information for a module. As a bonus, custom
@@ -567,7 +573,7 @@ end
% everything done in |require_module()|.
%
% \begin{macrocode}
-function provides_module(info)
+local function provides_module(info)
if not (info and info.name) then
err('provides_module: missing information')
end
@@ -576,6 +582,107 @@ function provides_module(info)
modules[info.name] = info
return errwarinf(info.name)
end
+luatexbase.provides_module = provides_module
+% \end{macrocode}
+%
+% \subsubsection{module availability and version checking}
+%
+% A simple table copy function.
+%
+% \begin{macrocode}
+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
+% \end{macrocode}
+%
+% Gives the table of the infos on a module, as given in |provides_module|.
+%
+% \begin{macrocode}
+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
+% \end{macrocode}
+%
+% Gives the version of a module, nil if the module is not loaded and empty
+% string if the module did not set its date.
+%
+% \begin{macrocode}
+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
+% \end{macrocode}
+%
+% Gives the date string of a module, nil if the module is not loaded and
+% empty string of the modules did not set its date.
+%
+% \begin{macrocode}
+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
+% \end{macrocode}
+%
+% Gives the date number of a module, for date comparison, nil if the
+% module is not loaded and -1 if the module did not set its date. The number
+% is formated as |yyyymmdd|.
+%
+% \begin{macrocode}
+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
+% \end{macrocode}
+%
+% Returns true if the module is loaded, false otherwise.
+%
+% \begin{macrocode}
+function is_module_loaded(name)
+ if modules[name] then
+ return true
+ else
+ return false
+ end
+end
+luatexbase.is_module_loaded = is_module_loaded
% \end{macrocode}
%
% \begin{macrocode}
@@ -594,8 +701,23 @@ local err, warn, info, log = luatexbase.provides_module {
version = 1,
description = 'dummy test package',
}
+luatexbase.provides_module {
+ name = 'test-modutils2',
+ date = '',
+ version = 1,
+ description = 'dummy test package',
+}
info('It works!\nOh, rly?\nYeah rly!')
log("I'm a one-line info.")
+info("1 = "..luatexbase.get_module_version('test-modutils'))
+if is_module_loaded('test-modutils') then
+ info("ok!")
+else
+ err("problem!")
+end
+info("2000/01/01 = "..luatexbase.get_module_info('test-modutils').date)
+info("20000101 = "..luatexbase.get_module_date_int('test-modutils'))
+info("-1 = "..luatexbase.get_module_date_int('test-modutils2'))
%</testdummy>
% \end{macrocode}
%
diff --git a/Master/texmf-dist/source/luatex/luatexbase/luatexbase.dtx b/Master/texmf-dist/source/luatex/luatexbase/luatexbase.dtx
index 49b0c07749c..2849818adbe 100644
--- a/Master/texmf-dist/source/luatex/luatexbase/luatexbase.dtx
+++ b/Master/texmf-dist/source/luatex/luatexbase/luatexbase.dtx
@@ -93,7 +93,7 @@ See the aforementioned source file(s) for copyright and licensing information.
% Grave accent \` Left brace \{ Vertical bar \|
% Right brace \} Tilde \~}
%
-% \pkdate{luatexbase}{v0.5 2013-04-13}
+% \pkdate{luatexbase}{v0.6 2013-05-04}
%
% \maketitle
%
@@ -116,7 +116,7 @@ See the aforementioned source file(s) for copyright and licensing information.
% \subpk{regs} extented allocation scheme for registers and the like,
% \emph{\`a la} \pk{etex}.
% \subpk{cctb} catcode table allocation.
-% \subpk{attr} attribute allocation.
+% \subpk{attr} attribute and whatsit node allocation.
% \subpk{mcb} callbacks extensions allowing to register many functions in a
% single callback, and declare new callbacks for packages.
% \subpk{modutils} Lua module declaration, including version checks.
@@ -214,7 +214,7 @@ See the aforementioned source file(s) for copyright and licensing information.
\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]
% \end{macrocode}
%
% Make sure \luatex is used.
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'.