[NTG-context] Howto use the lua io.read() function only in the first context run?

Andreas Schneider aksdb at gmx.de
Thu Mar 17 09:11:12 CET 2016


Am 2016-03-16 22:47, schrieb Romain Diss:
> Hi,
> 
> Thank you Hans... but it doesn't fully work. Now I only enter the input
> once (that's ok) but on the second run, the variable is not defined
> anymore. How can I keep it in the conTeXt memory?
> 
> -- Minimum still not working example
> local name
> if environment.arguments.currentrun == "1" then io.read() end
> context.startdocument()
> context("Hello " .. name)
> context.stopdocument()
> 
> All the best

You can use the LUA interface "job.passes".
In the first pass, you store your value. For example:
local passdata = job.passes.define("mystuff") --I usually define this at 
the top of my script and reuse it.
passdata["somevalue"] = "hello world";

Then in the subsequent runs you can access
local lastpassdata = job.passes.getcollected("mystuff") --Same here...
print(lastpassdata["somevalue"])

Best regards,
Andreas


More information about the ntg-context mailing list