75 lines
1.5 KiB
C++
75 lines
1.5 KiB
C++
#include "oboy.h"
|
|
|
|
#include <caml/mlvalues.h>
|
|
#include <caml/callback.h>
|
|
#include <caml/alloc.h>
|
|
#include <caml/memory.h>
|
|
#include <caml/misc.h>
|
|
#include <caml/osdeps.h>
|
|
|
|
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();
|
|
|
|
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;
|
|
}
|