* store data in the first run for later runs?
@ 2020-11-06 18:38 Pablo Rodriguez
0 siblings, 0 replies; only message in thread
From: Pablo Rodriguez @ 2020-11-06 18:38 UTC (permalink / raw)
To: mailing list for ConTeXt users
Dear list,
I have the following sample:
\starttext
\startTEXpage[offset=1em]
\startmode[*first]
\startluacode
io.write(" What’s your name? ")
document.user_name = io.read()
document_data = { "\\def\\UserName{" .. document.user_name .. "}" }
io.savedata(tex.jobname.."_document-tmp-data.txt", document_data)
\stopluacode
\stopmode
\input{\jobname_document-tmp-data.txt}
\UserName, nice to meet you.
\stopTEXpage
\stoptext
This prompts user input on the first run, but I have to save to an
external file to be able to read it in next runs.
Just in case you might wonder, the actual code requires "--purgeall".
Is there no way to save that in the .tuc file for later runs?
I have tried
https://wiki.contextgarden.net/System_Macros/Key_Value_Assignments#Multi-pass_data
(as Aditya suggested to me), but runs after the first one see to empty
the data in the Lua table.
Adapting a sample from the wiki:
\starttext
\definedataset[somedataset]
\startmode[*first]
\setdataset[somedataset][wantscake=yes, wantsdeath=no]
\stopmode
Do you want cake? \datasetvariable{somedataset}{1}{wantscake}.\\
BTW, do you want death? \datasetvariable{somedataset}{1}{wantsdeath}.
\stoptext
I wonder whether there is no cleaner way to do this.
Many thanks for your help,
Pablo
--
http://www.ousia.tk
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-11-06 18:38 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-06 18:38 store data in the first run for later runs? Pablo Rodriguez
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).