Merge lp:~marcustomlinson/unity-js-scopes/lp-1524200 into lp:unity-js-scopes

Proposed by Marcus Tomlinson on 2015-12-09
Status: Merged
Approved by: Marcus Tomlinson on 2015-12-15
Approved revision: 118
Merged at revision: 119
Proposed branch: lp:~marcustomlinson/unity-js-scopes/lp-1524200
Merge into: lp:unity-js-scopes
Diff against target: 102 lines (+33/-3)
5 files modified
qtc-templates/scope-js/src/data/displayName-settings.ini.in (+3/-3)
src/bindings/src/addon.cc (+18/-0)
src/bindings/src/common.cc (+7/-0)
src/bindings/src/variant.cc (+4/-0)
src/bindings/src/variant.h (+1/-0)
To merge this branch: bzr merge lp:~marcustomlinson/unity-js-scopes/lp-1524200
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve on 2015-12-09
Alexandre Abreu 2015-12-09 Pending
Review via email: mp+279977@code.launchpad.net

Commit message

Bind both the original Variant class and our bound version in order to support direct and indirect access to variants via the bindings

To post a comment you must log in.
118. By Marcus Tomlinson on 2015-12-09

Bind both the original Variant class and our bound version in order to support direct and indirect access to variants via the bindings

Alexandre Abreu (abreu-alexandre) wrote :

+1

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'qtc-templates/scope-js/src/data/displayName-settings.ini.in'
2--- qtc-templates/scope-js/src/data/displayName-settings.ini.in 2015-10-22 05:41:05 +0000
3+++ qtc-templates/scope-js/src/data/displayName-settings.ini.in 2015-12-09 07:25:35 +0000
4@@ -1,7 +1,7 @@
5 @if "%ContentType%" != "empty"
6-# Below are some example settings. You can access your scope's
7-# settings by calling settings() from the Query::run() method.
8-# E.g. auto location = settings().at("location").get_string();
9+# Below are some example settings. You can access your scope's settings by
10+# calling scopes.self.settings from anywhere in your scope implementation.
11+# E.g. var location = scopes.self.settings["location"].get_string();
12
13 #[location]
14 #type = string
15
16=== modified file 'src/bindings/src/addon.cc'
17--- src/bindings/src/addon.cc 2015-11-20 12:10:10 +0000
18+++ src/bindings/src/addon.cc 2015-12-09 07:25:35 +0000
19@@ -89,6 +89,7 @@
20 variant
21 .set_constructor<v8::Local<v8::Value>>()
22 .add_method("get_int", &Variant::get_int)
23+ .add_method("get_int64_t", &Variant::get_int64_t)
24 .add_method("get_double", &Variant::get_double)
25 .add_method("get_bool", &Variant::get_bool)
26 .add_method("get_string", &Variant::get_string)
27@@ -98,6 +99,22 @@
28 .add_method("which", &Variant::which)
29 .add_method("serialize_json", &Variant::serialize_json);
30
31+ // Also bind the original Variant class for direct access (E.g. via settings)
32+ v8cpp::Class<unity::scopes::Variant> variant_base(isolate);
33+ variant_base
34+ .add_method("get_int", &unity::scopes::Variant::get_int)
35+ .add_method("get_int64_t", &unity::scopes::Variant::get_int64_t)
36+ .add_method("get_double", &unity::scopes::Variant::get_double)
37+ .add_method("get_bool", &unity::scopes::Variant::get_bool)
38+ .add_method("get_string", &unity::scopes::Variant::get_string)
39+ .add_method("get_dict", &unity::scopes::Variant::get_dict)
40+ .add_method("get_array", &unity::scopes::Variant::get_array)
41+ .add_method("is_null", &unity::scopes::Variant::is_null)
42+ //.add_method("which", &unity::scopes::Variant::which)
43+ .add_method("serialize_json", &unity::scopes::Variant::serialize_json)
44+ .add_method("deserialize_json", &unity::scopes::Variant::deserialize_json);
45+
46+
47 v8cpp::Class<JavascriptScopeRuntime> js_scope(isolate);
48 js_scope
49 .add_method("scope_base", &JavascriptScopeRuntime::scope_base)
50@@ -454,6 +471,7 @@
51 module.add_class("SearchQuery", search_query);
52 module.add_class("SearchMetadata", search_metadata);
53 module.add_class("Variant", variant);
54+ module.add_class("VariantBase", variant_base);
55
56 // Factory functions
57 module.add_function("new_scope", &new_scope);
58
59=== modified file 'src/bindings/src/common.cc'
60--- src/bindings/src/common.cc 2015-10-08 14:02:02 +0000
61+++ src/bindings/src/common.cc 2015-12-09 07:25:35 +0000
62@@ -71,6 +71,13 @@
63
64 unity::scopes::Variant unity::scopesjs::to_variant(
65 v8::Local<v8::Value> value) {
66+ try
67+ {
68+ // Check first that the value recieved is not already a unity::scopes::Variant
69+ return v8cpp::from_v8<unity::scopes::Variant>(v8::Isolate::GetCurrent(), value);
70+ }
71+ catch (std::exception const&) {}
72+
73 using unity::scopes::Variant;
74 using unity::scopes::VariantArray;
75 using unity::scopes::VariantMap;
76
77=== modified file 'src/bindings/src/variant.cc'
78--- src/bindings/src/variant.cc 2015-10-19 20:21:29 +0000
79+++ src/bindings/src/variant.cc 2015-12-09 07:25:35 +0000
80@@ -64,6 +64,10 @@
81 return variant_->get_int();
82 }
83
84+int64_t Variant::get_int64_t() const {
85+ return variant_->get_int64_t();
86+}
87+
88 double Variant::get_double() const {
89 return variant_->get_double();
90 }
91
92=== modified file 'src/bindings/src/variant.h'
93--- src/bindings/src/variant.h 2015-10-19 20:21:29 +0000
94+++ src/bindings/src/variant.h 2015-12-09 07:25:35 +0000
95@@ -37,6 +37,7 @@
96 // v8 bindings
97 std::string serialize_json() const;
98 int get_int() const;
99+ int64_t get_int64_t() const;
100 double get_double() const;
101 bool get_bool() const;
102 std::string get_string() const;

Subscribers

People subscribed via source and target branches

to all changes: