Hi,

I tried the following code.

The lua code part has no problem.
The data is saved well.

I’d like to make an array of points (i, MP.data[i][1])

But I couldn’t retrieve the data as a point.
Before for loop, it said no complaints.
It gives an error message as following:

***************
error: Missing ')' has been inserted
metafun         > log >
metapost        > trace > <to be read again> ,
metapost        > trace > <for(1)> j := (EXPR 0) * u ; A [ (EXPR 0) ] := ( 
decimal j , lua ( "MP.data[" & decimal (EXPR 0) & "][1]" ) ) ; label ( textext 
( "A" ) , A [ (EXPR 0) ] ) ;  ENDFOR
metafun         > log >
metafun         > log > I found no right delimiter to match a left one. So I've 
put one in, behind the scenes; this may fix the problem.
****************
What is wrong in the code?

Thank you for reading.

Best regards,

Dalyoung



\usemodule[m-matrix]
\startluacode
mtx = moduledata.matrix
\stopluacode

\starttext
\startluacode
local matT = {{0,0,1,1/3},{1,0,0,1/3},{0,1/2,0,1/3},{0,1/2,0,0}}
local matOld = {{1/4},{1/4},{1/4},{1/4}}
local matNew = {}
local matHistory = {}
table.insert(matHistory, matOld)
for i = 2, 5   do
    matOld = matHistory[i-1]
    matNew = mtx.product(matT, matOld) 
    mtx.typeset(matT)context("\\times")mtx.typeset(matOld)
        context(" = ") mtx.typeset(matNew) context("\\blank")
    table.insert(matHistory, matNew)
end
table.save("tempList.lua", matHistory)
\stopluacode

\startMPcode
numeric u,i,j; u := 1cm;

pair A[];
path p;
lua("MP = { } MP.data = table.load('tempList.lua')") ;
for i = 1 upto 3:
    j := i*u;
    A[i] := (decimal j,lua("MP.data[" & decimal i & "][1]"));
   label(textext("A"),A[i]);
endfor;
\stopMPcode
\stoptext



Here is the saved data:

return {
 {
  { 0.25 },
  { 0.25 },
  { 0.25 },
  { 0.25 },
 },
 {
  { 0.33333333333333331 },
  { 0.33333333333333331 },
  { 0.20833333333333331 },
  { 0.125 },
 },
 {
  { 0.24999999999999997 },
  { 0.375 },
  { 0.20833333333333331 },
  { 0.16666666666666666 },
 },
 {
  { 0.26388888888888884 },
  { 0.30555555555555552 },
  { 0.24305555555555555 },
  { 0.1875 },
 },
 {
  { 0.30555555555555558 },
  { 0.32638888888888884 },
  { 0.21527777777777776 },
  { 0.15277777777777776 },
 },
}
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : [email protected] / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to