Thank you Aditya!

This solved my mwe:

    -- Print items
    for index, item in ipairs(items) do
      -- Generate a unique buffer name using the loop index
      local buffer_name = "buffer_" .. index

      -- Write the item to the buffer
      context.tobuffer(buffer_name, item)

      -- Retrieve and print the buffer content
      context.getbuffer{buffer_name}
    end

On 9 Apr 2026, at 11:01, Aditya Mahajan wrote:

On Thu, 9 Apr 2026, Emanuel Han wrote:

Sorry, some autocorrection of the mail program modified my copy-pasted mwe in my previous mail. I post it again here, this time not modified:

Here is MWE showing what is going wrong:

\starttext

\startluacode
  local str = "\\startstackingsteps[1] ABC \\stopstackingsteps"
  context(str)
\stopluacode

\stoptext

The reason this fails is that \startstacking is effectively a buffer; it stores everything until it sees a stopstacking and then processes it. Such mechanisms do not work from the lua end. For example:

\starttext

\startluacode
  local str = "\\startbuffer[what] ABC \\stopbuffer"
  context(str)
\stopluacode

\stoptext

Ironically, a simple fix is to go via the buffer route!

\starttext

\startluacode
  local str = "\\startstackingsteps[1] ABC \\stopstackingsteps"
  context.tobuffer("stacking", str)
  context.getbuffer{"stacking"}
\stopluacode

\stoptext

This sets the buffer "stacking" at the lua level, and the context side only sees stuff when \getbuffer is called. Note that in the code above, context.getbuffer{...} is a shortcut for context.getbuffer({...}).

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

maillist : [email protected] / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : [email protected] / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to