diff options
author | Chad Austin <chad@imvu.com> | 2013-05-03 18:20:26 -0700 |
---|---|---|
committer | Chad Austin <chad@imvu.com> | 2013-05-17 12:56:48 -0700 |
commit | fd8cbaa853ec9ea1f2c0c689e1729126c52368e4 (patch) | |
tree | 5359cad8a12b53f4d74dcd129945c6d08825a3c8 /tests/embind/embind_test.cpp | |
parent | 7f83ab2926947fda7181a7e67e76425f02da19c4 (diff) |
Add support for (fast?) memory_view objects. If C++ passes a memory_view to JS, it gets converted into a typed array object on the other side. Intended for WebGL.
Diffstat (limited to 'tests/embind/embind_test.cpp')
-rw-r--r-- | tests/embind/embind_test.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp index 23761efc..e8ca0338 100644 --- a/tests/embind/embind_test.cpp +++ b/tests/embind/embind_test.cpp @@ -1148,6 +1148,25 @@ EMSCRIPTEN_BINDINGS(interface_tests) { function("callDifferentArguments", &callDifferentArguments); } +template<typename T, size_t sizeOfArray> +constexpr size_t getElementCount(T (&)[sizeOfArray]) { + return sizeOfArray; +} + +static void callWithMemoryView(val v) { + // static so the JS test can read the memory after callTakeMemoryView runs + static unsigned char data[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; + v(memory_view(getElementCount(data), data)); + static float f[] = { 1.5f, 2.5f, 3.5f, 4.5f }; + v(typed_memory_view(getElementCount(f), f)); + static short s[] = { 1000, 100, 10, 1 }; + v(typed_memory_view(getElementCount(s), s)); +} + +EMSCRIPTEN_BINDINGS(memory_view_tests) { + function("callWithMemoryView", &callWithMemoryView); +} + class HasExternalConstructor { public: HasExternalConstructor(const std::string& str) |