summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElie Roux <elie.roux@telecom-bretagne.eu>2013-06-09 00:59:36 -0700
committerElie Roux <elie.roux@telecom-bretagne.eu>2013-06-09 00:59:36 -0700
commita9b1a5ef7f196e543bb579117132b214d5fd1bfc (patch)
treeff4548ec8872e13867f3d16075dbaac978bc1fbd
parentafd1f72fe35da0060ca940dcc3840d78567d61a5 (diff)
parent56d5b0f7c09bf0236e2b12fb613db5afed98462d (diff)
downloadluatexbase-a9b1a5ef7f196e543bb579117132b214d5fd1bfc.tar.gz
Merge pull request #8 from lualatex/master
sync with lualatex repo
-rw-r--r--NEWS2
-rw-r--r--luatexbase-attr.dtx63
2 files changed, 42 insertions, 23 deletions
diff --git a/NEWS b/NEWS
index 9ad27e2..311ed94 100644
--- a/NEWS
+++ b/NEWS
@@ -7,7 +7,7 @@
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)
+ - adding user-defined whatsit node allocation functions (see doc)
modutils
- adding functions to check the availability and version of a module
- fixing small error in module date requirement
diff --git a/luatexbase-attr.dtx b/luatexbase-attr.dtx
index d19240b..5b7288f 100644
--- a/luatexbase-attr.dtx
+++ b/luatexbase-attr.dtx
@@ -262,7 +262,7 @@ See the aforementioned source file(s) for copyright and licensing information.
%
% \subsubsection{Primitives needed}
%
-% First load \pk{luatexbase-modutils} (hence \pk{luatexbase-loader}
+% First load \pk{luatexbase-modutils} (hence \pk{luatexbase-loader}
% and \pk{luatexbase-compat}), and make sure \pk{luatex.sty} is loaded too.
%
% \begin{macrocode}
@@ -434,6 +434,8 @@ luatexbase.new_attribute = new_attribute
% \end{macrocode}
%
% Unset an attribute the correct way depending on \luatex's version.
+% The constant \verb+unset_value+ can be retrieved by calling
+% \verb+get_unset_value()+ to apply to nodes.
%
% \begin{macrocode}
local unset_value = (luatexbase.luatexversion < 37) and -1 or -2147483647
@@ -441,9 +443,14 @@ function unset_attribute(name)
tex.setattribute(attributes[name], unset_value)
end
luatexbase.unset_attribute = unset_attribute
+luatexbase.get_unset_value = function () return unset_value end
% \end{macrocode}
%
-% User whatsit allocation (experimental).
+% Allocation of user-defined whatsit nodes (experimental).
+% User-defined whatsit nodes (or user whatsits) are ignored by the
+% \luatex engine. They can thus be used to store information in
+% node lists without doing any harm. User whatsits can be
+% distinguished by an id that is stored in node field |user_id|.
%
% \begin{macrocode}
--- cf. luatexref-t.pdf, sect. 8.1.4.25
@@ -457,18 +464,18 @@ local anonymous_whatsits = 0
local anonymous_prefix = "anon"
% \end{macrocode}
%
-% The whatsit allocation is split into two functions:
+% User 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
+% Registering user 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
+% In addition to the user 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.
+% using the user whatsit as the second argument.
%
% \begin{macrocode}
--- string -> string -> int
@@ -512,23 +519,36 @@ 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”.
+% creates the corresponding whatsit node of subtype “user-defined”.
% We return a nullary function that delivers copies of the whatsit.
%
+% Alternatively, the first argument can be a whatsit node that
+% will then be used as prototype. Note that in this case a
+% \emph{copy} of the prototype will be stored in the closure,
+% eliminating side-effects.
+%
% \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
+--- (string | node_t) -> string -> ((unit -> node_t) * int)
+local new_user_whatsit = function (req, package)
+ local id, whatsit
+ if type(req) == "string" then
+ id = new_user_whatsit_id(req, package)
+ whatsit = newnode(whatsit_t, user_defined_t)
+ whatsit.user_id = id
+ elseif req.id == whatsit_t and req.subtype == user_defined_t then
+ id = req.user_id
+ whatsit = copynode(req)
+ if not whatsit_ids[id] then
+ warning("whatsit id %d unregistered; "
+ .. "inconsistencies may arise", id)
+ end
+ end
+ 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
+% If one knows the name of a user whatsit, its corresponding id
% can be retrieved by means of \verb|get_user_whatsit_id|.
%
% \begin{macrocode}
@@ -545,11 +565,11 @@ luatexbase.get_user_whatsit_id = get_user_whatsit_id
% 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.
+% user whatsit in question. First return value is the user 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.
+% We issue a warning and return empty strings in case the argument
+% doesn't correspond to a registered user whatsit id.
%
% \begin{macrocode}
--- int | fun | node -> (string, string)
@@ -611,7 +631,7 @@ local dump_registered_whatsits = function (asked_package)
--- mess up line breaking, so concatenation is unusable ...
local first = true
for i=1, #whatsit_list do
- if first then
+ if first then
first = false
else -- indent
texiowrite_nl" "
@@ -626,7 +646,6 @@ luatexbase.dump_registered_whatsits = dump_registered_whatsits
% \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