Mercurial > pub > dyncall > dyncall
annotate test/call_suite/mk-cases.lua @ 506:ed7d1f5e7973
- test cases: cosmetics for consistency
author | Tassilo Philipp |
---|---|
date | Sat, 09 Apr 2022 13:57:27 +0200 |
parents | f263eb7a206e |
children | a0c51f34023a |
rev | line source |
---|---|
0 | 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) | |
496
da5232da6270
- test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents:
430
diff
changeset
|
8 local h = { "/* ",id,":",sig," */ ",sig:sub(-1), " f", id,"(","" } |
430 | 9 local t = { "" } |
0 | 10 local pos = 0 |
496
da5232da6270
- test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents:
430
diff
changeset
|
11 maxargs = max(maxargs, #sig-2) |
da5232da6270
- test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents:
430
diff
changeset
|
12 for i = 1, #sig-2 do |
da5232da6270
- test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents:
430
diff
changeset
|
13 pos = tostring(i) |
0 | 14 local name = "a"..pos |
15 local ch = sig:sub(i,i) | |
430 | 16 h[#h+1] = ch.." "..name |
0 | 17 h[#h+1] = "," |
430 | 18 t[#t+1] = "V_"..ch.."["..pos.."]="..name..";" |
0 | 19 end |
20 h[#h] = "){" | |
496
da5232da6270
- test code: rand-sig now spitting out dyncallish sigs (with ')' end delim and rettype at end), purely for consistency
Tassilo Philipp
parents:
430
diff
changeset
|
21 t[#t+1] = "ret_"..sig:sub(-1).."("..pos..")}\n" |
0 | 22 return table.concat(h,"")..table.concat(t,"") |
23 end | |
24 | |
25 function mkfuntab(n) | |
26 local s = { "funptr G_funtab[] = {\n"} | |
430 | 27 for i = 0, n-1 do |
0 | 28 s[#s+1] = "\t(funptr)&f"..i..",\n" |
29 end | |
30 s[#s+1] = "};\n" | |
31 return table.concat(s,"") | |
32 end | |
33 | |
34 function mksigtab(sigs) | |
506 | 35 local s = { "const char * G_sigtab[] = {\n"} |
0 | 36 for k,v in pairs(sigs) do |
504
f263eb7a206e
- call_suite: made output more consistent with dyncall sig style
Tassilo Philipp
parents:
496
diff
changeset
|
37 s[#s+1] = '\t"'..v..'",\n' |
0 | 38 end |
39 s[#s+1] = "};\n" | |
40 return table.concat(s,"") | |
41 end | |
42 | |
43 function mkall() | |
430 | 44 local lineno = 0 |
0 | 45 local sigtab = { } |
46 for line in io.lines() do | |
47 local sig = trim(line) | |
48 io.write(mkcase(lineno,sig)) | |
49 sigtab[#sigtab+1] = sig | |
50 lineno = lineno + 1 | |
51 end | |
430 | 52 io.write(mkfuntab(lineno)) |
0 | 53 io.write(mksigtab(sigtab)) |
54 io.write("int G_maxargs = "..maxargs..";\n") | |
55 end | |
56 | |
57 mkall() | |
58 |