summaryrefslogtreecommitdiff
path: root/util/bind.lua
blob: 16ef3819bacf643f9023c7a1bcf83e0495d8234d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/lua5.1

local b = require 'generate-binding'


if arg[1] == "-f" then
	local signatures = {}
	local f = io.open(arg[2])
	for line in f:lines() do
		if string.match(line, "[^%s]") then
			table.insert(signatures, line)
		end
	end
	f:close()

	f = io.open(arg[2] .. ".bind", "w")
	for _, sig in ipairs(signatures) do
		local success, binding = pcall(b.bind, sig)
		if success == false then
			print(
				string.format(
					"bind signature \"%s\" failed: %s", sig, binding
				)
			)
		else
			f:write(b.bind(sig))
			f:write("\n\n\n")
		end
	end
	f:close()
else
	print(b.bind(arg[1]))
end