summaryrefslogtreecommitdiff
path: root/util/test.lua
diff options
context:
space:
mode:
Diffstat (limited to 'util/test.lua')
-rw-r--r--util/test.lua40
1 files changed, 40 insertions, 0 deletions
diff --git a/util/test.lua b/util/test.lua
new file mode 100644
index 0000000..9b9fc49
--- /dev/null
+++ b/util/test.lua
@@ -0,0 +1,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)