diff options
author | mey <mey@imvu.com> | 2012-12-03 16:25:17 -0800 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-12 14:22:18 +0300 |
commit | c9eb75d64ab5735f15012c5839980edf3f1dd2ee (patch) | |
tree | 8e528fc80756859361a9306c0ac451f91b3b5677 | |
parent | b5d84da03b83039a382494e2cfd1a125f0fb7199 (diff) |
adding function to convert JS array to vector.
-rwxr-xr-x | system/include/emscripten/bind.h | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index 6b8b6f10..281ae85b 100755 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -764,21 +764,6 @@ namespace emscripten { return *this; } - - /* - * void _embind_register_class_operator_array_get( - TYPEID classType, - TYPEID elementType, - GenericFunction invoker); - - void _embind_register_class_operator_array_set( - TYPEID classType, - TYPEID elementType, - GenericFunction invoker); - - ArrayAccessSetInvoker - */ - template<typename ElementType, typename IndexType> class_& arrayoperatorget() { using namespace internal; @@ -819,6 +804,18 @@ namespace emscripten { // VECTORS //////////////////////////////////////////////////////////////////////////////// template<typename T> + std::vector<T> vecFromJSArray(val v) { + auto l = v.get("length").as<unsigned>(); + + std::vector<T> rv; + for(unsigned i = 0; i < l; ++i) { + rv.push_back(v.get(i).as<T>()); + } + + return rv; + }; + + template<typename T> class_<std::vector<T>> register_vector(const char* name) { using namespace std; typedef vector<T> VecType; @@ -835,6 +832,7 @@ namespace emscripten { .template arrayoperatorget<T, size_t>() .template arrayoperatorset<T, size_t>() ; + return c; } |