Mercurial > pub > dyncall > dyncall
comparison test/callback_suite/mk-cases.lua @ 507:5a3c07a0f376
cleanups
author | Tassilo Philipp |
---|---|
date | Sat, 09 Apr 2022 14:00:59 +0200 |
parents | 049e04af13c8 |
children | f3d44195dbdf |
comparison
equal
deleted
inserted
replaced
506:ed7d1f5e7973 | 507:5a3c07a0f376 |
---|---|
1 require "config" | 1 require "config" |
2 | 2 |
3 function trim(l) return l:gsub("^%s+",""):gsub("%s+$","") end | 3 function trim(l) return l:gsub("^%s+",""):gsub("%s+$","") end |
4 function mkcase(id,sig) | 4 function mkcase(id,sig) |
5 local nargs = string.len(sig) - 2 -- @@@STRUCT wrong, b/c ignores callconv prefixes | 5 local nargs = string.len(sig) - 2 |
6 local rtype = string.sub(sig, nargs + 2, nargs + 2) | 6 local rtype = string.sub(sig, nargs + 2, nargs + 2) |
7 local s = "F" .. nargs .. "(f" .. id .. "," .. rtype | 7 local s = "F" .. nargs .. "(f" .. id .. "," .. rtype |
8 for i = 1, nargs do | 8 for i = 1, nargs do |
9 local type = string.sub(sig, i, i) | 9 local type = string.sub(sig, i, i) |
10 s = s .. "," .. type | 10 s = s .. "," .. type |
11 end | 11 end |
12 s = s .. ")\n" | 12 s = s .. ")\n" |
13 return s | 13 return s |
14 end | 14 end |
15 | 15 |
16 -- @@@STRUCT same as in call_suite{,_aggrs}, share? | |
17 function mkfuntab(n) | 16 function mkfuntab(n) |
18 local s = { "funptr G_funtab[] = {\n"} | 17 local s = { "funptr G_funtab[] = {\n"} |
19 for i = 0, n-1 do | 18 for i = 0, n-1 do |
20 s[#s+1] = "\t&f"..i..",\n" | 19 s[#s+1] = "\t&f"..i..",\n" |
21 end | 20 end |
22 s[#s+1] = "};\n" | 21 s[#s+1] = "};\n" |
23 return table.concat(s,"") | 22 return table.concat(s,"") |
24 end | 23 end |
25 | 24 |
26 -- @@@STRUCT same as in call_suite{,_aggrs}, share? | |
27 function mksigtab(sigs) | 25 function mksigtab(sigs) |
28 local s = { "const char * G_sigtab[] = {\n"} | 26 local s = { "const char * G_sigtab[] = {\n"} |
29 for k,v in pairs(sigs) do | 27 for k,v in pairs(sigs) do |
30 s[#s+1] = '\t"'..v..'",\n' | 28 s[#s+1] = '\t"'..v..'",\n' |
31 end | 29 end |
32 s[#s+1] = "};\n" | 30 s[#s+1] = "};\n" |
33 return table.concat(s,"") | 31 return table.concat(s,"") |
34 end | 32 end |
35 | 33 |
36 function mkall() | 34 function mkall() |
37 -- force minargs for ordered mode @@@STRUCT why? | 35 -- force minargs for ordered mode |
38 if mode == "ordered" then | 36 if mode == "ordered" then |
39 minargs = 0 | 37 minargs = 0 |
40 end | 38 end |
41 | 39 |
42 -- case macros | 40 -- case macros |