That's great. This is exactly what I needed for now, though Max's magic may
be useful in the future.

On Sun, Mar 30, 2025 at 2:21 PM Wolfgang Schuster <
[email protected]> wrote:

> Am 29.03.2025 um 16:06 schrieb Mohammad Hossein Bateni:
> > Hello,
> >
> > I have some code like this:
> >
> > ---------------------------------
> > \def\MakeSomething{... some code that returns number 12}
> >
> > \startluacode
> > function WorkWithSomething(data)
> >    -- call MakeSomething to obtain 12
> >    -- base on the value above make some decisions
> > end
> >
> > WorkWithSomething(some_data)
> > \stopluacode
> > ---------------------------------
> >
> > If I use context.MakeSomething() inside the lua block, this is
> > buffered till the end of the block, so I can't get the result and work
> > with it.
> >
> > If MakeSomething is a command already "edef-ed", I can use
> > tokens.getters.macro.MakeSomething to find the value.
> >
> > If MakeSomething has an argument which is determined within the
> > lua block, then I can't use this hack.
> >
> > The ugly partial solution I have found is to change the signature of
> > WorkWithSomething to receive an argument and then I replicate the
> > parameters of MakeSomething on the TeX side:
> >
> > ---------------------------------
> > \def\MakeSomething#1{...}
> >
> > \startluacode
> > function WorkWithSomething(data,MakeSomethingOutput)
> >    -- we wanted to use some computation on data to obtain input to
> > MakeSomething
> >    -- then call MakeSomething to obtain its result
> > end
> > \stopluacode
> >
> > \ctxlua{WorkWithSomething(some_data, "\MakeSomething{replicate
> > processing on data to obtain input to this macro}")}
> > ---------------------------------
> >
> > Is there a more elegant solution?
> > Ideally I want a way to start a TeX process under Lua, and
> > process the macros there before I get to the next line of Lua code.
> >
> > In my motivation, MakeSomething is \datasetvariable. I wanted to look up
> > something in the dataset and use it for the rest of
> computation/typesetting.
>
> ConTeXt provides the following function to access dataset values:
>
> job.datasets.getdata(name,tag,key,default)
>
> Wolfgang
>
>
> ___________________________________________________________________________________
> 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