[metapost] Get the list of path coordinates from objects (mplib)

Maxime Chupin notezik at gmail.com
Mon Jul 8 13:51:52 CEST 2019


Hi again (sorry),

I want to get the list of coordinates of points of a path but in the lua
side.
I managed to get the objects list, and the outline part and the path of the
outline part... but whereas I get the right size of the path (here 3
points), each knots is a nil value. See my code.

Thanks in advance.

local mpkpse = kpse.new('luatex', 'mpost')

local function finder(name, mode, ftype)
   if mode == "w" then
  return name
   else
  return mpkpse:find_file(name,ftype)
   end
end

function getpathfrommp(s)
   local mp = mplib.new({
         find_file = finder,})
   mp:execute('input plain ;')
   local rettable
   rettable = mp:execute('beginfig(1); path p; p:=
(0,0)--(2cm,2cm)--(1cm,0); draw p; endfig;end;')
   print("\nstatus: ".. rettable.status)
   print(rettable.log)
   if rettable.status == 0 then
      figures = rettable.fig
      figure = figures[1]
      print(figure:filename())
      local objects = figure:objects()
      print(#objects)
      local segment = objects[1]
      print(segment.type)
      print(#segment.path)
      print(#segment.path[1])
   end
end

-- 
Maxime Chupin
Site personnel : http://fougeriens.org/~mc/
Site professionnel : https://www.ceremade.dauphine.fr/~chupin/
<http://www.ceremade.dauphine.fr/~chupin/>
adresse libre : chupin at fougeriens.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://tug.org/pipermail/metapost/attachments/20190708/2d8b879f/attachment.html>


More information about the metapost mailing list