fix for OS X (default ALLOC_RETURN_TYPE to void)
[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 true then 
8    mpx = mplib.new({ini_version = true})
9    vv = mpx:execute("plain ");
10    v = mpx:execute("dump;");
11    vvv= mpx:finish();
12    print (tostring(vv.term) .. ' ' .. tostring(v.term) .. ' ' .. tostring(vvv.term))
13    print (tostring(vv.log) ..  ' ' .. tostring(v.log) .. ' ' .. tostring(vvv.log))
14    print (tostring(vv.error) ..  ' ' .. tostring(v.error) .. ' ' .. tostring(vvv.error))
15    mpx = nil;
16 end
17
18 dofile("/opt/tex/texmf-local/tex/context/base/l-table.lua");
19
20 function dorun (m, s) 
21   local v = m:execute(s)
22 --  print ('<<term:'..v.term..'>>')
23   if v.log then
24     print ('<<log:'..v.log..'>>')
25   end
26   if true and v.fig then
27      for _,gs in ipairs(v.fig) do
28       print(gs:postscript())
29            local b = gs:objects()
30        for _,vv in ipairs(b) do
31                   l = vv.path
32                   -- print(vv, vv.type)
33           if vv.type == "text" then
34                     print(vv.text, vv.font, vv.dsize, table.serialize(vv.transform))
35           end
36        end
37      end
38   end
39 end
40
41 -- chunks have to have 'complete file' nesting state
42 local lines = {
43  "\\",
44  "prologues:=1;",
45  "path p,q;",
46  "p = (0,0){right}..(20,100)..(50,60)..(75,50)...(25,25)..cycle;",
47  "q = (0,0){right}..(20,100)..(50,60)..(75,50)...(25,25);",
48  "pickup pencircle scaled 2;",
49  "beginfig(1); fill p withcolor (1,0,0); draw p dashed evenly; endfig;",
50 -- [[for i=1 upto 1000 : beginfig(1);  for k:=1 upto 10 : draw fullcircle scaled (uniformdeviate(10mm)) ;endfor; endfig ;    endfor ;]],
51  [[beginfig(2); fill p withcolor (1,0,1); endfig;\r
52    beginfig(3); draw q withcolor (0,1,1); endfig;]],
53  "beginfig(4); label(\"stuff\", (0,0)); endfig;",
54  "beginfig(5); draw fullcircle scaled 100 withpen pencircle xscaled 20 yscaled 10 rotated 30 ; endfig;",
55 }
56
57 function finder (a,b,c)
58    print(a,b,c)
59    if a == "mpost.map" then
60      return "/opt/tex/texmf-local/fonts/map/pdftex/pdftex.map"
61    end
62    if a =="cmr10.tfm" then
63      return "/opt/tex/texmf/fonts/tfm/public/cm/cmr10.tfm"
64    end
65    return a
66 end
67
68 mpx = mplib.new({mem_name = "plain.mem", 
69               command_line = "\\relax ", 
70               find_file = finder})
71
72 for _,l in ipairs(lines) do
73    dorun (mpx, l)
74 end
75
76 v = mpx:finish();
77