about summary refs log tree commit diff
path: root/guile-zig-local/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'guile-zig-local/test.c')
-rw-r--r--guile-zig-local/test.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/guile-zig-local/test.c b/guile-zig-local/test.c
new file mode 100644
index 0000000..c0d1809
--- /dev/null
+++ b/guile-zig-local/test.c
@@ -0,0 +1,36 @@
+// Testing guile bindings, see README.md and
+// https://www.gnu.org/savannah-checkouts/gnu/guile/docs/docs-2.0/guile-ref/Dynamic-Types.html
+
+#include <stdio.h>
+#include <libguile.h>
+#include <libguile/boolean.h>
+#include <libguile/numbers.h>
+
+extern void hello_zig();
+
+extern SCM my_incrementing_zig_function (SCM a, SCM flag);
+
+SCM my_incrementing_function (SCM a, SCM flag)
+{
+  SCM result;
+
+  if (scm_is_true (flag))
+    result = scm_sum (a, scm_from_int (1));
+  else
+    result = a;
+
+  return result;
+}
+
+
+int main() {
+    hello_zig();
+    SCM test =  scm_from_int(3);
+    SCM b = scm_from_bool(1);
+    SCM result = my_incrementing_function(test,b);
+    printf(" from %d to %d\n",scm_to_int(test),scm_to_int(result));
+    hello_zig();
+    SCM result2 = my_incrementing_zig_function(result,b);
+    printf(" from %d to %d\n",scm_to_int(result),scm_to_int(result2));
+    return 0;
+}