support multiple fig returns from one chunk
[mplib] / src / texk / web2c / mpdir / tests / test.lua
1
2 -- There are two interfaces:
3 -- new * run
4 -- or
5 -- new * execute^1 * finish
6
7 if false then 
8   mpx = mp.new({ini_version = true, command_line = "plain \\dump"})
9   print (mpx:run());
10   mpx = nil;
11 end
12
13 function finder (a,b,c)
14    print(a,b,c)
15    if a == "mpost.map" then
16      return "/opt/tex/texmf-local/fonts/map/pdftex/pdftex.map"
17    end
18    if a =="cmr10.tfm" then
19      return "/opt/tex/texmf/fonts/tfm/public/cm/cmr10.tfm"
20    end
21    return a
22 end
23
24 -- if you don't do this, it only finds local files
25 mp.find_file_function (finder)
26
27 function dorun (m, s) 
28   local v = m:execute(s)
29 --  print ('<<term:'..v.term..'>>')
30   print ('<<log:'..v.log..'>>')
31   if v.fig then
32      for _,gs in ipairs(v.fig) do
33        print(gs:postscript())
34      end
35   end
36 end
37
38 -- chunks have to have 'complete file' nesting state
39 local lines = {
40  "prologues:=3;",
41  "path p;",
42  "p = (0,0){right}..(20,100)..(50,60)..(75,50)...(25,25)..cycle;",
43  "pickup pencircle scaled 2;",
44  "beginfig(1); fill p withcolor (1,0,0); draw p dashed evenly; endfig;",
45  "beginfig(2); fill p withcolor (0,1,0); draw p dashed evenly; endfig;",
46  "beginfig(3); fill p withcolor (0,0,1); draw p dashed evenly; endfig;",
47  "beginfig(4); fill p withcolor (1,1,0); draw p dashed evenly; endfig;",
48  [[beginfig(5); fill p withcolor (1,0,1); draw p dashed evenly; endfig; 
49    beginfig(6); fill p withcolor (0,1,1); draw p dashed evenly; endfig;]],
50  "beginfig(7); label(\"stuff\", (0,0)); endfig;",
51 }
52
53 mpx = mp.new({mem_name = "plain.mem", command_line = "\\relax "})
54
55 for _,l in ipairs(lines) do
56    dorun (mpx, l)
57 end
58
59 v = mpx:finish();
60