Hello LuaMetaFun Fans,

Can I use mp.inject.path in Lua to create a disconnected path in MetaPost?

This is for my module that draws globes. I currently do something like this for 
drawing the continents. (This MWE has two triangular continents.)

\startluacode
  continents = {}
  continents[1] = {{0,0}, {-1,-1}, {-1,0}, cycle = true }
  continents[2] = {{0,1}, {1,0}, {1,-1}, cycle = true }
  function mp.getglobepath(continentnum)
    mp.inject.path(continents[continentnum])
  end
\stopluacode

\startMPpage
  path p[], q ;
  p1 = (lua.mp.getglobepath(1) scaled 1cm) ;
  p2 = (lua.mp.getglobepath(2) scaled 1cm) ;
  q = p1 && p2 && cycle ;
  draw p1 withpen pencircle scaled 2pt withcolor .7 ;
  draw p2 withpen pencircle scaled 2pt withcolor .7 ;
  fill q withcolor 0.9 ;
  draw q withcolor red ;
\stopMPpage

The path q has both of the continents, disconnected.

I’d like to produce the two continents in Lua and pass them to MetaPost as a 
single disconnected path, using something like this: 

\startluacode
  continents = {
    {0,0}, {-1,-1}, {-1,0}, — Change this to make a disconnected path!
    {0,1}, {1,0}, {1,-1},
    cycle = true }
  function mp.getglobepath()
    mp.inject.path(continents)
  end
\stopluacode

\startMPpage
  path p ;
  p = (lua.mp.getglobepath() scaled 1cm) ;
  fill p withcolor 0.9 ;
  draw p withcolor red ;
\stopMPpage

If I can make the path p disconnected, this would allow me to make exactly the 
path I want in Lua, before passing it to MetaPost, rather than passing lots of 
paths and connecting them in MetaPost with the mysterious (to me) && or &&&&.

Thanks!
Gavin


___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
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