On 12/23/2025 12:14 AM, David Chiang wrote:
That works, thanks very much!

Just realize that it's an (in itself valid and stable) side effect: the putting an expandafter in front of ending a local processing state token is basically a no-op but it has the side effect of pushing back that then already read next token which triggers a nesting cleanup.

(We could add such a cleanup but it means introducing an incompatibility and that is not going to happen in luatex. It's fast enough anyway and when one needs that much nesting, there is likely a better solution to the problem at hand.)

Hans

On Dec 21, 2025 at 23:09:53, Max Chernoff <[email protected] <mailto:[email protected]>> wrote:
Hi David,

On Sun, 2025-12-21 at 17:21 -0800, David Chiang wrote:
Is this the intended behavior,

I wouldn't say that it's intended, but it's definitely expected. You can
replicate fairly similar errors with just TeX code. Although I can't
replicate your error with only 10 000 loops, I needed 100 000 instead:

   \directlua{
       for i = 1, 100000 do
           tex.runtoks(function () end)
       end
   }
   \end

and is there a way to pop from the stack to avoid the overflow?

Probably the easiest solution in this case is to insert an \expandafter
every time that you call tex.runtoks:

   \directlua{
       local expandafter = token.create("expandafter")

       for i = 1, 100000 do
           tex.runtoks(function ()
               token.put_next(expandafter)
           end)
       end
   }
   \end

There's also a coroutine trick that you can use

https://tug.org/TUGboat/tb39-1/tb121hagen-exec.pdf <https://tug.org/ TUGboat/tb39-1/tb121hagen-exec.pdf>

although you'll need probably need to modify that code a little bit to
work with the latest LuaTeX.

Probably a better solution is to not call tex.runtoks a hundred thousand
times since I can't really think of a scenario where that makes
sense---it usually makes more sense to just use tex.runtoks only a few
dozen times, even if that means that you need to include way more code
in each call.

Thanks,
-- Max

_______________________________________________
dev-luatex mailing list -- [email protected]
To unsubscribe send an email to [email protected]


--

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
_______________________________________________
dev-luatex mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to