On 16-2-2012 07:43, Mari Voipio wrote:

I'm trying to do something that should be possible and I think
"variables" is the answer, I just can't figure out how.

attached .. (will be in test suite)

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
-----------------------------------------------------------------
% For Mari Voipio

\startluacode

    local files = { }

    function document.collectgraphics(pattern)
        files = table.merged(files,dir.glob(pattern))
        files = table.unique(files)
        table.sort(files)
        logs.report(string.format("graphics: %s",table.concat(files," ")))
    end

    function document.choosegraphic()
        if #files > 0 then
            context(table.remove(files, math.random(1,#files)) or "dummy")
        else
            context("dummy")
        end
    end

\stopluacode

\def\CollectGraphics[#1]{\ctxlua{document.collectgraphics("#1")}}
\def\ChooseGraphic      {\ctxlua{document.choosegraphic()}}

\CollectGraphics[*.png]
\CollectGraphics[*.jpg]

\starttext

    \dorecurse {10} {
        \expanded{\externalfigure[\ChooseGraphic][width=4cm]}
    }

\stoptext
___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to