From d00fef35c95285b05352757e512685e0dd657bbb Mon Sep 17 00:00:00 2001 From: Camilo Polymeris Date: Sat, 26 Apr 2014 23:01:07 -0300 Subject: Bind std::basic_string to js strings --- system/lib/embind/bind.cpp | 1 + tests/embind/embind.test.js | 15 +++++++++++++++ tests/embind/embind_test.cpp | 4 ++++ 3 files changed, 20 insertions(+) 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"); _embind_register_std_string(TypeID::get(), "std::string"); + _embind_register_std_string(TypeID >::get(), "std::basic_string"); _embind_register_std_wstring(TypeID::get(), sizeof(wchar_t), "std::wstring"); _embind_register_emval(TypeID::get(), "emscripten::val"); _embind_register_memory_view(TypeID::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", 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", 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", 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 emval_test_take_and_return_std_basic_string_unsigned_char(std::basic_string str) { + return str; +} + std::wstring take_and_return_std_wstring(std::wstring str) { return str; } -- cgit v1.2.3-18-g5258 From ef6e3bada9777e5bece9e0b5a6a96e5b80645845 Mon Sep 17 00:00:00 2001 From: Chad Austin Date: Sat, 26 Apr 2014 21:41:52 -0700 Subject: fix polymeris's tests --- tests/embind/embind_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp index 2b6a4d1b..5a83903a 100644 --- a/tests/embind/embind_test.cpp +++ b/tests/embind/embind_test.cpp @@ -1450,6 +1450,7 @@ EMSCRIPTEN_BINDINGS(tests) { //function("emval_test_take_and_return_const_char_star", &emval_test_take_and_return_const_char_star); function("emval_test_take_and_return_std_string", &emval_test_take_and_return_std_string); function("emval_test_take_and_return_std_string_const_ref", &emval_test_take_and_return_std_string_const_ref); + function("emval_test_take_and_return_std_basic_string_unsigned_char", &emval_test_take_and_return_std_basic_string_unsigned_char); function("take_and_return_std_wstring", &take_and_return_std_wstring); //function("emval_test_take_and_return_CustomStruct", &emval_test_take_and_return_CustomStruct); -- cgit v1.2.3-18-g5258 From 6c1b114fa5078dcac3f6617a6f890f0106fcf090 Mon Sep 17 00:00:00 2001 From: Camilo Polymeris Date: Tue, 29 Apr 2014 17:20:09 -0400 Subject: Add myself to AUTHORS --- AUTHORS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index c162103a..7994f80e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -137,4 +137,4 @@ a license to everyone to use it as detailed in LICENSE.) * Ori Avtalion * Guillaume Blanc * Usagi Ito - +* Camilo Polymeris -- cgit v1.2.3-18-g5258