[NTG-context] Sending data from lua to context and back to lua

Henning Hraban Ramm texml at fiee.net
Thu Feb 8 16:26:16 CET 2018

Am 2018-02-08 um 15:34 schrieb Rudolf Bahr <quasi at quasi.de>:

> On Thu, Feb 08, 2018 at 09:30:48AM +0100, Thomas A. Schmitz wrote:
>> On 02/07/2018 06:39 PM, Rudolf Bahr wrote:
>>> Sometimes the necessity could arise to send data from lua to context
>>> and answers back to lua. I tried this by using "read" and
>>> "immediate\write" commands in context. These commands are described
>>> in chapter 21 and 22 of Donald E. Knuth's "The TeXbook".
>>>
>>> My question is: Do there exist better and more simple solutions?
>>
>> You can print (typeset) information from inside lua code with the "context"
>> function. Have you seen the manual cld-mkiv.pdf? It's in the minimals.
>>
>> Thomas
>
> Yes, thank you. I tried "context()" several times, but without success.
> Could be, that I have a false meaning how to use it: If I transfer data
> from context to lua and vice versa then in my imagination there must be
> variables in both languages  where the sent data is to be found.
>
> With the use of "\immediate\write" and "\read" in context and the read and write
> functions in lua I know exactly from where to where the data goes. How to do
> the same with "context()"?

\startluacode

function SomeFunction()
context("Value")
end

\stopluacode

\def\MyVar{\ctxlua{SomeFunction()}}

Greetlings, Hraban
---
http://www.fiee.net
http://wiki.contextgarden.net
GPG Key ID 1C9B22FD