Hi everyone,

I’ve made great progress creating globes for my diagrams using the data in the 
mp-geo package and some ideas from Hans. I have a couple questions about moving 
information from Lua to MetaPost. Below is a MWE for illustration. I have two 
related questions:

1) Is there a way for MetaPost to grab information from a Lua table? Currently 
the MetaPost code calls a Lua function which has a single line returning the 
information from the table. Is this necessary, or is these something in 
MetaPost that can get a path or color from a Lua table? 

2) While I’m having good luck with paths, colors are causing trouble. In the 
data set the color information is in strings with French names of the color, 
like “rouge.” If I hand this string to MetaPost, MetaPost doesn’t expand it 
into a color. It does work if it is a native color, like “red,” but not if it 
is a defined color and not if the color is in a Lua variable. Any suggestions?

Thanks!
Gavin


The code below produces four pie shape wedges to show the different results of 
handling the color. They should all be red, but the last two are black.


\startMPinclusions
  color rouge;          % To avoid changing the data files, I need to define 
colors in French.
  rouge=(1,0,0);        % For this MWE, I only define rouge.
  
  color mycolor;        % Defining mycolor in MetaPost works great, as shown in 
the first shape.
  mycolor = rouge;
\stopMPinclusions

\startluacode
  myluapath = {{0,0}, {1,0,0,0,1,0.25}, {0.8,0.6,0.95,0.4}, cycle = true}
  myluacolor = “red”    --% Data files are read by Lua, so the myluacolor will 
be a string (in French, but native colors don't work either).
  
  function mp.getpath() --% Is there a way for the MetaPost code to grab the 
path directly from the table?
    mp.inject.path(myluapath)
  end
  
  function mp.getred() --% Returning a string work for native colors.
    mp.inject.string("red")
  end

  function mp.getrouge() --% Returning a string does not work for defined
    mp.inject.string("rouge")
  end

  function mp.getcolor() --% Putting the string in a variable does not work.
    mp.inject.string(mycolor)
  end
\stopluacode

\starttext
  \startMPpage
   fill lua.mp.getpath() scaled 2.5cm withcolor mycolor; % MetaPost color 
definition works great.
   fill lua.mp.getpath() scaled 2.5cm shifted (0, -2cm) withcolor 
lua.mp.getred(); % Returning a string work for native colors.
   fill lua.mp.getpath() scaled 2.5cm shifted (0, -4cm) withcolor 
lua.mp.getrouge(); % Returning a string does not work for defined colors.
   fill lua.mp.getpath() scaled 2.5cm shifted (0, -6cm) withcolor 
lua.mp.getcolor(); % Putting the string in a variable does not work.
  \stopMPpage
\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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to