summaryrefslogtreecommitdiff
path: root/util/test.lua
blob: 9b9fc49e336dbcf8815d9a4a39573606f138075b (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
34
35
36
37
38
39
40
function test(description, func)
	io.write(description .. ': ')
	local result, msg = pcall(func)
	if result == true then
		print("OK")
	else
		print("FAIL")
		print(debug.traceback(msg))
		print()
	end
end


local b = require 'generate-binding'


test("simplest possible binding", function()
	local binding = b.bind("void some_function();")
	assert(binding == [[
int some_function_bind(lua_State *L)
{
	some_function();
	return 0;
}]])
end)


test("complicated binding", function()
	local binding = b.bind("const char * qqq(int a, float q, unsigned char m);")
	assert(binding == [[
int qqq_bind(lua_State *L)
{
	lua_Integer a = luaL_checkinteger(L, 1);
	lua_Number q = luaL_checknumber(L, 2);
	lua_Integer m = luaL_checkinteger(L, 3);
	const char *result = qqq(a, q, m);
	lua_pushstring(L, result);
	return 1;
}]])
end)