summaryrefslogtreecommitdiff
path: root/macros/luatex/generic/luakeys/luakeys.lua
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2022-11-22 03:01:53 +0000
committerNorbert Preining <norbert@preining.info>2022-11-22 03:01:53 +0000
commitd8e47184a9a1a04b1aa016bb4a56d066b8940805 (patch)
tree3fc8db43e5fe0e68f3d4e52dd686a4e1db558702 /macros/luatex/generic/luakeys/luakeys.lua
parentcf9efbbd09ec0218821a622f2ff7dc2ce0ad5645 (diff)
CTAN sync 202211220301
Diffstat (limited to 'macros/luatex/generic/luakeys/luakeys.lua')
-rw-r--r--macros/luatex/generic/luakeys/luakeys.lua62
1 files changed, 41 insertions, 21 deletions
diff --git a/macros/luatex/generic/luakeys/luakeys.lua b/macros/luatex/generic/luakeys/luakeys.lua
index 8b065289de..a220413390 100644
--- a/macros/luatex/generic/luakeys/luakeys.lua
+++ b/macros/luatex/generic/luakeys/luakeys.lua
@@ -692,6 +692,10 @@ local is = {
string = function(value)
return type(value) == 'string'
end,
+
+ any = function(value)
+ return true
+ end,
}
--- Apply the key-value-pair definitions (defs) on an input table in a
@@ -929,33 +933,49 @@ local function apply_definitions(defs,
pick = function(value, key, def)
if def.pick then
- if type(def.pick) == 'string' and is[def.pick] == nil then
- throw_error(
- 'Wrong setting. Allowed settings for the attribute “def.pick” are: true, boolean, dimension, integer, number, string. Got “' ..
- tostring(def.pick) .. '”.')
+ local pick_types
+
+ -- Allow old deprecated attribut pick = true
+ if def.pick == true then
+ pick_types = { 'any' }
+ elseif type(def.pick) == 'table' then
+ pick_types = def.pick
+ else
+ pick_types = { def.pick }
end
+ -- Check if the pick attribute is valid
+ for _, pick_type in ipairs(pick_types) do
+ if type(pick_type) == 'string' and is[pick_type] == nil then
+ throw_error(
+ 'Wrong data type in the “pick” attribute: ' ..
+ tostring(pick_type) ..
+ '. Allowed are: any, boolean, dimension, integer, number, string.')
+ end
+ end
+
+ -- The key has already a value. We leave the function at this
+ -- point to be able to check the pick attribute for errors
+ -- beforehand.
if value ~= nil then
return value
end
- for i, v in pairs(input) do
- -- We can not use ipairs here. `ipairs(t)` iterates up to the
- -- first absent index. Values are deleted from the `input`
- -- table.
- if type(i) == 'number' then
- local picked_value = nil
- -- Pick a value by type: boolean, dimension, integer, number, string
- if is[def.pick] ~= nil then
- if is[def.pick](v) then
+
+ for _, pick_type in ipairs(pick_types) do
+ for i, v in pairs(input) do
+ -- We can not use ipairs here. `ipairs(t)` iterates up to the
+ -- first absent index. Values are deleted from the `input`
+ -- table.
+ if type(i) == 'number' then
+ local picked_value = nil
+ if is[pick_type](v) then
picked_value = v
end
- -- Pick every value
- elseif v ~= nil then
- picked_value = v
- end
- if picked_value ~= nil then
- input[i] = nil
- return picked_value
+
+ if picked_value ~= nil then
+ input[i] = nil
+ return picked_value
+ end
end
end
end
@@ -1230,7 +1250,7 @@ local result_store = {}
-- @section
local export = {
- version = { 0, 8, 0 },
+ version = { 0, 9, 0 },
namespace = namespace,