Of course, it takes me some time to understand, and a little reading in the metafun xl manual, but now I catch it !
\starttext
\startMPpage
runscript("metapost.setparameterset('test', table.load('mydata.lua') or { })") ;
path b ; b := getparameterpath "test" "test_c";
draw fullcircle scaled 3cm ;
draw b scaled .4;
% show(b);
getparameters "test" [
test_a = 123,
test_b = (456,789),
test_c = (boundingbox currentpicture)
] ;
runscript("table.save('mydata.lua',(metapost.getparameterset('test')))") ;
\stopMPpage
\stoptext
but maybe i need abetter one .. a proper save/restore in the tuc file or so, but you can play with this first
Hans
If someones in the futur needs more explanation (like me!), here is my minimal working example derived from the one of Hans:
% ————————————
\starttext
\startMPpage
pair ThePosition[];
ThePosition[1] := (0,0) ;
ThePosition[2] := (10,10) ;
draw ThePosition[1] -- ThePosition[2] ;
% save the parameters in the object MyData
getparameters "MyData" [
pos_a = ThePosition[1],
pos_b = ThePosition[2]
] ;
% Save this object in a file
runscript("table.save('TheMagicalFile.lua',(metapost.getparameterset('MyData')))") ;
\stopMPpage
% We modify the value of ThePosition[2]
\startMPpage
ThePosition[2] := (10,0) ;
draw ThePosition[1] -- ThePosition[2] ;
\stopMPpage
% We now read the value of ThePosition[2] from the file
\startMPpage
% Save the data from the external file
runscript("metapost.setparameterset('MyData', table.load('TheMagicalFile.lua') or { })") ;
ThePosition[2] := getparameter "MyData" "pos_b" ;
draw ThePosition[1] -- ThePosition[2] ;
\stopMPpage
\stoptext
% ————————————
Complementary question : I saw that the « pos_a » « pos_b » of the example could not take numerical value, for example pos_1, pos_2.. How can I use metafun to write a macro to save the contents of hundreds of variable in this object, something like :
getparameters "MyData » [
for i=1 upto 100 :
pos_decimal(i) = ThePosition[i],
endfor ;
] ;
If this is possible, then this is wonderful and open news doors !
Thanks again,
Fabrice.