Mercurial > pub > dyncall > dyncall
comparison test/call_suite/mk-cases.lua @ 0:3e629dc19168
initial from svn dyncall-1745
author | Daniel Adler |
---|---|
date | Thu, 19 Mar 2015 22:24:28 +0100 |
parents | |
children | 8e22b70d3ee4 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3e629dc19168 |
---|---|
1 require"math" | |
2 local max = math.max | |
3 local maxargs = 0 | |
4 | |
5 function trim(l) return l:gsub("^%s+",""):gsub("%s+$","") end | |
6 function mkcase(id,sig) | |
7 local sig = trim(sig) | |
8 local h = { "/* ",id,":",sig," */ ",sig:sub(1,1), " f", id,"(",""} | |
9 local t = { "fid=",id,";" } | |
10 local pos = 0 | |
11 maxargs = max(maxargs, #sig-1) | |
12 for i = 2, #sig do | |
13 pos = tostring(i-1) | |
14 local name = "a"..pos | |
15 local ch = sig:sub(i,i) | |
16 | |
17 h[#h+1] = ch | |
18 h[#h+1] = " " | |
19 h[#h+1] = name | |
20 h[#h+1] = "," | |
21 | |
22 t[#t+1] = "V_" | |
23 t[#t+1] = ch | |
24 t[#t+1] = "[" | |
25 t[#t+1] = pos | |
26 t[#t+1] = "]" | |
27 t[#t+1] = "=" | |
28 t[#t+1] = name | |
29 t[#t+1] = ";" | |
30 end | |
31 h[#h] = "){" | |
32 t[#t+1] = "ret_" | |
33 t[#t+1] = sig:sub(1,1) | |
34 t[#t+1] = "(" | |
35 t[#t+1] = pos | |
36 t[#t+1] = ")" | |
37 t[#t+1] = "}\n" | |
38 return table.concat(h,"")..table.concat(t,"") | |
39 end | |
40 | |
41 function mkfuntab(n) | |
42 local s = { "funptr G_funtab[] = {\n"} | |
43 for i = 1, n do | |
44 s[#s+1] = "\t(funptr)&f"..i..",\n" | |
45 end | |
46 s[#s+1] = "};\n" | |
47 return table.concat(s,"") | |
48 end | |
49 | |
50 function mksigtab(sigs) | |
51 local s = { "char const * G_sigtab[] = {\n"} | |
52 for k,v in pairs(sigs) do | |
53 s[#s+1] = '\t"' | |
54 s[#s+1] = v | |
55 s[#s+1] = '",\n' | |
56 end | |
57 s[#s+1] = "};\n" | |
58 return table.concat(s,"") | |
59 end | |
60 | |
61 function mkall() | |
62 local lineno = 1 | |
63 local sigtab = { } | |
64 for line in io.lines() do | |
65 local sig = trim(line) | |
66 io.write(mkcase(lineno,sig)) | |
67 sigtab[#sigtab+1] = sig | |
68 lineno = lineno + 1 | |
69 end | |
70 io.write(mkfuntab(lineno-1)) | |
71 io.write(mksigtab(sigtab)) | |
72 io.write("int G_maxargs = "..maxargs..";\n") | |
73 end | |
74 | |
75 mkall() | |
76 -- print(mkcase(1,"vififififi")) | |
77 |