qml 0.0.7 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +3 -0
- data/.travis.yml +5 -9
- data/LICENSE.txt +1 -1
- data/README.md +84 -114
- data/changes.md +5 -0
- data/examples/fizzbuzz/fizzbuzz.rb +3 -4
- data/examples/todo_array/todo_array.rb +4 -4
- data/examples/todo_sequel/todo_sequel.rb +7 -7
- data/examples/twitter/twitter.rb +5 -3
- data/ext/qml/application.c +88 -0
- data/ext/qml/application.h +9 -0
- data/ext/qml/component.c +89 -0
- data/ext/qml/component.h +10 -0
- data/ext/qml/conversion.c +60 -0
- data/ext/qml/conversion.h +8 -0
- data/ext/qml/dispatcher.c +31 -0
- data/ext/qml/dispatcher.h +7 -0
- data/ext/qml/engine.c +135 -0
- data/ext/qml/engine.h +10 -0
- data/ext/qml/exporter.c +93 -0
- data/ext/qml/exporter.h +7 -0
- data/ext/qml/extconf.rb +38 -97
- data/ext/qml/interface.c +156 -0
- data/ext/qml/interface.h +11 -0
- data/ext/qml/js_array.c +47 -0
- data/ext/qml/js_array.h +7 -0
- data/ext/qml/js_function.c +109 -0
- data/ext/qml/js_function.h +7 -0
- data/ext/qml/js_object.c +284 -0
- data/ext/qml/js_object.h +19 -0
- data/ext/qml/js_wrapper.c +19 -0
- data/ext/qml/js_wrapper.h +7 -0
- data/ext/qml/lib/libqmlbind/.gitignore +38 -0
- data/ext/qml/lib/libqmlbind/.gitmodules +3 -0
- data/ext/qml/lib/libqmlbind/.travis.yml +14 -0
- data/ext/qml/lib/libqmlbind/LICENSE.txt +22 -0
- data/ext/qml/lib/libqmlbind/libqmlbind.pro +3 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind.h +14 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/application.h +18 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/component.h +21 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/engine.h +34 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/exporter.h +37 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/interface.h +16 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/iterator.h +19 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/metaobject.h +13 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/plugin.h +17 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/qmlbind_global.h +78 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/register.h +17 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/signal_emitter.h +15 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/string.h +15 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/value.h +100 -0
- data/ext/qml/lib/libqmlbind/qmlbind/qmlbind.pro +62 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_application.cpp +103 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_component.cpp +54 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_engine.cpp +65 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_exporter.cpp +52 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_interface.cpp +19 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_iterator.cpp +32 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_metaobject.cpp +19 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_plugin.cpp +27 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_register.cpp +17 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_signal_emitter.cpp +27 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_string.cpp +22 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_value.cpp +215 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/backref.cpp +54 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/backref.h +29 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/engine.cpp +32 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/engine.h +27 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/exporter.cpp +73 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/exporter.h +46 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/interface.cpp +75 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/interface.h +37 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/metaobject.cpp +101 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/metaobject.h +29 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/signalemitter.cpp +33 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/signalemitter.h +25 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/ticktimer.cpp +15 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/ticktimer.h +19 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/typeregisterer.cpp +112 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/typeregisterer.h +28 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/util.h +13 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/wrapper.cpp +23 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/wrapper.h +29 -0
- data/ext/qml/lib/libqmlbind/readme.md +14 -0
- data/ext/qml/lib/libqmlbind/test/api.c +1 -0
- data/ext/qml/lib/libqmlbind/test/application_test.cpp +16 -0
- data/ext/qml/lib/libqmlbind/test/component_test.cpp +57 -0
- data/ext/qml/lib/libqmlbind/test/engine_test.cpp +94 -0
- data/ext/qml/lib/libqmlbind/test/exporter_test.cpp +312 -0
- data/ext/qml/lib/libqmlbind/test/fixtures/emptyhandlers.cpp +36 -0
- data/ext/qml/lib/libqmlbind/test/fixtures/emptyhandlers.h +6 -0
- data/ext/qml/lib/libqmlbind/test/fixtures/test.qml +5 -0
- data/ext/qml/lib/libqmlbind/test/fixtures/testmodule/qmldir +2 -0
- data/ext/qml/lib/libqmlbind/test/fixtures/testmodule/test.qml +5 -0
- data/ext/qml/lib/libqmlbind/test/iterator_test.cpp +37 -0
- data/ext/qml/lib/libqmlbind/test/main.cpp +11 -0
- data/ext/qml/lib/libqmlbind/test/plugin_test.cpp +41 -0
- data/ext/qml/lib/libqmlbind/test/test.pro +26 -0
- data/ext/qml/lib/libqmlbind/test/test_helper.h +20 -0
- data/ext/qml/lib/libqmlbind/test/value_test.cpp +252 -0
- data/ext/qml/lib/libqmlbind/testplugin/testplugin.cpp +11 -0
- data/ext/qml/lib/libqmlbind/testplugin/testplugin.h +21 -0
- data/ext/qml/lib/libqmlbind/testplugin/testplugin.json +3 -0
- data/ext/qml/lib/libqmlbind/testplugin/testplugin.pro +21 -0
- data/ext/qml/meta_object.c +81 -0
- data/ext/qml/meta_object.h +8 -0
- data/ext/qml/plugin_loader.c +71 -0
- data/ext/qml/plugin_loader.h +7 -0
- data/ext/qml/qml.c +95 -0
- data/ext/qml/qml.h +10 -0
- data/ext/qml/rubyqml-plugin/listmodel.cpp +102 -0
- data/ext/qml/rubyqml-plugin/listmodel.h +37 -0
- data/ext/qml/rubyqml-plugin/rubyqml-plugin.pro +19 -0
- data/ext/qml/rubyqml-plugin/rubyqmlplugin.cpp +25 -0
- data/ext/qml/rubyqml-plugin/rubyqmlplugin.h +19 -0
- data/ext/qml/signal_emitter.c +71 -0
- data/ext/qml/signal_emitter.h +9 -0
- data/lib/qml.rb +11 -10
- data/lib/qml/access.rb +64 -86
- data/lib/qml/application.rb +20 -71
- data/lib/qml/component.rb +41 -33
- data/lib/qml/core_ext.rb +1 -0
- data/lib/qml/core_ext/to_qml.rb +70 -0
- data/lib/qml/data.rb +1 -0
- data/lib/qml/data/array_model.rb +99 -101
- data/lib/qml/data/list_model.rb +107 -131
- data/lib/qml/data/list_model_access.rb +44 -0
- data/lib/qml/data/query_model.rb +45 -47
- data/lib/qml/dispatcher.rb +5 -13
- data/lib/qml/engine.rb +9 -58
- data/lib/qml/errors.rb +0 -21
- data/lib/qml/interface.rb +21 -0
- data/lib/qml/js_array.rb +8 -0
- data/lib/qml/js_object.rb +69 -0
- data/lib/qml/js_util.rb +18 -0
- data/lib/qml/plugin_loader.rb +1 -13
- data/lib/qml/plugins.rb +3 -17
- data/lib/qml/proc_access.rb +28 -0
- data/lib/qml/qt.rb +21 -3
- data/lib/qml/reactive.rb +147 -8
- data/lib/qml/signal.rb +67 -0
- data/lib/qml/version.rb +1 -1
- data/qml.gemspec +8 -2
- data/spec/qml/access_spec.rb +33 -120
- data/spec/qml/application_spec.rb +11 -24
- data/spec/qml/component_spec.rb +4 -4
- data/spec/qml/data/array_model_spec.rb +2 -2
- data/spec/qml/data/list_model_spec.rb +2 -2
- data/spec/qml/data/query_model_spec.rb +4 -4
- data/spec/qml/engine_spec.rb +23 -21
- data/spec/qml/interface_spec.rb +20 -0
- data/spec/qml/js_array_spec.rb +29 -0
- data/spec/qml/js_function_spec.rb +32 -0
- data/spec/qml/js_object_spec.rb +113 -0
- data/spec/qml/plugin_loader_spec.rb +9 -11
- data/spec/qml/qt_spec.rb +9 -0
- data/spec/qml/reactive_spec.rb +37 -0
- data/spec/qml/signal_connect_spec.rb +27 -0
- data/spec/qml/signal_spec.rb +73 -0
- data/spec/qml/to_qml_spec.rb +76 -0
- data/spec/shared/qml/access_example.rb +21 -0
- data/spec/shared/qml/data/list_model.rb +12 -13
- data/spec/spec_helper.rb +2 -3
- metadata +141 -166
- data/examples/imageprovider/imageprovider.rb +0 -57
- data/examples/imageprovider/main.qml +0 -51
- data/ext/qml/accessclass.cpp +0 -65
- data/ext/qml/accessclass.h +0 -19
- data/ext/qml/accessobject.cpp +0 -30
- data/ext/qml/accessobject.h +0 -22
- data/ext/qml/common.h +0 -18
- data/ext/qml/conversionerror.h +0 -14
- data/ext/qml/ext_accesswrapperfactory.cpp +0 -75
- data/ext/qml/ext_accesswrapperfactory.h +0 -39
- data/ext/qml/ext_anywrapper.cpp +0 -34
- data/ext/qml/ext_anywrapper.h +0 -23
- data/ext/qml/ext_kernel.cpp +0 -81
- data/ext/qml/ext_kernel.h +0 -9
- data/ext/qml/ext_metaobject.cpp +0 -399
- data/ext/qml/ext_metaobject.h +0 -60
- data/ext/qml/ext_pluginloader.cpp +0 -53
- data/ext/qml/ext_pluginloader.h +0 -30
- data/ext/qml/ext_pointer.cpp +0 -132
- data/ext/qml/ext_pointer.h +0 -41
- data/ext/qml/ext_testutil.cpp +0 -40
- data/ext/qml/ext_testutil.h +0 -9
- data/ext/qml/foreignclass.cpp +0 -72
- data/ext/qml/foreignclass.h +0 -88
- data/ext/qml/foreignmetaobject.cpp +0 -345
- data/ext/qml/foreignmetaobject.h +0 -46
- data/ext/qml/foreignobject.cpp +0 -22
- data/ext/qml/foreignobject.h +0 -21
- data/ext/qml/functioninfo.h +0 -16
- data/ext/qml/init.cpp +0 -67
- data/ext/qml/kernel.cpp +0 -39
- data/ext/qml/kernel.h +0 -32
- data/ext/qml/listmodel.cpp +0 -137
- data/ext/qml/listmodel.h +0 -45
- data/ext/qml/markable.h +0 -12
- data/ext/qml/objectdata.cpp +0 -26
- data/ext/qml/objectdata.h +0 -20
- data/ext/qml/objectgc.cpp +0 -69
- data/ext/qml/objectgc.h +0 -28
- data/ext/qml/plugins/core/applicationextension.cpp +0 -29
- data/ext/qml/plugins/core/applicationextension.h +0 -25
- data/ext/qml/plugins/core/componentextension.cpp +0 -41
- data/ext/qml/plugins/core/componentextension.h +0 -28
- data/ext/qml/plugins/core/contextextension.cpp +0 -39
- data/ext/qml/plugins/core/contextextension.h +0 -29
- data/ext/qml/plugins/core/core.pro +0 -29
- data/ext/qml/plugins/core/coreplugin.cpp +0 -87
- data/ext/qml/plugins/core/coreplugin.h +0 -49
- data/ext/qml/plugins/core/engineextension.cpp +0 -43
- data/ext/qml/plugins/core/engineextension.h +0 -31
- data/ext/qml/plugins/core/imageprovider.cpp +0 -38
- data/ext/qml/plugins/core/imageprovider.h +0 -18
- data/ext/qml/plugins/core/imagerequestpromise.cpp +0 -19
- data/ext/qml/plugins/core/imagerequestpromise.h +0 -21
- data/ext/qml/plugins/core/qmlexception.cpp +0 -11
- data/ext/qml/plugins/core/qmlexception.h +0 -17
- data/ext/qml/plugins/testutil/imageprovidertest.cpp +0 -40
- data/ext/qml/plugins/testutil/imageprovidertest.h +0 -17
- data/ext/qml/plugins/testutil/objectlifechecker.cpp +0 -17
- data/ext/qml/plugins/testutil/objectlifechecker.h +0 -24
- data/ext/qml/plugins/testutil/ownershiptest.cpp +0 -26
- data/ext/qml/plugins/testutil/ownershiptest.h +0 -30
- data/ext/qml/plugins/testutil/testobject.cpp +0 -6
- data/ext/qml/plugins/testutil/testobject.h +0 -108
- data/ext/qml/plugins/testutil/testobjectsubclass.cpp +0 -10
- data/ext/qml/plugins/testutil/testobjectsubclass.h +0 -19
- data/ext/qml/plugins/testutil/testutil.pro +0 -22
- data/ext/qml/plugins/testutil/testutilplugin.cpp +0 -55
- data/ext/qml/plugins/testutil/testutilplugin.h +0 -36
- data/ext/qml/qmltyperegisterer.cpp +0 -74
- data/ext/qml/qmltyperegisterer.h +0 -30
- data/ext/qml/rubyclass.cpp +0 -82
- data/ext/qml/rubyclass.h +0 -230
- data/ext/qml/rubyvalue.cpp +0 -656
- data/ext/qml/rubyvalue.h +0 -224
- data/ext/qml/signalforwarder.cpp +0 -64
- data/ext/qml/signalforwarder.h +0 -29
- data/ext/qml/util.cpp +0 -112
- data/ext/qml/util.h +0 -82
- data/ext/qml/valuereference.cpp +0 -50
- data/ext/qml/valuereference.h +0 -22
- data/ext/qml/weakvaluereference.cpp +0 -51
- data/ext/qml/weakvaluereference.h +0 -21
- data/lib/qml/context.rb +0 -71
- data/lib/qml/data/error.rb +0 -5
- data/lib/qml/dispatchable.rb +0 -34
- data/lib/qml/error_converter.rb +0 -16
- data/lib/qml/geometry.rb +0 -3
- data/lib/qml/geometry/point.rb +0 -5
- data/lib/qml/geometry/rectangle.rb +0 -5
- data/lib/qml/geometry/size.rb +0 -5
- data/lib/qml/image_provider.rb +0 -87
- data/lib/qml/init.rb +0 -29
- data/lib/qml/meta_object.rb +0 -20
- data/lib/qml/models.rb +0 -1
- data/lib/qml/qt_classes.rb +0 -9
- data/lib/qml/qt_object_base.rb +0 -233
- data/lib/qml/reactive/bindable.rb +0 -79
- data/lib/qml/reactive/chained_signal.rb +0 -25
- data/lib/qml/reactive/error.rb +0 -5
- data/lib/qml/reactive/object.rb +0 -293
- data/lib/qml/reactive/property.rb +0 -19
- data/lib/qml/reactive/signal.rb +0 -115
- data/lib/qml/reactive/signal_spy.rb +0 -27
- data/lib/qml/reactive/signals/map_signal.rb +0 -21
- data/lib/qml/reactive/signals/merge_signal.rb +0 -21
- data/lib/qml/reactive/signals/select_signal.rb +0 -21
- data/lib/qml/reactive/simple_property.rb +0 -17
- data/lib/qml/reactive/unbound_property.rb +0 -42
- data/lib/qml/reactive/unbound_signal.rb +0 -51
- data/lib/qml/test_util.rb +0 -1
- data/lib/qml/test_util/object_life_checker.rb +0 -17
- data/lib/qml/wrappable.rb +0 -9
- data/spec/qml/context_spec.rb +0 -43
- data/spec/qml/conversion_spec.rb +0 -60
- data/spec/qml/dispatchable_spec.rb +0 -26
- data/spec/qml/dispatcher_spec.rb +0 -71
- data/spec/qml/geometry/point_spec.rb +0 -4
- data/spec/qml/geometry/rectangle_spec.rb +0 -4
- data/spec/qml/geometry/size_spec.rb +0 -4
- data/spec/qml/image_provider_spec.rb +0 -33
- data/spec/qml/qt_object_base_spec.rb +0 -119
- data/spec/qml/reactive/object_spec.rb +0 -249
- data/spec/qml/reactive/property_spec.rb +0 -70
- data/spec/qml/reactive/signal_spec.rb +0 -191
- data/spec/qml/reactive/signal_spy_spec.rb +0 -26
- data/spec/qml/reactive/unbound_property_spec.rb +0 -40
- data/spec/qml/reactive/unbound_signal_spec.rb +0 -70
- data/spec/qml/test_object_spec.rb +0 -186
- data/spec/qml/wrappable_spec.rb +0 -10
- data/spec/shared/qml/reactive/object.rb +0 -39
data/ext/qml/rubyvalue.h
DELETED
@@ -1,224 +0,0 @@
|
|
1
|
-
#pragma once
|
2
|
-
#include "util.h"
|
3
|
-
#include <ruby.h>
|
4
|
-
#include <array>
|
5
|
-
|
6
|
-
class QVariant;
|
7
|
-
class QJSValue;
|
8
|
-
|
9
|
-
namespace RubyQml {
|
10
|
-
|
11
|
-
namespace detail {
|
12
|
-
template <typename T, typename Enable = void> struct Conversion
|
13
|
-
{
|
14
|
-
static T from(RubyValue x);
|
15
|
-
static RubyValue to(typename std::conditional<std::is_scalar<T>::value, T, const T &>::type str);
|
16
|
-
};
|
17
|
-
|
18
|
-
}
|
19
|
-
|
20
|
-
#define RUBYQML_INTERN(str) \
|
21
|
-
[] { static auto id = rb_intern(str); return id; }()
|
22
|
-
|
23
|
-
class RubyModule;
|
24
|
-
|
25
|
-
class RubyValue
|
26
|
-
{
|
27
|
-
public:
|
28
|
-
RubyValue() = default;
|
29
|
-
RubyValue(VALUE value) : mValue(value) {}
|
30
|
-
|
31
|
-
template <typename T> static RubyValue from(const T &value)
|
32
|
-
{
|
33
|
-
return detail::Conversion<T>::to(value);
|
34
|
-
}
|
35
|
-
|
36
|
-
template <typename T> T to() const
|
37
|
-
{
|
38
|
-
return detail::Conversion<T>::from(*this);
|
39
|
-
}
|
40
|
-
|
41
|
-
operator VALUE() const { return mValue; }
|
42
|
-
|
43
|
-
template <typename ... TArgs>
|
44
|
-
RubyValue send(ID method, TArgs ... args) const
|
45
|
-
{
|
46
|
-
return rb_funcall(mValue, method, sizeof...(args), args...);
|
47
|
-
}
|
48
|
-
|
49
|
-
template <typename ... TArgs>
|
50
|
-
RubyValue send(const char *method, TArgs ... args) const
|
51
|
-
{
|
52
|
-
return send(rb_intern(method), args...);
|
53
|
-
}
|
54
|
-
|
55
|
-
bool operator==(const RubyValue &other) const { return mValue == other.mValue; }
|
56
|
-
bool operator!=(const RubyValue &other) const { return !operator==(other); }
|
57
|
-
explicit operator bool() const { return RTEST(mValue); }
|
58
|
-
|
59
|
-
bool isKindOf(const RubyValue &module) const
|
60
|
-
{
|
61
|
-
return RTEST(rb_obj_is_kind_of(mValue, module));
|
62
|
-
}
|
63
|
-
|
64
|
-
bool isConvertibleTo(int metaType) const;
|
65
|
-
int defaultMetaType() const;
|
66
|
-
|
67
|
-
static RubyValue fromVariant(const QVariant &value);
|
68
|
-
QVariant toVariant() const;
|
69
|
-
QVariant toVariant(int type) const;
|
70
|
-
static RubyValue fromQObject(QObject *obj, bool implicit = true);
|
71
|
-
QObject *toQObject() const;
|
72
|
-
|
73
|
-
ID toID() const;
|
74
|
-
static RubyValue fromID(ID id) { return ID2SYM(id); }
|
75
|
-
|
76
|
-
static void addEnumeratorMetaType(int metaType);
|
77
|
-
|
78
|
-
private:
|
79
|
-
volatile VALUE mValue = Qnil;
|
80
|
-
};
|
81
|
-
|
82
|
-
namespace detail {
|
83
|
-
|
84
|
-
template <>
|
85
|
-
struct Conversion<RubyValue>
|
86
|
-
{
|
87
|
-
static RubyValue from(RubyValue x) { return x; }
|
88
|
-
static RubyValue to(RubyValue x) { return x; }
|
89
|
-
};
|
90
|
-
|
91
|
-
template <>
|
92
|
-
struct Conversion<bool>
|
93
|
-
{
|
94
|
-
static bool from(RubyValue value) { return value; }
|
95
|
-
static RubyValue to(bool x) { return x ? Qtrue : Qfalse; }
|
96
|
-
};
|
97
|
-
|
98
|
-
// signed integers
|
99
|
-
|
100
|
-
template <typename T>
|
101
|
-
struct Conversion<T, typename std::enable_if<std::is_signed<T>::value && std::is_integral<T>::value>::type>
|
102
|
-
{
|
103
|
-
static T from(RubyValue x) { return NUM2LL(x); }
|
104
|
-
static RubyValue to(T x) { return LL2NUM(x); }
|
105
|
-
};
|
106
|
-
|
107
|
-
// unsigned integers
|
108
|
-
|
109
|
-
template <typename T>
|
110
|
-
struct Conversion<T, typename std::enable_if<std::is_unsigned<T>::value && std::is_integral<T>::value>::type>
|
111
|
-
{
|
112
|
-
static T from(RubyValue x) { return NUM2ULL(x); }
|
113
|
-
static RubyValue to(T x) { return ULL2NUM(x); }
|
114
|
-
};
|
115
|
-
|
116
|
-
// floating point values
|
117
|
-
|
118
|
-
template <typename T>
|
119
|
-
struct Conversion<T, typename std::enable_if<std::is_floating_point<T>::value>::type>
|
120
|
-
{
|
121
|
-
static T from(RubyValue x)
|
122
|
-
{
|
123
|
-
auto type = rb_type(x);
|
124
|
-
if (type == T_FIXNUM || type == T_BIGNUM) {
|
125
|
-
return double(NUM2LL(x));
|
126
|
-
} else {
|
127
|
-
return RFLOAT_VALUE(VALUE(x));
|
128
|
-
}
|
129
|
-
}
|
130
|
-
static RubyValue to(T x)
|
131
|
-
{
|
132
|
-
return rb_float_new(x);
|
133
|
-
}
|
134
|
-
};
|
135
|
-
|
136
|
-
// QList and QVector
|
137
|
-
|
138
|
-
template <class T> struct IsQListLike : std::false_type {};
|
139
|
-
template <class V> struct IsQListLike<QList<V>> : std::true_type {};
|
140
|
-
template <class V> struct IsQListLike<QVector<V>> : std::true_type {};
|
141
|
-
|
142
|
-
template <template<class> class T, class V>
|
143
|
-
struct Conversion<T<V>, typename std::enable_if<IsQListLike<T<V>>::value>::type>
|
144
|
-
{
|
145
|
-
static T<V> from(RubyValue x)
|
146
|
-
{
|
147
|
-
x = rb_convert_type(x, T_ARRAY, "Array", "to_ary");
|
148
|
-
int length = RARRAY_LEN(VALUE(x));
|
149
|
-
T<V> list;
|
150
|
-
list.reserve(length);
|
151
|
-
for (int i = 0; i < length; ++i) {
|
152
|
-
list << RubyValue(RARRAY_AREF(VALUE(x), i)).to<V>();
|
153
|
-
}
|
154
|
-
return list;
|
155
|
-
}
|
156
|
-
static RubyValue to(const T<V> &list)
|
157
|
-
{
|
158
|
-
auto ary = rb_ary_new();
|
159
|
-
for (const auto &elem : list) {
|
160
|
-
auto x = RubyValue::from(elem);
|
161
|
-
rb_ary_push(ary, x);
|
162
|
-
}
|
163
|
-
return ary;
|
164
|
-
}
|
165
|
-
};
|
166
|
-
|
167
|
-
// QHash and QMap
|
168
|
-
|
169
|
-
template <class T> struct IsQHashLike : std::false_type {};
|
170
|
-
template <class K, class V> struct IsQHashLike<QHash<K, V>> : std::true_type {};
|
171
|
-
template <class K, class V> struct IsQHashLike<QMap<K, V>> : std::true_type {};
|
172
|
-
|
173
|
-
template <template<class, class> class T, class K, class V>
|
174
|
-
struct Conversion<T<K, V>, typename std::enable_if<IsQHashLike<T<K, V>>::value>::type>
|
175
|
-
{
|
176
|
-
static T<K, V> from(RubyValue x)
|
177
|
-
{
|
178
|
-
x = rb_convert_type(x, T_HASH, "Hash", "to_hash");
|
179
|
-
|
180
|
-
T<K, V> hash;
|
181
|
-
auto each = [](VALUE key, VALUE value, VALUE arg) -> int {
|
182
|
-
auto &hash = *reinterpret_cast<T<K, V> *>(arg);
|
183
|
-
hash[RubyValue(key).to<K>()] = RubyValue(value).to<V>();
|
184
|
-
return ST_CONTINUE;
|
185
|
-
};
|
186
|
-
auto eachPtr = (int (*)(VALUE, VALUE, VALUE))each;
|
187
|
-
rb_hash_foreach(x, (int (*)(...))eachPtr, (VALUE)(&hash));
|
188
|
-
return hash;
|
189
|
-
}
|
190
|
-
static RubyValue to(const T<K, V> &hash)
|
191
|
-
{
|
192
|
-
auto rubyHash = rb_hash_new();
|
193
|
-
for (auto i = hash.begin(); i != hash.end(); ++i) {
|
194
|
-
auto k = RubyValue::from(i.key());
|
195
|
-
auto v = RubyValue::from(i.value());
|
196
|
-
rb_hash_aset(rubyHash, k, v);
|
197
|
-
}
|
198
|
-
return rubyHash;
|
199
|
-
}
|
200
|
-
};
|
201
|
-
|
202
|
-
// QObject-derived
|
203
|
-
|
204
|
-
template <typename T>
|
205
|
-
struct Conversion<
|
206
|
-
T *,
|
207
|
-
typename std::enable_if<
|
208
|
-
std::is_base_of<QObject, T>::value
|
209
|
-
>::type
|
210
|
-
>
|
211
|
-
{
|
212
|
-
static T *from(RubyValue value) { return dynamic_cast<T *>(value.toQObject()); }
|
213
|
-
static RubyValue to(T *value) { return RubyValue::fromQObject(value); }
|
214
|
-
};
|
215
|
-
|
216
|
-
template <>
|
217
|
-
struct Conversion<const char *>
|
218
|
-
{
|
219
|
-
static RubyValue to(const char *str);
|
220
|
-
};
|
221
|
-
|
222
|
-
} // namespace detail
|
223
|
-
|
224
|
-
} // namespace RubyQml
|
data/ext/qml/signalforwarder.cpp
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
#include "signalforwarder.h"
|
2
|
-
#include "util.h"
|
3
|
-
#include <QtCore/QDebug>
|
4
|
-
|
5
|
-
namespace RubyQml {
|
6
|
-
|
7
|
-
SignalForwarder::SignalForwarder(QObject *obj, const QMetaMethod &signal, RubyValue proc) :
|
8
|
-
QObject(obj),
|
9
|
-
mSignal(signal),
|
10
|
-
mProcRef(proc)
|
11
|
-
{
|
12
|
-
QMetaObject::connect(obj, signal.methodIndex(), this, QObject::staticMetaObject.methodCount());
|
13
|
-
}
|
14
|
-
|
15
|
-
SignalForwarder::~SignalForwarder()
|
16
|
-
{
|
17
|
-
}
|
18
|
-
|
19
|
-
int SignalForwarder::qt_metacall(QMetaObject::Call call, int id, void **args)
|
20
|
-
{
|
21
|
-
id = QObject::qt_metacall(call, id, args);
|
22
|
-
if (id < 0) {
|
23
|
-
return id;
|
24
|
-
}
|
25
|
-
if (call == QMetaObject::InvokeMetaMethod) {
|
26
|
-
if (id == 0) {
|
27
|
-
forwardArgs(args);
|
28
|
-
}
|
29
|
-
--id;
|
30
|
-
}
|
31
|
-
return id;
|
32
|
-
}
|
33
|
-
|
34
|
-
void SignalForwarder::gc_mark()
|
35
|
-
{
|
36
|
-
rb_gc_mark(mProcRef.value());
|
37
|
-
}
|
38
|
-
|
39
|
-
void SignalForwarder::forwardArgs(void **args)
|
40
|
-
{
|
41
|
-
QVariantList list;
|
42
|
-
list.reserve(mSignal.parameterCount());
|
43
|
-
for (int i = 0; i < mSignal.parameterCount(); ++i) {
|
44
|
-
auto type = mSignal.parameterType(i);
|
45
|
-
if (type == QMetaType::QVariant) {
|
46
|
-
list << *static_cast<QVariant *>(args[i + 1]);
|
47
|
-
} else {
|
48
|
-
list << QVariant(type, args[i + 1]);
|
49
|
-
}
|
50
|
-
}
|
51
|
-
callProc(list);
|
52
|
-
}
|
53
|
-
|
54
|
-
void SignalForwarder::callProc(const QVariantList &list)
|
55
|
-
{
|
56
|
-
if (mProcRef.hasValue()) {
|
57
|
-
withGvl([&] {
|
58
|
-
auto args = RubyValue::from(list);
|
59
|
-
rb_apply(mProcRef.value(), RUBYQML_INTERN("call"), args);
|
60
|
-
});
|
61
|
-
}
|
62
|
-
}
|
63
|
-
|
64
|
-
} // namespace RubyQml
|
data/ext/qml/signalforwarder.h
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
#pragma once
|
2
|
-
#include "rubyvalue.h"
|
3
|
-
#include "weakvaluereference.h"
|
4
|
-
#include "markable.h"
|
5
|
-
#include <QObject>
|
6
|
-
#include <QMetaMethod>
|
7
|
-
|
8
|
-
namespace RubyQml {
|
9
|
-
|
10
|
-
class SignalForwarder : public QObject, public Markable
|
11
|
-
{
|
12
|
-
public:
|
13
|
-
SignalForwarder(QObject *obj, const QMetaMethod &signal, RubyValue proc);
|
14
|
-
~SignalForwarder();
|
15
|
-
|
16
|
-
int qt_metacall(QMetaObject::Call call, int id, void **args) override;
|
17
|
-
|
18
|
-
void gc_mark() override;
|
19
|
-
|
20
|
-
private:
|
21
|
-
void forwardArgs(void **args);
|
22
|
-
void callProc(const QVariantList &list);
|
23
|
-
|
24
|
-
QMetaMethod mSignal;
|
25
|
-
WeakValueReference mProcRef;
|
26
|
-
};
|
27
|
-
|
28
|
-
} // namespace RubyQml
|
29
|
-
|
data/ext/qml/util.cpp
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
#include "util.h"
|
2
|
-
#include "rubyvalue.h"
|
3
|
-
#include <QString>
|
4
|
-
#include <string>
|
5
|
-
#include <memory>
|
6
|
-
#include <cxxabi.h>
|
7
|
-
|
8
|
-
#ifdef HAVE_RUBY_THREAD_H
|
9
|
-
#include <ruby/thread.h>
|
10
|
-
#else
|
11
|
-
extern "C" {
|
12
|
-
void *rb_thread_call_with_gvl(void *(*func)(void *), void *data1);
|
13
|
-
void *rb_thread_call_without_gvl(void *(*func)(void *), void *data1, rb_unblock_function_t *ubf, void *data2);
|
14
|
-
}
|
15
|
-
#endif
|
16
|
-
|
17
|
-
namespace RubyQml {
|
18
|
-
|
19
|
-
void convertCppErrors(const std::function<void ()> &doAction) noexcept
|
20
|
-
{
|
21
|
-
bool cppErrorOccured= false;
|
22
|
-
VALUE cppErrorClassName = Qnil;
|
23
|
-
VALUE cppErrorMessage = Qnil;
|
24
|
-
try {
|
25
|
-
doAction();
|
26
|
-
}
|
27
|
-
catch (const std::exception &ex) {
|
28
|
-
cppErrorOccured = true;
|
29
|
-
int status;
|
30
|
-
auto classname = abi::__cxa_demangle(typeid(ex).name(), nullptr, nullptr, &status);
|
31
|
-
cppErrorClassName = rb_str_new_cstr(classname);
|
32
|
-
free(classname);
|
33
|
-
cppErrorMessage = rb_str_new_cstr(ex.what());
|
34
|
-
}
|
35
|
-
if (cppErrorOccured) {
|
36
|
-
auto patterns = rb_funcall(rb_path2class("QML::ErrorConverter"), rb_intern("patterns"), 0);
|
37
|
-
auto rubyClass = rb_hash_aref(patterns, cppErrorClassName);
|
38
|
-
VALUE exc;
|
39
|
-
if (RTEST(rubyClass)) {
|
40
|
-
exc = rb_funcall(rubyClass, rb_intern("new"), 1, cppErrorMessage);
|
41
|
-
} else {
|
42
|
-
exc = rb_funcall(rb_path2class("QML::CppError"), rb_intern("new"), 2, cppErrorClassName, cppErrorMessage);
|
43
|
-
}
|
44
|
-
rb_exc_raise(exc);
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
|
-
void rescue(const std::function<void ()> &doAction, const std::function<void (RubyValue)> &handleException)
|
49
|
-
{
|
50
|
-
VALUE (*callback)(VALUE) = [](VALUE data) {
|
51
|
-
(*reinterpret_cast<std::function<void ()> *>(data))();
|
52
|
-
return Qnil;
|
53
|
-
};
|
54
|
-
VALUE (*rescueCallback)(VALUE, VALUE) = [](VALUE data, VALUE excObject) {
|
55
|
-
(*reinterpret_cast<std::function<void (VALUE)>*>(data))(excObject);
|
56
|
-
return Qnil;
|
57
|
-
};
|
58
|
-
rb_rescue((VALUE (*)(...))callback, (VALUE)&doAction, (VALUE (*)(...))rescueCallback, (VALUE)&handleException);
|
59
|
-
}
|
60
|
-
|
61
|
-
void rescueNotify(const std::function<void ()> &doAction)
|
62
|
-
{
|
63
|
-
rescue(doAction, [&](RubyValue excObject) {
|
64
|
-
rb_funcall(rb_path2class("QML::Application"), rb_intern("notify_error"), 1, excObject);
|
65
|
-
});
|
66
|
-
}
|
67
|
-
|
68
|
-
namespace {
|
69
|
-
|
70
|
-
void changeGvl(const std::function<void ()> &doAction, bool gvl)
|
71
|
-
{
|
72
|
-
auto actionPtr = const_cast<void *>(static_cast<const void *>(&doAction));
|
73
|
-
auto f = [](void *data) -> void * {
|
74
|
-
auto &doAction= *static_cast<const std::function<void ()> *>(data);
|
75
|
-
try {
|
76
|
-
doAction();
|
77
|
-
} catch (...) {
|
78
|
-
return new std::exception_ptr(std::current_exception());
|
79
|
-
}
|
80
|
-
return nullptr;
|
81
|
-
};
|
82
|
-
void *result;
|
83
|
-
if (gvl) {
|
84
|
-
result = rb_thread_call_with_gvl(f, actionPtr);
|
85
|
-
} else {
|
86
|
-
result = rb_thread_call_without_gvl(f, actionPtr, RUBY_UBF_IO, nullptr);
|
87
|
-
}
|
88
|
-
std::unique_ptr<std::exception_ptr> exc(static_cast<std::exception_ptr *>(result));
|
89
|
-
if (exc && *exc) {
|
90
|
-
std::rethrow_exception(*exc);
|
91
|
-
}
|
92
|
-
}
|
93
|
-
|
94
|
-
}
|
95
|
-
|
96
|
-
void withoutGvl(const std::function<void ()> &doAction)
|
97
|
-
{
|
98
|
-
changeGvl(doAction, false);
|
99
|
-
}
|
100
|
-
|
101
|
-
void withGvl(const std::function<void ()> &doAction)
|
102
|
-
{
|
103
|
-
changeGvl(doAction, true);
|
104
|
-
}
|
105
|
-
|
106
|
-
void fail(const char *errorClassName, const QString &message)
|
107
|
-
{
|
108
|
-
auto msg = message.toUtf8();
|
109
|
-
rb_raise(rb_path2class(errorClassName), "%s", msg.data());
|
110
|
-
}
|
111
|
-
|
112
|
-
}
|
data/ext/qml/util.h
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
#pragma once
|
2
|
-
|
3
|
-
#include <QMetaType>
|
4
|
-
#include <functional>
|
5
|
-
#include <type_traits>
|
6
|
-
#include <array>
|
7
|
-
#include <ruby.h>
|
8
|
-
|
9
|
-
#ifndef RARRAY_AREF
|
10
|
-
#define RARRAY_AREF(a, i) ((RARRAY_PTR(a)[i]))
|
11
|
-
#endif
|
12
|
-
|
13
|
-
namespace RubyQml {
|
14
|
-
|
15
|
-
template <size_t... Indices>
|
16
|
-
struct IntegerSequence {};
|
17
|
-
|
18
|
-
template <size_t N, typename Seq = IntegerSequence<>, bool Last = N == 0>
|
19
|
-
struct MakeIntegerSequenceImpl
|
20
|
-
{
|
21
|
-
using type = Seq;
|
22
|
-
};
|
23
|
-
|
24
|
-
template <size_t N, size_t... Indices>
|
25
|
-
struct MakeIntegerSequenceImpl<N, IntegerSequence<Indices...>, false> :
|
26
|
-
MakeIntegerSequenceImpl<N - 1, IntegerSequence<N - 1, Indices...>>
|
27
|
-
{};
|
28
|
-
|
29
|
-
template <size_t N>
|
30
|
-
using MakeIntegerSequence = typename MakeIntegerSequenceImpl<N>::type;
|
31
|
-
|
32
|
-
template <typename F, typename... Args, size_t... Indices>
|
33
|
-
typename std::result_of<F(Args...)>::type
|
34
|
-
applyWithTupleImpl(const F &func, const std::tuple<Args...> &args, IntegerSequence<Indices...>)
|
35
|
-
{
|
36
|
-
return func(std::get<Indices>(args)...);
|
37
|
-
}
|
38
|
-
|
39
|
-
template <typename F, typename... Args>
|
40
|
-
typename std::result_of<F(Args...)>::type
|
41
|
-
applyWithTuple(const F &func, const std::tuple<Args...> &args)
|
42
|
-
{
|
43
|
-
return applyWithTupleImpl(func, args, MakeIntegerSequence<sizeof...(Args)>());
|
44
|
-
}
|
45
|
-
|
46
|
-
class RubyValue;
|
47
|
-
|
48
|
-
class RubyException
|
49
|
-
{
|
50
|
-
public:
|
51
|
-
RubyException(int state) : mState(state) {}
|
52
|
-
int state() const { return mState; }
|
53
|
-
private:
|
54
|
-
int mState = 0;
|
55
|
-
};
|
56
|
-
|
57
|
-
void convertCppErrors(const std::function<void()> &doAction) noexcept;
|
58
|
-
|
59
|
-
void rescue(const std::function<void ()> &doAction, const std::function<void (RubyValue)> &handleException);
|
60
|
-
void rescueNotify(const std::function<void ()> &doAction);
|
61
|
-
|
62
|
-
// call function with GVL unlocked
|
63
|
-
void withoutGvl(const std::function<void()> &doAction);
|
64
|
-
|
65
|
-
// call function with GVL locked
|
66
|
-
void withGvl(const std::function<void()> &doAction);
|
67
|
-
|
68
|
-
void fail(const char *errorClassName, const QString &message);
|
69
|
-
|
70
|
-
template <typename ... TArgs>
|
71
|
-
void callSuper(TArgs ... args)
|
72
|
-
{
|
73
|
-
constexpr int argc = sizeof...(args);
|
74
|
-
std::array<VALUE, argc> argv = {{ VALUE(args)... }};
|
75
|
-
protect([&] {
|
76
|
-
rb_call_super(argc, argv.data());
|
77
|
-
});
|
78
|
-
}
|
79
|
-
|
80
|
-
} // namespace RubyQml
|
81
|
-
|
82
|
-
Q_DECLARE_METATYPE(const QMetaObject*)
|