added two utility functions to emval.
- check if a given key exists. - return length of an array.
This commit is contained in:
Родитель
1b9928686e
Коммит
d161fccc9b
|
@ -53,6 +53,10 @@ function __emval_new_cstring(str) {
|
|||
return __emval_register(Pointer_stringify(str));
|
||||
}
|
||||
|
||||
function __emval_has_property(handle, k) {
|
||||
return _emval_handle_array[handle].value.hasOwnProperty(k);
|
||||
}
|
||||
|
||||
function __emval_get_property(handle, k) {
|
||||
k = Pointer_stringify(k);
|
||||
return __emval_register(_emval_handle_array[handle].value[k]);
|
||||
|
@ -66,6 +70,15 @@ function __emval_get_property_by_unsigned_long(handle, k) {
|
|||
return __emval_register(_emval_handle_array[handle].value[k]);
|
||||
}
|
||||
|
||||
function __emval_get_length(handle) {
|
||||
var val = _emval_handle_array[handle].value;
|
||||
if (Object.prototype.toString.call(val) === "[object Array]") {
|
||||
return val.length;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
function __emval_eval_global_method(handle, objectName, methodName) {
|
||||
var objectNameStr = Pointer_stringify(objectName);
|
||||
var methodNameStr = Pointer_stringify(methodName);
|
||||
|
|
|
@ -14,12 +14,14 @@ namespace emscripten {
|
|||
EM_VAL _emval_new_object();
|
||||
EM_VAL _emval_new_long(long value);
|
||||
EM_VAL _emval_new_cstring(const char* str);
|
||||
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);
|
||||
EM_VAL _emval_get_property_by_unsigned_long(EM_VAL object, unsigned long 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);
|
||||
unsigned int _emval_get_length(EM_VAL object);
|
||||
void _emval_as(EM_VAL value, TYPEID returnType);
|
||||
EM_VAL _emval_call(
|
||||
EM_VAL value,
|
||||
|
@ -78,6 +80,10 @@ namespace emscripten {
|
|||
return *this;
|
||||
}
|
||||
|
||||
bool exist(const char* key) const {
|
||||
return internal::_emval_has_property(handle, key);
|
||||
}
|
||||
|
||||
val get(const char* key) const {
|
||||
return val(internal::_emval_get_property(handle, key));
|
||||
}
|
||||
|
@ -111,6 +117,10 @@ namespace emscripten {
|
|||
internal::_emval_set_property_by_int(handle, key, v.handle);
|
||||
}
|
||||
|
||||
unsigned int length() {
|
||||
return internal::_emval_get_length(handle);
|
||||
}
|
||||
|
||||
template<typename ...Args>
|
||||
val operator()(Args... args) {
|
||||
using namespace internal;
|
||||
|
|
Загрузка…
Ссылка в новой задаче