[NTG-context] protected macro vs protected luacall
Hans Hagen
j.hagen at freedom.nl
Thu Jan 26 23:07:03 CET 2023
On 1/26/2023 9:33 PM, Henri Menke via ntg-context wrote:
> \directlua{
> userdata = userdata or {}
> function userdata.test()
> tex.print("\string\\numexpr 17\string\\relax")
> end
> }
>
> \tt
> \protected\def\test{\directlua{userdata.test()}}
> \meaning\test\par
> \edef\x{\test}\meaning\x\par
> \the\test
>
> \directlua{
> local t = lua.get_functions_table()
> t[\string#t + 1] = userdata.test
> token.set_lua("test", userdata.test, \string#t, "protected")
> }
> \meaning\test\par
> \edef\x{\test}\meaning\x\par
> \the\test
from the code it looks like we're talking plain luatex ...
\the is very selective and doesn't work for all primitives or macros
compare it to \number which accepts any number representation following
it while \the doesn't work ok 123
that said, your set_lua is wrong and passes a function as well as an index
\directlua{
lua.get_functions_table()[999] = function()
tex.print("\string\\numexpr 17\string\\relax")
end
token.set_lua("test", 999)
}
\the \test % needs the \numexpr
\number \test % doesn't
\count0 \test % needs the \numexpr
\count0=\test % doesn't
etc
Hans
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
More information about the ntg-context
mailing list