On 11/27/2022 1:05 PM, damien thiriet via ntg-context wrote:
Hi,


I am used to giving very extensive feedbacks to my pupils.
These are buffers with xtables flushing lua vectors.
Here is their basic structures:

* an environment that stores xtables. Turned into MWE, look like:

    \startenvironment env_corrige.mkiv

    \startluacode
       userdata = userdata or {}
    function userdata.Critere (commentaire,note,notemax)
       context.startxcell {"width=11cm","height=2.75cm"}
          context(Eleve[commentaire])
       context.stopxcell ()
       context.startxcell {"width=1.5cm","align=flushright"}
          context(Eleve[note])
          context("/")
          context(notemax)
       context.stopxcell ()
    end
    \stopluacode

    \startbuffer [grille]
    \startxtable
       \startxrow
          \startxcell
             \ctxlua {userdata.Critere ("structure","NoteStructure",2)}
          \stopxcell
       \stopxrow
    \stopxtable
    \stopbuffer
    \stopenvironment

* The main file is divided in subjects, each one of them
being the feedback to one pupil. In a MWE fashion

    \useenvironment [env_corrige]
    \starttext
    \startsubject[title={Astérix}]
    \startluacode
    Eleve = {
       structure = "analyse très fine",
       NoteStructure = 2,
    }
    \stopluacode
    \getbuffer [grille]
    \stopsubject

    \startsubject[title={Obélix}]
    Eleve = {
      structure = "le détail doit être travaillé. Pensez à la finesse de vos menhirs…"
       NoteStructure = 1,
    }
    \stopsubject
    \getbuffer [grille]
    \stoptext

Since whatever I fill in those files is written
inside luacode environment, I tried to switch to
cld documents.

Here is my main file in cld version

    context.useenvironment({"env_corrige"})

    context.starttext()

    context.startsubject({title="Asterix"})

    Eleve = {
       structure = "analyse très fine",
       NoteStructure = 2,
    }
    context.getbuffer({"ExoCorrection"})
    context.stopsubsubject()

    context.startsubject({title="Obélix"})

    Eleve = {
      structure = "le détail doit être travaillé. Pensez à la finesse de vos menhirs…"
       NoteStructure = 1,
    }
    context.getbuffer({"ExoCorrection"})
    context.stopsubsubject()
    context.stoptext()

The troubles is that buffers are filled with
the last version of Eleve table.
I guess this is because the whole file
is parsed and then filled in buffers.
My understanding of the cld manuel is that
context.tobuffer()
and
context.direct()

should be used, but couldn't figure out how.
Tried several times, also with context.step but
all failed.
I think I didn't properly understand the "temp"
and str of context.tobuffer description in manual.

What changes should I introduce to my cld files?
see attached ... it's more that you overload Eleve ... an alternative is to make a function that gets that table as (then local) argument but I don't want to touch your code too much

the function wrapper sort of delays (immediate evaluation is a general problem, of function driven typesetting, which is why in the end a pure function driven one is not better / easier than tex)


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
-----------------------------------------------------------------
\startenvironment env_corrige

\startluacode

userdata = userdata or {}

function userdata.Critere (commentaire,note,notemax)
  context.startxcell { "width=11cm", "height=2.75cm" }
     context(userdata.Eleve[commentaire])
  context.stopxcell ()
  context.startxcell { "width=1.5cm", "align=flushright" }
     context("%s/%s",userdata.Eleve[note], notemax)
  context.stopxcell ()
end

\stopluacode

\startbuffer [ExoCorrection]
\startxtable
  \startxrow
     \startxcell
        \ctxlua {userdata.Critere ("structure", "NoteStructure", 2)}
     \stopxcell
  \stopxrow
\stopxtable
\stopbuffer

\stopenvironment
context.useenvironment { "env_corrige" }

context.starttext()

    context(function()
       context.startsubject { title = "Asterix" }
       userdata.Eleve = {
          structure     = "analyse très fine",
          NoteStructure = 2,
       }
       context.getbuffer { "ExoCorrection" }
       context.stopsubsubject()
    end)

    context(function()
        context.startsubject { title = "Obélix" }
        userdata.Eleve = {
          structure     = "le détail doit être travaillé. Pensez à la finesse 
de vos menhirs…",
          NoteStructure = 1,
        }
       context.getbuffer { "ExoCorrection" }
       context.stopsubsubject()
    end)

context.stoptext()
___________________________________________________________________________________
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
___________________________________________________________________________________

Reply via email to