Use Caml macros for variables
This commit is contained in:
parent
d197159f5a
commit
f0cab3f1c6
|
@ -3,6 +3,7 @@
|
|||
#include <caml/mlvalues.h>
|
||||
#include <caml/callback.h>
|
||||
#include <caml/alloc.h>
|
||||
#include <caml/memory.h>
|
||||
#include <caml/misc.h>
|
||||
#include <caml/osdeps.h>
|
||||
|
||||
|
@ -11,40 +12,57 @@ OBoy::OBoy(QObject *parent) : QObject(parent)
|
|||
|
||||
}
|
||||
|
||||
// https://caml.inria.fr/pub/docs/manual-ocaml/intfc.html
|
||||
// http://www.mega-nerd.com/erikd/Blog/CodeHacking/Ocaml/calling_ocaml.html
|
||||
|
||||
QString OBoy::name() const
|
||||
{
|
||||
CAMLparam0();
|
||||
|
||||
value * closure_f = caml_named_value("oboy_name");
|
||||
if (closure_f == nullptr) {
|
||||
CAMLdrop;
|
||||
return QString("<Unreachable>");
|
||||
}
|
||||
|
||||
const char *str = String_val(caml_callback(*closure_f, Val_unit));
|
||||
CAMLdrop;
|
||||
return QString(str);
|
||||
}
|
||||
|
||||
QString OBoy::version() const
|
||||
{
|
||||
CAMLparam0();
|
||||
|
||||
value * closure_f = caml_named_value("oboy_version");
|
||||
if (closure_f == nullptr) {
|
||||
CAMLdrop;
|
||||
return QString("<Unreachable>");
|
||||
}
|
||||
|
||||
const char *str = String_val(caml_callback(*closure_f, Val_unit));
|
||||
CAMLdrop;
|
||||
return QString(str);
|
||||
}
|
||||
|
||||
bool OBoy::load(const QString &path)
|
||||
{
|
||||
CAMLparam0();
|
||||
CAMLlocal1(ocaml_path) ;
|
||||
|
||||
value * closure_f = caml_named_value("oboy_load");
|
||||
if (closure_f == nullptr) {
|
||||
CAMLdrop;
|
||||
return false;
|
||||
}
|
||||
|
||||
QString truncated(path);
|
||||
truncated.remove(0, 7); // remove file://
|
||||
QByteArray ba = truncated.toLocal8Bit();
|
||||
value ocaml_path = caml_copy_string_of_os(ba.data());
|
||||
|
||||
ocaml_path = caml_copy_string_of_os(ba.data());
|
||||
|
||||
const bool success = Bool_val(caml_callback(*closure_f, ocaml_path));
|
||||
CAMLdrop;
|
||||
return success;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue