514
|
1 function trim(s)
|
|
2 return s:gsub("^%s+",""):gsub("%s+$","")
|
|
3 end
|
|
4
|
519
|
5 -- parse array notation, e.g. returns "a", 4 for "a[4]"
|
|
6 function split_array_decl(s)
|
|
7 local name = s
|
|
8 local n = nil -- not an array
|
|
9 local i = s:find('%[')
|
|
10 if i ~= nil then
|
|
11 name = name:sub(1, i-1)
|
|
12 n = tonumber(s:sub(i):match('[0123456789]+'))
|
|
13 end
|
|
14 return name, n
|
|
15 end
|
|
16
|
512
|
17 function mkfuntab(n, prefix, t, array_name, with_cast)
|
|
18 local s = { t.." "..array_name.."[] = {\n"}
|
|
19 local cast = ''
|
|
20 if with_cast == true then
|
|
21 cast = '('..t..')'
|
|
22 end
|
|
23 for i = 0, n-1 do
|
|
24 s[#s+1] = "\t"..cast.."&"..prefix..i..",\n"
|
|
25 end
|
|
26 s[#s+1] = "};\n"
|
|
27 return table.concat(s,"")
|
|
28 end
|
|
29
|
|
30 -- @@@ sigprefix should be added by generators, not here
|
|
31 function mksigtab(sigs, sigprefix, array_name)
|
|
32 local s = { "const char * "..array_name.."[] = {\n"}
|
|
33 for k,v in pairs(sigs) do
|
|
34 s[#s+1] = '\t"'..sigprefix..v..'",\n'
|
|
35 end
|
|
36 s[#s+1] = "};\n"
|
|
37 return table.concat(s,"")
|
|
38 end
|
|
39
|