aboutsummaryrefslogtreecommitdiff
path: root/tests/embind/embind_test.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-03-31 17:28:55 -0700
committerAlon Zakai <alonzakai@gmail.com>2014-03-31 17:28:55 -0700
commitd75c0bca8116f7dcb5224c4cce971a0397faac48 (patch)
tree17a95d16afae30579aa52405413bca816dd4d974 /tests/embind/embind_test.cpp
parent673d4315ab0d14846dfa2d966abd32400679fd43 (diff)
parentffed52a8ac686a54bfda83d722673c11b8e7093e (diff)
Merge pull request #2264 from imvu/incoming-with-fastcomp-asm.js-emval-2
Make emscripten::val compatible with fastcomp/asm.js
Diffstat (limited to 'tests/embind/embind_test.cpp')
-rw-r--r--tests/embind/embind_test.cpp59
1 files changed, 58 insertions, 1 deletions
diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp
index 4efc4bd8..d299660a 100644
--- a/tests/embind/embind_test.cpp
+++ b/tests/embind/embind_test.cpp
@@ -842,7 +842,7 @@ Enum emval_test_take_and_return_Enum(Enum e) {
return e;
}
-enum class EnumClass { ONE, TWO };
+enum class EnumClass : char { ONE, TWO };
EnumClass emval_test_take_and_return_EnumClass(EnumClass e) {
return e;
@@ -2304,3 +2304,60 @@ EMSCRIPTEN_BINDINGS(mixins) {
.constructor<>()
);
}
+
+template<typename T>
+T val_as(const val& v) {
+ return v.as<T>();
+}
+
+EMSCRIPTEN_BINDINGS(val_as) {
+ function("val_as_bool", &val_as<bool>);
+ function("val_as_char", &val_as<char>);
+ function("val_as_short", &val_as<short>);
+ function("val_as_int", &val_as<int>);
+ function("val_as_long", &val_as<long>);
+
+ function("val_as_float", &val_as<float>);
+ function("val_as_double", &val_as<double>);
+
+ function("val_as_string", &val_as<std::string>);
+ function("val_as_wstring", &val_as<std::wstring>);
+ function("val_as_val", &val_as<val>);
+
+ function("val_as_value_object", &val_as<StructVector>);
+ function("val_as_value_array", &val_as<TupleVector>);
+
+ function("val_as_enum", &val_as<Enum>);
+
+ // memory_view is always JS -> C++
+ //function("val_as_memory_view", &val_as<memory_view>);
+}
+
+val construct_with_6(val factory) {
+ unsigned char a1 = 6;
+ double a2 = -12.5;
+ std::string a3("a3");
+ StructVector a4(1, 2, 3, 4);
+ EnumClass a5 = EnumClass::TWO;
+ TupleVector a6(-1, -2, -3, -4);
+ return factory.new_(a1, a2, a3, a4, a5, a6);
+}
+
+val construct_with_memory_view(val factory) {
+ static const char data[11] = "0123456789";
+ return factory.new_(
+ std::string("before"),
+ memory_view(10, data),
+ std::string("after"));
+}
+
+val construct_with_ints_and_float(val factory) {
+ static const char data[11] = "0123456789";
+ return factory.new_(65537, 4.0f, 65538);
+}
+
+EMSCRIPTEN_BINDINGS(val_new_) {
+ function("construct_with_6_arguments", &construct_with_6);
+ function("construct_with_memory_view", &construct_with_memory_view);
+ function("construct_with_ints_and_float", &construct_with_ints_and_float);
+}