ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* protected macro vs protected luacall
@ 2023-01-26 20:33 Henri Menke via ntg-context
  2023-01-26 22:07 ` Hans Hagen via ntg-context
  0 siblings, 1 reply; 8+ messages in thread
From: Henri Menke via ntg-context @ 2023-01-26 20:33 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Henri Menke

Dear list,

I have noticed a somewhat strange difference between protected macros
and protected luacalls, namely that the latter cannot be expanded by
\the.  In the example below I define a Lua function that prints
\numexpr 17\relax to the token stream and I call it once from a
protected TeX macro wrapping \directlua and once from a protected
luacall registered with token.set_lua.


\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

\bye


However, the second \the\test fails with the following error:


! You can't use `luacall 0' after \the.
l.21 \the\test
            

Is this asymmetry between luacalls and regular macros intended? Is
there a workaround where I can have a luacall that doesn't expand
inside of \edef but still expands after \the?

Cheers, Henri
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : https://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-01-27 11:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-26 20:33 protected macro vs protected luacall Henri Menke via ntg-context
2023-01-26 22:07 ` Hans Hagen via ntg-context
2023-01-27  9:13   ` Henri Menke via ntg-context
2023-01-27  9:30     ` Hans Hagen via ntg-context
2023-01-27  9:35       ` Henri Menke via ntg-context
2023-01-27 10:01         ` Hans Hagen via ntg-context
2023-01-27 11:03           ` Henri Menke via ntg-context
2023-01-27 11:52             ` Hans Hagen via ntg-context

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).