From 2f6bafae85663973e07b3d67b2c301b98502630a Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Fri, 15 Mar 2024 21:24:56 +0000 Subject: penlightplus (15mar24) git-svn-id: svn://tug.org/texlive/trunk@70656 c570f23f-e606-0410-a88d-b1316a301751 --- .../doc/luatex/penlightplus/penlightplus.pdf | Bin 80983 -> 81225 bytes .../doc/luatex/penlightplus/penlightplus.tex | 4 +- .../tex/luatex/penlightplus/penlightplus.lua | 41 ++++++++++++++------- .../tex/luatex/penlightplus/penlightplus.sty | 28 ++++++++++---- 4 files changed, 51 insertions(+), 22 deletions(-) (limited to 'Master') diff --git a/Master/texmf-dist/doc/luatex/penlightplus/penlightplus.pdf b/Master/texmf-dist/doc/luatex/penlightplus/penlightplus.pdf index 8f4fcb97172..2e37875101e 100644 Binary files a/Master/texmf-dist/doc/luatex/penlightplus/penlightplus.pdf and b/Master/texmf-dist/doc/luatex/penlightplus/penlightplus.pdf differ diff --git a/Master/texmf-dist/doc/luatex/penlightplus/penlightplus.tex b/Master/texmf-dist/doc/luatex/penlightplus/penlightplus.tex index 53488619bf5..015dac98ef2 100644 --- a/Master/texmf-dist/doc/luatex/penlightplus/penlightplus.tex +++ b/Master/texmf-dist/doc/luatex/penlightplus/penlightplus.tex @@ -1,5 +1,5 @@ % Kale Ewasiuk (kalekje@gmail.com) -% 2024-02-29 +% 2024-03-14 % Copyright (C) 2021-2024 Kale Ewasiuk % % Permission is hereby granted, free of charge, to any person obtaining a copy @@ -279,6 +279,8 @@ or simply use \cmd{ind} without the table name, where the assumed table is the l \tblget{a}\\ \tblget{my.x}\\ \tblget{.x}\\ +\tbladd{my.newkey}{val}\tblget{newkey}\\ +\tbladd{nk}{VAL}\tblget{nk}\\ \tblif{n}{tr}[fa]\\ \tblifv{n}{TR}[FA]\\ \tblif{my.y}{Tr}[Fa]\\ diff --git a/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua b/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.lua index a831c6721d8..e51b01c14bd 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) ---% 2024-02-29 +--% 2024-03-14 --% Copyright (C) 2021-2024 Kale Ewasiuk --% --% Permission is hereby granted, free of charge, to any person obtaining a copy @@ -32,10 +32,15 @@ __PL_SKIP_TEX__ = __PL_SKIP_TEX__ or false --if declared true before here, it wi __PL_GLOBALS__ = __PL_GLOBALS__ or false __PL_NO_HYPERREF__ = __PL_NO_HYPERREF__ or false - penlight.luakeys = require'luakeys'() -penlight.COMP = require'pl.comprehension'.new() -- for comprehensions +penlight.debug_available = false -- check if penlight debug package is available +if debug ~= nil then + if type(debug.getinfo) == 'function' then + penlight.debug_available = true + end +end + -- http://lua-users.org/wiki/SplitJoin -- todo read me!! @@ -719,17 +724,22 @@ function penlight.array2d.parse_numpy2d_str(s) end -local _parse_range = penlight.clone_function(penlight.array2d.parse_range) -function penlight.array2d.parse_range(s) -- edit parse range to do numpy string if no letter passed - penlight.utils.assert_arg(1,s,'string') - if not s:find'%a' then - return penlight.array2d.parse_numpy2d_str(s) - end - return _parse_range(s) -end +if not penlight.debug_available then + penlight.tex.pkgwarn('penlight', 'lua debug library is not available, recommend re-compiling with the --luadebug option') +else + penlight.COMP = require'pl.comprehension'.new() -- for comprehensions + local _parse_range = penlight.clone_function(penlight.array2d.parse_range) + function penlight.array2d.parse_range(s) -- edit parse range to do numpy string if no letter passed + penlight.utils.assert_arg(1,s,'string') + if not s:find'%a' then + return penlight.array2d.parse_numpy2d_str(s) + end + return _parse_range(s) + end +end @@ -865,9 +875,11 @@ function penlight.get_tbl(s) return penlight.tbls[s] end -function penlight.get_tbl_index(s) +function penlight.get_tbl_index(s, undec) + undec = undec or false -- flag for allowing undeclared indexing local tbl = '' local key = '' + local s_raw = s if s:find('%.') then local tt = s:split('.') tbl = tt[1] @@ -884,8 +896,9 @@ function penlight.get_tbl_index(s) if type(key) == 'number' and key < 0 then key = #penlight.tbls[tbl]+1+key end end if tbl == '' then tbl = penlight.rec_tbl end - if penlight.tbls[tbl] == nil or penlight.tbls[tbl][key] == nil then - penlight.tex.pkgerror('penlightplus', 'Invalid index of tbl using: "'..s..'"') + + if (penlight.tbls[tbl] == nil) or ((not undec) and (penlight.tbls[tbl][key] == nil)) then + penlight.tex.pkgerror('penlightplus', 'Invalid tbl index attempt using: "'..s_raw..'". We tried to use tbl: "' ..tbl..'" and key: "'..key..'"') end return tbl, key end diff --git a/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty b/Master/texmf-dist/tex/luatex/penlightplus/penlightplus.sty index ee7ff3ad11f..3c411d227ac 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) -% 2024-02-29 +% 2024-03-14 % Copyright (C) 2021-2024 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}[2024-02-29] +\ProvidesPackage{penlightplus}[2024-03-14] \RequirePackage{luacode} \RequirePackage{luakeys} @@ -141,14 +141,14 @@ end }} -\NewDocumentCommand{\tbladd}{m m m}{\luadirect{% add a kv pair to a table - __tbl__ = penlight.get_tbl_name(\luastring{#1}) - penlight.tbls[__tbl__][\luastring{#2}] = \luastring{#3} +\NewDocumentCommand{\tbladd}{m m}{\luadirect{% add a kv pair to a table + __tbl__, __key__ = penlight.get_tbl_index(\luastring{#1}, true) + penlight.tbls[__tbl__][__key__] = \luastring{#2} }} \NewDocumentCommand{\tbladdN}{m m m}{\luadirect{% add a kv pair to a table - __tbl__ = penlight.get_tbl_name(\luastring{#1}) - penlight.tbls[__tbl__][\luastring{#2}] = \luastringN{#3} + __tbl__, __key__ = penlight.get_tbl_index(\luastring{#1}, true) + penlight.tbls[__tbl__][__key__] = \luastringN{#2} }} @@ -183,8 +183,22 @@ \NewDocumentCommand{\tblprt}{m}{\luadirect{penlight.wrth(penlight.get_tbl(\luastring{#1}),'penlightplus table: '..\luastring{#1})}} + + + % legacy code, delete this \let\kvtblundefcheck\tblkvundefcheck + +\NewDocumentCommand{\tbladdo}{m m m}{\luadirect{% add a kv pair to a table + __tbl__ = penlight.get_tbl_name(\luastring{#1}) + penlight.tbls[__tbl__][\luastring{#2}] = \luastring{#3} +}} + +\NewDocumentCommand{\tbladdNo}{m m m}{\luadirect{% add a kv pair to a table + __tbl__ = penlight.get_tbl_name(\luastring{#1}) + penlight.tbls[__tbl__][\luastring{#2}] = \luastringN{#3} +}} + \let\chgtbl\tblchg \let\newtbl\tblnew \let\gettbl\tblget -- cgit v1.2.3