diff options
author | Chad Austin <chad@imvu.com> | 2013-01-22 08:46:35 -0800 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-12 14:23:24 +0300 |
commit | 661e70cb38bbdd704821c50c4324b5675b41068c (patch) | |
tree | cfe2098b9286f24f01d788c36bd987f2bfe50e7e | |
parent | 5701999237b30f3503b6ad2f20099e874561bdf9 (diff) |
simplify emscripten::val set and get
-rwxr-xr-x | src/embind/emval.js | 22 | ||||
-rw-r--r-- | system/include/emscripten/val.h | 40 |
2 files changed, 13 insertions, 49 deletions
diff --git a/src/embind/emval.js b/src/embind/emval.js index 1953428d..84ed1956 100755 --- a/src/embind/emval.js +++ b/src/embind/emval.js @@ -74,17 +74,8 @@ function __emval_get_global(name) { return __emval_register(global[name]); } -function __emval_get_property(handle, k) { - k = Pointer_stringify(k); - return __emval_register(_emval_handle_array[handle].value[k]); -} - -function __emval_get_property_by_long(handle, k) { - return __emval_register(_emval_handle_array[handle].value[k]); -} - -function __emval_get_property_by_unsigned_long(handle, k) { - return __emval_register(_emval_handle_array[handle].value[k]); +function __emval_get_property(handle, key) { + return __emval_register(_emval_handle_array[handle].value[_emval_handle_array[key].value]); } function __emval_eval_global_method(handle, objectName, methodName) { @@ -94,13 +85,8 @@ function __emval_eval_global_method(handle, objectName, methodName) { return __emval_register(result); } -function __emval_set_property(handle, k, value) { - k = Pointer_stringify(k); - _emval_handle_array[handle].value[k] = _emval_handle_array[value].value; -} - -function __emval_set_property_by_int(handle, k, value) { - _emval_handle_array[handle].value[k] = _emval_handle_array[value].value; +function __emval_set_property(handle, key, value) { + _emval_handle_array[handle].value[_emval_handle_array[key].value] = _emval_handle_array[value].value; } function __emval_as(handle, returnType) { diff --git a/system/include/emscripten/val.h b/system/include/emscripten/val.h index b0f55ec6..4903751b 100644 --- a/system/include/emscripten/val.h +++ b/system/include/emscripten/val.h @@ -20,12 +20,9 @@ namespace emscripten { void _emval_take_value(TYPEID type/*, ...*/); EM_VAL _emval_get_global(const char* name); - EM_VAL _emval_get_property(EM_VAL object, const char* key); - EM_VAL _emval_get_property_by_long(EM_VAL object, long key); - EM_VAL _emval_get_property_by_unsigned_long(EM_VAL object, unsigned long key); + EM_VAL _emval_get_property(EM_VAL object, EM_VAL key); EM_VAL _emval_eval_global_method(EM_VAL object, const char* objectName, const char* methodName); - void _emval_set_property(EM_VAL object, const char* key, EM_VAL value); - void _emval_set_property_by_int(EM_VAL object, long key, EM_VAL value); + void _emval_set_property(EM_VAL object, EM_VAL key, EM_VAL value); void _emval_as(EM_VAL value, TYPEID returnType); EM_VAL _emval_call( EM_VAL value, @@ -106,38 +103,19 @@ namespace emscripten { bool hasOwnProperty(const char* key) const { return val::global("Object").get("prototype").get("hasOwnProperty").call("call", *this, val(key)).as<bool>(); } - - val get(const char* key) const { - return val(internal::_emval_get_property(handle, key)); - } - - val get(int key) const { - return get(long(key)); - } - - val get(unsigned int key) const { - typedef unsigned long T; - return get(T(key)); - } - - val get(long key) const { - return val(internal::_emval_get_property_by_long(handle, key)); - } - - val get(unsigned long key) const { - return val(internal::_emval_get_property_by_unsigned_long(handle, key)); + + template<typename T> + val get(const T& key) const { + return val(internal::_emval_get_property(handle, val(key).handle)); } val eval_global_method(const char* objectName, const char* methodName) const { return val(internal::_emval_eval_global_method(handle, objectName, methodName)); } - void set(const char* key, val v) { - internal::_emval_set_property(handle, key, v.handle); - } - - void set(long key, val v) { - internal::_emval_set_property_by_int(handle, key, v.handle); + template<typename T> + void set(const T& key, val v) { + internal::_emval_set_property(handle, val(key).handle, v.handle); } template<typename ...Args> |