Hi,

I upgrsded lmtx. A few small things (emntioned already) at the tex end but Alan and I are now in metafun mode.

I (finally) adpated lmtx to delegated mplib logging, so

\startMPcode{doublefun}
    tracingall ; fill fullcircle scaled 3cm withcolor "darkmagenta" ;
\stopMPcode

should work. Just in case someone keeps an eye on the metafun code and wonders what 'records' are, here is an example:

\starttext

\startMPcode

    record FooA ; interim FooA := newrecord [
        name = "FooA"
        index = 123
    ] ;

    record FooB ; interim FooB := newrecord [
        name = "FooB"
        index = 456
    ] ;

    record FooC ; interim FooC := newrecord [
        name  = "FooC"
        index = 789,
        crap  = [
            more = "MORE"
        ]
    ] ;

draw textext(getrecord(FooA).name) rotated -45 withcolor "darkred" ; draw textext(getrecord(FooB).name) rotated 0 withcolor "darkgreen" ; draw textext(getrecord(FooC).name) rotated 45 withcolor "darkblue" ; draw textext(getrecord(FooC).crap.more) rotated 90 withcolor "darkgray" ;

    begingroup;

        interim FooC := newrecord [
            name  = "FooC"
            index = 789,
            crap  = [
                more = "NESTED 1"
            ]
        ] ;

draw textext(getrecord(FooC).crap.more) shifted (0,-1cm) withcolor "darkgray" ;
        draw textext(FooC) shifted (2cm,-1cm) withcolor "darkgray" ;

        begingroup;

            interim FooC := newrecord [
                crap  = [
                    more = "NESTED 2"
                ]
            ] ;

draw textext(getrecord(FooC).index) shifted (4cm,-2cm) withcolor "darkgray" ; draw textext(getrecord(FooC).crap.more) shifted (0,-2cm) withcolor "darkgray" ;
            draw textext(FooC) shifted (2cm,-2cm) withcolor "darkgray"  ;

        endgroup;

    endgroup;

draw textext(getrecord(FooC).crap.more) shifted (0,-3cm) withcolor "darkgray" ;
    draw textext(FooC) shifted (2cm,-3cm) withcolor "darkgray"  ;

    record FooD ; interim FooD := newrecord [
        name = "FooD"
        list = { 11, 22, 33, 44 }
    ] ;

    for i=1 upto getrecord FooD.list[] :
draw textext(getrecord(FooD).list[i]) shifted (i*cm,-5cm) withcolor "darkgray" ;
    endfor ;
    for i=1 upto getrecord FooD.#list :
draw textext(getrecord(FooD).list[i]) shifted (5cm+i*cm,-5cm) withcolor "darkred" ;
    endfor ;

    numeric v ;
    for i=1 upto 10000 :
        v := 0 ;
        for j=1 upto 4 :
            v := v + getrecord FooD.list[j] ;
        endfor ;
    endfor ;
    draw textext(v) shifted (12cm,-5cm) withcolor "darkgray"  ;

    interim FooD := setrecord [
        name = "FooD"
        tsil = { 44, 33, 22, 11 }
    ] ;

    for i=1 upto getrecord FooD.#list :
draw textext(getrecord FooD.list[i]) shifted (5cm+i*cm,-6cm) withcolor "darkgreen" ;
    endfor ;
    for i=1 upto getrecord FooD.#tsil :
draw textext(getrecord FooD.tsil[i]) shifted (5cm+i*cm,-7cm) withcolor "darkgray" ;
    endfor ;

    tracingall ;

draw textext(getrecord FooD.list[2]) shifted (5cm,-8cm) withcolor "darkmagenta" ;

\stopMPcode

\startluacode
    inspect(metapost.getrecord("FooA"))
    inspect(metapost.getrecord("FooB"))
    inspect(metapost.getrecord("FooC"))
    inspect(metapost.getrecord("FooD"))
\stopluacode

\stoptext

So, one can store structured data at the mp end, use it there, and access it also from lua (after all it's done in lua). It honors metapost grouping (which is what interim does with internals, and records use metapost internals as reference).

Hans

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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 via email to