51 lines
1.1 KiB
C++
51 lines
1.1 KiB
C++
#include "oboy.h"
|
|
|
|
#include <caml/mlvalues.h>
|
|
#include <caml/callback.h>
|
|
#include <caml/alloc.h>
|
|
#include <caml/misc.h>
|
|
#include <caml/osdeps.h>
|
|
|
|
OBoy::OBoy(QObject *parent) : QObject(parent)
|
|
{
|
|
|
|
}
|
|
|
|
QString OBoy::name() const
|
|
{
|
|
value * closure_f = caml_named_value("oboy_name");
|
|
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
|
|
{
|
|
value * closure_f = caml_named_value("oboy_version");
|
|
if (closure_f == nullptr) {
|
|
return QString("<Unreachable>");
|
|
}
|
|
|
|
const char *str = String_val(caml_callback(*closure_f, Val_unit));
|
|
return QString(str);
|
|
}
|
|
|
|
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;
|
|
}
|