Last active
September 13, 2021 04:25
-
-
Save melwyn95/bae19fb06352497399178d3bad9fdc68 to your computer and use it in GitHub Desktop.
OCaml C stubs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <caml/mlvalues.h> | |
#include <caml/memory.h> | |
#include <caml/alloc.h> | |
// Reference: http://decapode314.free.fr/ocaml/ocaml-wrapping-c.html | |
// Reference: https://ocaml.org/manual/intfc.html | |
// This stub return a (int,string) result | |
value esy_test_result(value unit) { | |
CAMLparam1( unit ); | |
CAMLlocal1( result ); | |
// Ok 42 | |
result = caml_alloc(1, 0); | |
Store_field( result, 0, Val_int(42) ); | |
// Error "the walking camel" | |
// result = caml_alloc(1, 1); | |
// char *s = "the walking camel"; | |
// Store_field( result, 0, caml_copy_string(s) ); | |
CAMLreturn(result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment