Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Ocaml code:
- type foo = Bar of int;;
- Callback.register "test-cb" (fun (x : int) -> Bar x);;
- external do_test : int -> foo = "do_test";;
- let _ = match do_test 4 with
- Bar x -> print_endline "success!";;
- */
- // c code
- #include<mlvalues.h>
- #include<memory.h>
- #include<assert.h>
- CAMLprim value do_test(value foo) {
- CAMLparam1(foo);
- CAMLlocal1(ret);
- assert(Is_long(foo));
- value *cb = caml_named_value("test-cb");
- ret = caml_callback(*cb, foo);
- printf("%u\n", Tag_val(ret));
- CAMLreturn(ret);
- }
Advertisement
Add Comment
Please, Sign In to add comment