2019-05-11 20:00:33 +02:00
|
|
|
#include "oboy.h"
|
|
|
|
|
2019-05-11 21:13:09 +02:00
|
|
|
#include <caml/mlvalues.h>
|
|
|
|
#include <caml/callback.h>
|
2019-05-15 14:03:53 +02:00
|
|
|
#include <caml/alloc.h>
|
|
|
|
#include <caml/misc.h>
|
|
|
|
#include <caml/osdeps.h>
|
2019-05-11 21:13:09 +02:00
|
|
|
|
2019-05-11 20:00:33 +02:00
|
|
|
OBoy::OBoy(QObject *parent) : QObject(parent)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2019-05-11 21:13:09 +02:00
|
|
|
|
|
|
|
QString OBoy::name() const
|
|
|
|
{
|
2019-05-14 13:54:17 +02:00
|
|
|
value * closure_f = caml_named_value("oboy_name");
|
2019-05-11 21:13:09 +02:00
|
|
|
if (closure_f == nullptr) {
|
|
|
|
return QString("<Unreachable>");
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *str = String_val(caml_callback(*closure_f, Val_unit));
|
|
|
|
return QString(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString OBoy::version() const
|
|
|
|
{
|
2019-05-14 13:54:17 +02:00
|
|
|
value * closure_f = caml_named_value("oboy_version");
|
2019-05-11 21:13:09 +02:00
|
|
|
if (closure_f == nullptr) {
|
|
|
|
return QString("<Unreachable>");
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *str = String_val(caml_callback(*closure_f, Val_unit));
|
|
|
|
return QString(str);
|
|
|
|
}
|
2019-05-15 14:03:53 +02:00
|
|
|
|
|
|
|
bool OBoy::load(const QString &path)
|
|
|
|
{
|
|
|
|
value * closure_f = caml_named_value("oboy_load");
|
|
|
|
if (closure_f == nullptr) {
|
|
|
|
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());
|
|
|
|
|
|
|
|
const bool success = Bool_val(caml_callback(*closure_f, ocaml_path));
|
|
|
|
return success;
|
|
|
|
}
|