Get the list of path coordinates from objects (mplib)

Maxime Chupin <[email protected]> Mon, 8 Jul 2019 13:51:52 +0200
Newsgroups gmane.comp.tex.metapost
Message-ID <CAJPNWxBQTKi5rZ-eF8yz5O=-cfhT_bgGYpMrHbO2bY_3L_dv0A@mail.gmail.com>
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 : [email protected]

--
http://tug.org/metapost/