From 46cd06e16d8d655721ece4f672750b0a62ca4703 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 5 Sep 2023 20:06:27 +0000 Subject: penlightplus (5sep23) git-svn-id: svn://tug.org/texlive/trunk@68185 c570f23f-e606-0410-a88d-b1316a301751 --- .../tex/luatex/penlightplus/penlightplus.lua | 82 ++++++++++++++-------- .../tex/luatex/penlightplus/penlightplus.sty | 57 ++++----------- 2 files changed, 65 insertions(+), 74 deletions(-) (limited to 'Master/texmf-dist/tex/luatex/penlightplus') diff --git a/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua b/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua index 96eb565fb65..1f74d45777a 100644 --- a/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua +++ b/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua @@ -1,5 +1,5 @@ --% Kale Ewasiuk (kalekje@gmail.com) ---% 2023-08-27 +--% 2023-09-04 --% Copyright (C) 2021-2023 Kale Ewasiuk --% --% Permission is hereby granted, free of charge, to any person obtaining a copy @@ -776,22 +776,36 @@ end penlight.tbls = {} -function penlight.get_tbl_item(s, p) -- get item with string, p means print value - p = p or false - local itm = 'tbl: INVALID INDEX WITH: "'..s..'"' - if s:find('%.') then - local tt = s:split('.') - itm = penlight.tbls[tt[1]][tt[2]] - elseif s:find('/') then - local tt = s:split('/') - itm = penlight.tbls[tt[1]][tonumber(tonumber(tt[2]))] - else - if s:isdigit() then - itm = penlight.tbls._recent[tonumber(s)] +penlight.rec_tbl = '' +penlight.rec_tbl_opts = {} + +function penlight.get_tbl_index(s) + local tbl = '' + local key = '' + if s:find('%.') then + local tt = s:split('.') + tbl = tt[1] + key = tt[2] + elseif s:find('/') then + local tt = s:split('/') + tbl = tt[1] + key = tonumber(tonumber(tt[2])) + if key < 0 then key = #penlight.tbls[tbl]+1+key end else - itm = penlight.tbls._recent[s] + tbl = penlight.rec_tbl + key = tonumber(s) or s + if type(key) == 'number' and key < 0 then key = #penlight.tbls[tbl]+1+key end end - end + if penlight.tbls[tbl] == nil or penlight.tbls[tbl][key] == nil then + penlight.tex.pkgerror('penlightplus', 'Invalid index of tbl using: "'..s..'"') + end + return tbl, key +end + +function penlight.get_tbl_item(s, p) -- get item with string, p means print value + p = p or false + local tbl, key = penlight.get_tbl_index(s) + local itm = penlight.tbls[tbl][key] if p then tex.sprint(tostring(itm)) end @@ -800,20 +814,30 @@ end function penlight.set_tbl_item(s, v) - if s:find('%.') then - local tt = s:split('.') - penlight.tbls[tt[1]][tt[2]] = v - elseif s:find('/') then - local tt = s:split('/') - penlight.tbls[tt[1]][tonumber(tonumber(tt[2]))] = v - else - if s:isdigit() then - penlight.tbls._recent[tonumber(s)] = v - else - penlight.tbls._recent[s] = v - end - end - end + tbl, key = penlight.get_tbl_index(s) + penlight.tbls[tbl][key] = v +end + +function penlight.check_recent_tbl_undefault() + local undefaults = {} + if penlight.rec_tbl_opts ~= nil then + local defaults = penlight.tablex.union( + penlight.rec_tbl_opts.defs or {}, + penlight.rec_tbl_opts.defaults or {} + ) + for k, v in pairs(penlight.tbls[penlight.rec_tbl]) do + if defaults[k] == nil then + undefaults[#undefaults+1] = k + end + end + if penlight.hasval(undefaults) then + penlight.tex.pkgerror('penlightplus', + 'Invalid keys passed to tbl keyval: ' .. (', '):join(undefaults) .. + ' ; choices are: ' .. (', '):join(penlight.tablex.keys(defaults)) + ) + end + end +end if penlight.hasval(__PL_GLOBALS__) then diff --git a/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty b/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty index 3f95ae4d9ef..01b0aafc167 100644 --- a/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty +++ b/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty @@ -1,5 +1,5 @@ % Kale Ewasiuk (kalekje@gmail.com) -% 2023-08-27 +% 2023-09-04 % Copyright (C) 2021-2023 Kale Ewasiuk % % Permission is hereby granted, free of charge, to any person obtaining a copy @@ -22,7 +22,7 @@ % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE % OR OTHER DEALINGS IN THE SOFTWARE. -\ProvidesPackage{penlightplus}[2023-08-27] +\ProvidesPackage{penlightplus}[2023-09-04] \RequirePackage{luacode} \RequirePackage{luakeys} @@ -102,25 +102,27 @@ \NewDocumentCommand{\ifluaxv}{m m O{}}{\ifluax{penlight.hasval(#1)}{#2}[#3]} -% testing ifluax -% {-->\ifluax{1 == 2}{\LARGE TRUE}[\tiny FALSE]<--test\\ -% -->\ifluax{abc == nil}{\LARGE TRUE}[\tiny FALSE]<--test} - %%% \NewDocumentCommand{\newtbl}{m}{\luadirect{ penlight.tbls[\luastring{#1}] = {} - penlight.tbls._recent = penlight.tbls[\luastring{#1}] + penlight.rec_tbl = \luastring{#1} }} \NewDocumentCommand{\tblfrkv}{m m O{}}{ \luadirect{ - penlight.tbls[\luastring{#1}] = penlight.luakeys.parse(\luastring{#2}, penlight.luakeys.parse(\luastring{#3})) - penlight.tbls._recent = penlight.tbls[\luastring{#1}] + penlight.rec_tbl_opts = penlight.luakeys.parse(\luastring{#3}) + penlight.tbls[\luastring{#1}] = penlight.luakeys.parse(\luastring{#2}, penlight.rec_tbl_opts) + penlight.rec_tbl = \luastring{#1} }} +\NewDocumentCommand{\tblfrcsv}{m m O{}}{\tblfrkv{#1}{#2}[naked_as_value=true,#3]} + + +\NewDocumentCommand{\kvtblundefcheck}{}{\luadirect{penlight.check_recent_tbl_undefault()}} % todo + \NewDocumentCommand{\chgtbl}{ m }{ \luadirect{ - penlight.tbls._recent = penlight.tbls[\luastring{#1}] + penlight.rec_tbl = \luastring{#1} }} \NewDocumentCommand{\gettbl}{m}{\luadirect{ @@ -143,38 +145,3 @@ \NewDocumentCommand{\iftblv}{m m O{}}{\ifluaxv{penlight.get_tbl_item(\luastring{#1})}{#2}[#3]} - - -%\NewDocumentCommand{\tblupd}{ m m}{\luadirect{ -% penlight.tablex.update(penlight.tbls[\luastring{#1}], penlight.tbls[\luastring{#2}]) -%}} -% -%\NewDocumentCommand{\tblupdkv}{ m m }{\luadirect{ -% penlight.tablex.update(penlight.tbls[\luastring{#1}], penlight.luakeys.parse(\luastring{#2})) -%}} - -% -%% todo need a get table function. If blank is passed, the last table referenced is used. -%\NewDocumentCommand{\tblfrkvII}{ m m m }{\luadirect{ -% _G[\luastring{#1}] = penlight.tablex.update(penlight.luakeys.parse(\luastring{#2}), luakeys.parse(\luastring{#3})) -%}} - -%\NewDocumentCommand{\tbldo}{m m O{} }{\luadirect{ -% % tex.sprint(tostring(_G[\luastring{#1}][#2])) -% % todo allow one to use pl tablex function here, -% % {tbl}{update}[arg1][arg2] -% penlight.tablex[\luastring[#1]](_G[\luastring{}], _G[\luastring{}]) -%}} - - - - -%%%%%%%%5 - -%\begin{luacode*} -% function set_dim(name, len) -% tex.sprint('\\global\\let\\'..name..'\\relax') -- reset length -% tex.sprint('\\global\\newlength{\\'..name..'}') -- make new len -% tex.setglue(name, tex.sp(len)) -% end -%\end{luacode*} -- cgit v1.2.3