#include "oboy.h" #include #include #include #include #include #include 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(""); } 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(""); } 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(); ocaml_path = caml_copy_string_of_os(ba.data()); _loaded = Bool_val(caml_callback(*closure_f, ocaml_path)); this->loadedChanged(_loaded); CAMLdrop; return _loaded; } bool OBoy::loaded() const { return _loaded; }