From 7458a83c249fca6333e9486395363503b09e5321 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 7 May 2013 18:05:45 +0200 Subject: make user whatsit generators accept an optional argument of type node --- luatexbase-attr.dtx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/luatexbase-attr.dtx b/luatexbase-attr.dtx index aa5e987..ed60cf7 100644 --- a/luatexbase-attr.dtx +++ b/luatexbase-attr.dtx @@ -537,10 +537,24 @@ local new_user_whatsit = function (name, package) local whatsit = newnode(whatsit_t, user_defined_t) whatsit.user_id = id --- unit -> node_t - return function ( ) return copynode(whatsit) end, id + local generator = function (proto) + local res + if proto then + local proto_id = proto.user_id + if proto_id ~= id then --- mismatch + warning("overriding user_id %d of whatsit prototype (now: %d)", + proto.user_id, id) + end + res = copynode(proto) + res.user_id = id + else + res = copynode(whatsit) + end + return res + end + return generator, 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 -- cgit v1.2.3 From ea883f6348d13018179627d5ffd63f22bf843a9f Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 7 May 2013 18:12:54 +0200 Subject: do some basic validation on a node before accepting it as whatsit --- luatexbase-attr.dtx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/luatexbase-attr.dtx b/luatexbase-attr.dtx index ed60cf7..99b853a 100644 --- a/luatexbase-attr.dtx +++ b/luatexbase-attr.dtx @@ -539,7 +539,10 @@ local new_user_whatsit = function (name, package) --- unit -> node_t local generator = function (proto) local res - if proto then + if proto + and proto.id == whatsit_t + and proto.subtype == user_defined_t + then local proto_id = proto.user_id if proto_id ~= id then --- mismatch warning("overriding user_id %d of whatsit prototype (now: %d)", -- cgit v1.2.3 From 3260c403de194f3001e1ffac32ab32c7bc79d481 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 16 May 2013 21:52:25 +0200 Subject: add function to retrieve attribute unset value --- luatexbase-attr.dtx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/luatexbase-attr.dtx b/luatexbase-attr.dtx index c6a7040..499677d 100644 --- a/luatexbase-attr.dtx +++ b/luatexbase-attr.dtx @@ -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,6 +443,7 @@ 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} % % Allocation of user-defined whatsit nodes (experimental). -- cgit v1.2.3