aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Austin <chad@imvu.com>2013-01-15 17:59:07 -0800
committerJukka Jylänki <jujjyl@gmail.com>2013-04-12 14:23:08 +0300
commitc5b8e64a0becd50f51ae50b1f4480f3274f680f6 (patch)
treedd1e541cfd9287a78ae1c2f7a80181b7b0fbf2f6
parentd0969fc651367d801d28146ef6f4dbe1d26f2aa2 (diff)
bring emscripten::val closer to the set of primitive operations provided by JS on values
-rwxr-xr-xsrc/embind/emval.js12
-rw-r--r--system/include/emscripten/val.h32
2 files changed, 27 insertions, 17 deletions
diff --git a/src/embind/emval.js b/src/embind/emval.js
index 49424631..3df5a540 100755
--- a/src/embind/emval.js
+++ b/src/embind/emval.js
@@ -41,6 +41,10 @@ function __emval_decref(handle) {
}
}
+function __emval_new_array() {
+ return __emval_register([]);
+}
+
function __emval_new_object() {
return __emval_register({});
}
@@ -49,12 +53,8 @@ function __emval_new_null() {
return __emval_register(null);
}
-function __emval_new_long(value) {
- return __emval_register(value);
-}
-
-function __emval_new_cstring(str) {
- return __emval_register(Pointer_stringify(str));
+function __emval_new_cstring(v) {
+ return __emval_register(Pointer_stringify(v));
}
function __emval_has_property(handle, k) {
diff --git a/system/include/emscripten/val.h b/system/include/emscripten/val.h
index 8f7df882..65f52266 100644
--- a/system/include/emscripten/val.h
+++ b/system/include/emscripten/val.h
@@ -11,10 +11,13 @@ namespace emscripten {
void _emval_incref(EM_VAL value);
void _emval_decref(EM_VAL value);
+
+ EM_VAL _emval_new_array();
EM_VAL _emval_new_object();
EM_VAL _emval_new_null();
- EM_VAL _emval_new_long(long value);
- EM_VAL _emval_new_cstring(const char* str);
+ EM_VAL _emval_new_cstring(const char*);
+ void _emval_take_value(TYPEID type/*, ...*/);
+
bool _emval_has_property(EM_VAL object, const char* key);
EM_VAL _emval_get_property(EM_VAL object, const char* key);
EM_VAL _emval_get_property_by_long(EM_VAL object, long key);
@@ -45,28 +48,35 @@ namespace emscripten {
class val {
public:
+ static val array() {
+ return val(internal::_emval_new_array());
+ }
+
static val object() {
return val(internal::_emval_new_object());
- };
+ }
static val null() {
return val(internal::_emval_new_null());
- };
+ }
static val take_ownership(internal::EM_VAL e) {
return val(e);
}
- explicit val(long l)
- : handle(internal::_emval_new_long(l))
- {}
-
- explicit val(const char* str)
- : handle(internal::_emval_new_cstring(str))
- {}
+ template<typename T>
+ explicit val(const T& value) {
+ typedef internal::BindingType<T> BT;
+ auto taker = reinterpret_cast<internal::EM_VAL (*)(internal::TYPEID, typename BT::WireType)>(&internal::_emval_take_value);
+ handle = taker(internal::TypeID<T>::get(), BT::toWireType(value));
+ }
val() = delete;
+ val(const char* v)
+ : handle(internal::_emval_new_cstring(v))
+ {}
+
val(const val& v)
: handle(v.handle)
{