Storing and retrieving two-pass data
Hi, I am trying to save a string to the .tuc file and to retrieve it in the next run. My attempt: \starttext \startluacode local collected = utilities.storage.allocate() local tobesaved = utilities.storage.allocate() job.register("job.userdata", tobesaved) tobesaved["foo"] = "value_foo" tobesaved["bar"] = "value_bar" \stopluacode \stoptext This leads to the following entry in the .tuc file: utilitydata.job.userdata={ ["bar"]="value_bar", ["foo"]="value_foo", } I expected to be able to retrieve the data with e.g. collected["foo"], but the collected table is empty. What is the interface to retrieve the values from the .tuc file? Aditya mentioned that there will be a new interface in this (or the upcoming) beta. Marco
Am 18.04.2012 um 12:55 schrieb Marco:
Hi,
I am trying to save a string to the .tuc file and to retrieve it in the next run. My attempt:
\starttext \startluacode local collected = utilities.storage.allocate() local tobesaved = utilities.storage.allocate()
job.register("job.userdata", tobesaved)
tobesaved["foo"] = "value_foo" tobesaved["bar"] = "value_bar" \stopluacode \stoptext
This leads to the following entry in the .tuc file:
utilitydata.job.userdata={ ["bar"]="value_bar", ["foo"]="value_foo", }
I expected to be able to retrieve the data with e.g. collected["foo"], but the collected table is empty. What is the interface to retrieve the values from the .tuc file? Aditya mentioned that there will be a new interface in this (or the upcoming) beta.
The following works with the current beta, you can find another example in core-dat.mkiv. \definedataset[test-1] \definedataset[test-2] \starttext \setdataset[test-1][x=Value X 1,y=Value Y 1] \setdataset[test-1][x=Value X 2,y=Value Y 2] \setdataset[test-2][a][name=Ben Lee User,job=Manager] \setdataset[test-2][b][title=TeX by Topic] \startlines \datasetvariable{test-1}{1}{x}:\datasetvariable{test-1}{1}{y} \datasetvariable{test-1}{2}{x}:\datasetvariable{test-1}{2}{y} \stoplines Name: \datasetvariable{test-2}{a}{name} \par Job: \datasetvariable{test-2}{a}{job} \par \stoptext Wolfgang
On 2012-04-18 Wolfgang Schuster
The following works with the current beta, you can find another example in core-dat.mkiv.
[…]
Thanks a lot. One more question: How to address the last element without manually keeping track of how often it was saved? Anyhow, I am just interested in the last saved value. A solution which simply overwrites the old value every time would also be fine. \starttext \definedataset [test] \setdataset [test] [foo=first] \setdataset [test] [foo=second] % I don't know that element "2" is the last foo is: \datasetvariable{test}{2}{foo} % what I need % foo is: \datasetvariable{test}{"last"}{foo} \stoptext Regards Marco
Am 18.04.2012 um 14:15 schrieb Marco:
On 2012-04-18 Wolfgang Schuster
wrote: The following works with the current beta, you can find another example in core-dat.mkiv.
[…]
Thanks a lot. One more question: How to address the last element without manually keeping track of how often it was saved? Anyhow, I am just interested in the last saved value. A solution which simply overwrites the old value every time would also be fine.
\starttext \definedataset [test] \setdataset [test] [foo=first] \setdataset [test] [foo=second]
% I don't know that element "2" is the last foo is: \datasetvariable{test}{2}{foo}
% what I need % foo is: \datasetvariable{test}{"last"}{foo} \stoptext
\definedataset[test] \newcounter\testcounter % optional because \increment checks if the command is defined \startsetups dataset:test \doifvariable{test}{foo} { \doglobal\increment\testcounter \setdataset[test][foo=\getvariable{test}{foo}] } \stopsetups \setvariables[test][set=\texsetup{dataset:test}] \starttext \setvariables[test][foo=first] \setvariables[test][foo=second] foo is: \datasetvariable{test}{\testcounter}{foo} \stoptext Wolfgang
On 2012-04-19 Wolfgang Schuster
On 20-4-2012 17:30, Marco wrote:
On 2012-04-19 Wolfgang Schuster
wrote: Hi Wolfgang,
thanks for the answer. In the first place I also came up with a similar solution to yours. But that's what I meant by ”manually counting” and wanted to avoid. Apparently I missed the obvious, there is no special magic needed:
% doesn't seem to be necessary % \definedataset [test]
\setdataset [test] [foo] [foo=first] \setdataset [test] [foo] [foo=second]
\setdataset [test] [bar] [bar=first] \setdataset [test] [bar] [bar=second] \setdataset [test] [bar] [bar=third]
\starttext foo is: \datasetvariable{test}{foo}{foo}\crlf bar is: \datasetvariable{test}{bar}{bar} \stoptext
Wikified: http://wiki.contextgarden.net/System_Macros/Key_Value_Assignments#Two-pass_d...
Maybe you should add a note about \detupdatase[test][delay=yes] as option. In that case a node is injected and the dataset is extended with 'realpage', 'index' and 'order' information with the realpage being synchronized when the node is flushed. Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On 2012-04-22 Hans Hagen
Wikified: http://wiki.contextgarden.net/System_Macros/Key_Value_Assignments#Two-pass_d...
Maybe you should add a note about \detupdatase[test][delay=yes] as option.
Done. http://wiki.contextgarden.net/System_Macros/Key_Value_Assignments#Two-pass_d... http://wiki.contextgarden.net/Command/definedataset Marco
participants (3)
-
Hans Hagen
-
Marco
-
Wolfgang Schuster