-
Notifications
You must be signed in to change notification settings - Fork 4
/
julia_api.hpp
61 lines (44 loc) · 1.1 KB
/
julia_api.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef QML_JULIA_API_H
#define QML_JULIA_API_H
#include <vector>
#include <QJSValue>
#include <QQmlEngine>
#include <QQmlPropertyMap>
#include <QVariant>
#include "julia_function.hpp"
#include "julia_signals.hpp"
namespace qmlwrap
{
/// Global API, allowing to call Julia functions from QML
class JuliaAPI : public QQmlPropertyMap
{
Q_OBJECT
public:
JuliaSignals* juliaSignals() const
{
return m_julia_signals;
}
void setJuliaSignals(JuliaSignals* julia_signals);
void set_js_engine(QJSEngine* e);
void register_function(const QString& name, jl_function_t* f);
~JuliaAPI();
private:
JuliaSignals* m_julia_signals = nullptr;
void register_function_internal(JuliaFunction* f);
QJSEngine* m_engine = nullptr;
std::vector<JuliaFunction*> m_registered_functions;
};
struct JuliaSingleton
{
Q_GADGET
QML_FOREIGN(JuliaAPI)
QML_SINGLETON
QML_NAMED_ELEMENT(Julia)
public:
inline static JuliaAPI *s_singletonInstance = nullptr;
static JuliaAPI* create(QQmlEngine *, QJSEngine *engine);
private:
inline static QJSEngine *s_engine = nullptr;
};
} // namespace qmlwrap
#endif