From 89fe3ee651a41181c9912a37822318ce2024f6f5 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 29 Nov 2013 14:14:57 +0100 Subject: [mcb] implement is_active_callback() Part of https://github.com/lualatex/luatexbase/issues/17 --- luatexbase-mcb.dtx | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/luatexbase-mcb.dtx b/luatexbase-mcb.dtx index d9fb995..0c1f687 100644 --- a/luatexbase-mcb.dtx +++ b/luatexbase-mcb.dtx @@ -862,7 +862,7 @@ luatexbase.create_callback = create_callback % \end{macrocode} % % This function calls a callback. It can only call a callback created by -% the \texttt{create} function. +% the |create_callback| function. % % \begin{macrocode} function call_callback(name, ...) @@ -890,6 +890,41 @@ end luatexbase.call_callback = call_callback % \end{macrocode} % +% |is_active_callback| checks the activation state of a given +% callback function. It is passed the description of the function +% and the name of the callback it was registered under. +% +% The function raises an error if passed an invalid callback name +% or if the name or the description is missing. +% The return value is |true| iff the callback function is +% registered, |false| otherwise. +% +% \begin{macrocode} +--- string -> string -> bool +luatexbase.is_active_callback = function (name, description) + if not name then + err ("unable to check for callback:\nno proper name passed") + return false + elseif not callbacktypes [name] then + err ("unable to check for callback %q:\nis not a valid callback", name) + return false + elseif not description then + err ("unable to check for callback %q:\nno description given", name) + return false + end + local lst = callbacklist [name] + if not lst then --- callback inactive, no functions registered + return false + end + for _, v in next, lst do + if v.description == description then --- success + return true + end + end + return false +end +% \end{macrocode} +% % That's all folks! % % \begin{macrocode} -- cgit v1.2.3 From 1c3cc9603566ac83f6c79eddd39ca61a2d70a7ad Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 29 Nov 2013 14:40:22 +0100 Subject: [attr] fix error message --- luatexbase-attr.dtx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/luatexbase-attr.dtx b/luatexbase-attr.dtx index 5b7288f..4d2cf2a 100644 --- a/luatexbase-attr.dtx +++ b/luatexbase-attr.dtx @@ -391,9 +391,9 @@ 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") + error("luatexbase error: Attribute 0 has already been set by the \\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 -- cgit v1.2.3 From d6cc5e4f2097aae25c013efa73c64033566529f6 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 29 Nov 2013 14:47:48 +0100 Subject: [mcb] add tests for is_active_callback() --- luatexbase-mcb.dtx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/luatexbase-mcb.dtx b/luatexbase-mcb.dtx index 0c1f687..557f41d 100644 --- a/luatexbase-mcb.dtx +++ b/luatexbase-mcb.dtx @@ -948,13 +948,16 @@ local function sample(head,...) return head, true end local prio = luatexbase.priority_in_callback +local is_active = luatexbase.is_active_callback msg("\n*********\n* Testing management functions\n*********") luatexbase.add_to_callback("hpack_filter", sample, "sample one", 1) luatexbase.add_to_callback("hpack_filter", sample, "sample two", 2) luatexbase.add_to_callback("hpack_filter", sample, "sample three", 1) assert(prio("hpack_filter", "sample three")) +assert(is_active("hpack_filter", "sample three") == true) luatexbase.remove_from_callback("hpack_filter", "sample three") assert(not prio("hpack_filter", "sample three")) +assert(is_active("hpack_filter", "sample three") == false) luatexbase.reset_callback("hpack_filter") assert(not prio("hpack_filter", "sample one")) % \end{macrocode} -- cgit v1.2.3 From 84473fa4bd42deecedd6e8e5befc8a0174f0f1b8 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 29 Nov 2013 15:07:49 +0100 Subject: [mcb] implement callback_descriptions() Addresses https://github.com/lualatex/luatexbase/issues/17 --- luatexbase-mcb.dtx | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/luatexbase-mcb.dtx b/luatexbase-mcb.dtx index 557f41d..532cfbb 100644 --- a/luatexbase-mcb.dtx +++ b/luatexbase-mcb.dtx @@ -925,6 +925,39 @@ luatexbase.is_active_callback = function (name, description) end % \end{macrocode} % +% |callback_descriptions| returns a table containing all +% descriptions of the functions registered for a given callback in +% the order of their priority. +% +% The function raises an error if the callback name is missing or +% invalid. +% If there is no function registered for the callback, an empty +% table is returned. +% +% \begin{macrocode} +--- string -> string list option +luatexbase.callback_descriptions = function (name) + if not name then + err ("unable to check for callback:\nno proper name passed") + return + elseif not callbacktypes [name] then + err ("unable to check for callback %q:\nis not a valid callback", name) + return + end + local lst = callbacklist [name] + local registered = { } + if lst then + for i = 1, #lst do + local itm = lst [i] + if i then + registered [i] = itm.description + end + end + end + return registered +end +% \end{macrocode} +% % That's all folks! % % \begin{macrocode} -- cgit v1.2.3 From d4e393604b20fb7dab4f1046c1eec277a72e3741 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 29 Nov 2013 15:09:17 +0100 Subject: [mcb] add test for callback_descriptions() --- luatexbase-mcb.dtx | 1 + 1 file changed, 1 insertion(+) diff --git a/luatexbase-mcb.dtx b/luatexbase-mcb.dtx index 532cfbb..df95170 100644 --- a/luatexbase-mcb.dtx +++ b/luatexbase-mcb.dtx @@ -988,6 +988,7 @@ luatexbase.add_to_callback("hpack_filter", sample, "sample two", 2) luatexbase.add_to_callback("hpack_filter", sample, "sample three", 1) assert(prio("hpack_filter", "sample three")) assert(is_active("hpack_filter", "sample three") == true) +assert(#luatexbase.callback_descriptions("hpack_filter") == 3) luatexbase.remove_from_callback("hpack_filter", "sample three") assert(not prio("hpack_filter", "sample three")) assert(is_active("hpack_filter", "sample three") == false) -- cgit v1.2.3 From c277244a226831be412432355829a8c0f4e65008 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 29 Nov 2013 15:11:32 +0100 Subject: update news --- NEWS | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index bd9f4d1..94d91ef 100644 --- a/NEWS +++ b/NEWS @@ -1,9 +1,11 @@ Changes in the luatexbase package/bundle -2013/06/08 v0.7 +2013/11/29 v0.7 mcb - minor changes and more coherent behaviour - refreshing the list of callbacks + - add two functions is_active_callback() and + callback_descriptions() 2013/05/11 v0.6 all -- cgit v1.2.3