I created a small example to learn how to do it.
Using cigloo I generated extern declaration and pasted
inside a bigloo module. Is there a way to include the
output of cigloo inside the module without copy/pasting?
Here is the content of main.scm:
(module foo
(extern
;; beginning of example.h
(create_abc::ABC* () "create_abc")
(sum::int (int int) "sum")
(type s-ABC_ (struct (value::int "value")
(sum::*int,int,string->int "sum")) "struct ABC_")
(type int,int,string->int "int ($(int,int,char *))")
(type *int,int,string->int (function int (int int string)) "int
((*$)(int,int,char *))")
(type ABC s-ABC_ "ABC")
(type ->ABC* "ABC *($())")
(type int,int->int "int ($(int,int))")
;; end of example.h
)
(main main))
(define (main x)
(let ((out (create_abc)))
(print "total:")
(print out)))
When I run the command: bigloo main.scm libexample.so -o main
I get the following error:
main.c:19:8: error: unknown type name ‘ABC’
extern ABC * create_abc();
What I am doing wrong?#include <stdlib.h>
#include <stdio.h>
#include "example.h"
int bar(int a, int b, char * message) {
printf("%s\n", message);
return a + b + 40;
}
ABC * create_abc() {
ABC * my_struct = malloc(sizeof(ABC));
my_struct->value = 42;
my_struct->sum = bar;
return my_struct;
}
int sum(int a, int b) {
return a + b;
}
typedef struct ABC_ {
int value;
int (*sum)(int a, int b, char * message);
} ABC;
ABC * create_abc();
int sum(int a, int b);