ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Pablo Rodriguez <oinos@gmx.es>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: store data in the first run for later runs?
Date: Fri, 6 Nov 2020 19:38:53 +0100	[thread overview]
Message-ID: <860ddf5d-d501-d590-d2eb-b13e29f9d045@gmx.es> (raw)

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
___________________________________________________________________________________

                 reply	other threads:[~2020-11-06 18:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=860ddf5d-d501-d590-d2eb-b13e29f9d045@gmx.es \
    --to=oinos@gmx.es \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).