make the lua frontend reentrant as well
[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                   print(vv, vv.type, table.serialize(vv.path), table.serialize(vv.color))
32           if vv.type == "text" then
33                     print(vv.text, vv.font, vv.dsize, table.serialize(vv.transform))
34           end
35        end
36      end
37   end
38 end
39
40 -- chunks have to have 'complete file' nesting state
41 local lines = {
42  "\\",
43  "prologues:=3;",
44  "path p,q;",
45  "p = (0,0){right}..(20,100)..(50,60)..(75,50)...(25,25)..cycle;",
46  "q = (0,0){right}..(20,100)..(50,60)..(75,50)...(25,25);",
47  "pickup pencircle scaled 2;",
48  "beginfig(1); fill p withcolor (1,0,0); draw p dashed evenly; endfig;",
49  [[beginfig(2); fill p withcolor (1,0,1); endfig; 
50    beginfig(3); draw q withcolor (0,1,1); endfig;]],
51  "beginfig(4); label(\"stuff\", (0,0)); endfig;",
52 }
53
54 function finder (a,b,c)
55    print(a,b,c)
56    if a == "mpost.map" then
57      return "/opt/tex/texmf-local/fonts/map/pdftex/pdftex.map"
58    end
59    if a =="cmr10.tfm" then
60      return "/opt/tex/texmf/fonts/tfm/public/cm/cmr10.tfm"
61    end
62    return a
63 end
64
65 mpx = mplib.new({mem_name = "plain.mem", 
66               command_line = "\\relax ", 
67               find_file = finder})
68
69 for _,l in ipairs(lines) do
70    dorun (mpx, l)
71 end
72
73 v = mpx:finish();
74