diff options
author | Camilo Polymeris <cpolymeris@gmail.com> | 2014-04-26 23:01:07 -0300 |
---|---|---|
committer | Camilo Polymeris <cpolymeris@gmail.com> | 2014-04-29 17:10:17 -0400 |
commit | d00fef35c95285b05352757e512685e0dd657bbb (patch) | |
tree | 5a6e313cc176c538287daa7026848ef050ca3135 | |
parent | d5cf59ac87b14eee47e229fe0543c8faa27a2ff4 (diff) |
Bind std::basic_string<unsigned char> to js strings
-rw-r--r-- | system/lib/embind/bind.cpp | 1 | ||||
-rw-r--r-- | tests/embind/embind.test.js | 15 | ||||
-rw-r--r-- | tests/embind/embind_test.cpp | 4 |
3 files changed, 20 insertions, 0 deletions
diff --git a/system/lib/embind/bind.cpp b/system/lib/embind/bind.cpp index 37918050..16c24a91 100644 --- a/system/lib/embind/bind.cpp +++ b/system/lib/embind/bind.cpp @@ -78,6 +78,7 @@ EMSCRIPTEN_BINDINGS(native_and_builtin_types) { register_float<double>("double");
_embind_register_std_string(TypeID<std::string>::get(), "std::string");
+ _embind_register_std_string(TypeID<std::basic_string<unsigned char> >::get(), "std::basic_string<unsigned char>");
_embind_register_std_wstring(TypeID<std::wstring>::get(), sizeof(wchar_t), "std::wstring");
_embind_register_emval(TypeID<val>::get(), "emscripten::val");
_embind_register_memory_view(TypeID<memory_view>::get(), "emscripten::memory_view");
diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js index 6bba4de0..3ded811a 100644 --- a/tests/embind/embind.test.js +++ b/tests/embind/embind.test.js @@ -442,6 +442,21 @@ module({ var e = cm.emval_test_take_and_return_std_string((new Int8Array([65, 66, 67, 68])).buffer); assert.equal('ABCD', e); }); + + test("can pass Uint8Array to std::basic_string<unsigned char>", function() { + var e = cm.emval_test_take_and_return_std_basic_string_unsigned_char(new Uint8Array([65, 66, 67, 68])); + assert.equal('ABCD', e); + }); + + test("can pass Int8Array to std::basic_string<unsigned char>", function() { + var e = cm.emval_test_take_and_return_std_basic_string_unsigned_char(new Int8Array([65, 66, 67, 68])); + assert.equal('ABCD', e); + }); + + test("can pass ArrayBuffer to std::basic_string<unsigned char>", function() { + var e = cm.emval_test_take_and_return_std_basic_string_unsigned_char((new Int8Array([65, 66, 67, 68])).buffer); + assert.equal('ABCD', e); + }); test("non-ascii wstrings", function() { var expected = String.fromCharCode(10) + diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp index 1b835751..2b6a4d1b 100644 --- a/tests/embind/embind_test.cpp +++ b/tests/embind/embind_test.cpp @@ -109,6 +109,10 @@ std::string emval_test_take_and_return_std_string_const_ref(const std::string& s return str; } +std::basic_string<unsigned char> emval_test_take_and_return_std_basic_string_unsigned_char(std::basic_string<unsigned char> str) { + return str; +} + std::wstring take_and_return_std_wstring(std::wstring str) { return str; } |