diff options
author | Chad Austin <chad@imvu.com> | 2013-04-10 23:59:51 -0700 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-18 20:08:09 +0300 |
commit | 6a4574cfe44b75f8cfaa916a08b402f99baf6cc7 (patch) | |
tree | b9bb8c88e5ce73bddcd96da4897eab07d91ed59c /system | |
parent | bcf017994524b515274344dcf667dc03b8153448 (diff) |
Add support for returning std::wstring
Diffstat (limited to 'system')
-rwxr-xr-x | system/include/emscripten/bind.h | 7 | ||||
-rwxr-xr-x | system/include/emscripten/wire.h | 20 | ||||
-rwxr-xr-x | system/lib/embind/bind.cpp | 21 |
3 files changed, 46 insertions, 2 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index 73a8d4da..9b6e69c9 100755 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -47,10 +47,15 @@ namespace emscripten { TYPEID floatType, const char* name); - void _embind_register_cstring( + void _embind_register_std_string( TYPEID stringType, const char* name); + void _embind_register_std_wstring( + TYPEID stringType, + size_t charSize, + const char* name); + void _embind_register_emval( TYPEID emvalType, const char* name); diff --git a/system/include/emscripten/wire.h b/system/include/emscripten/wire.h index 64114491..0e8334e8 100755 --- a/system/include/emscripten/wire.h +++ b/system/include/emscripten/wire.h @@ -181,6 +181,26 @@ namespace emscripten { } }; + template<> + struct BindingType<std::wstring> { + typedef struct { + size_t length; + wchar_t data[1]; // trailing data + }* WireType; + static WireType toWireType(const std::wstring& v) { + WireType wt = (WireType)malloc(sizeof(size_t) + v.length() * sizeof(wchar_t)); + wt->length = v.length(); + wmemcpy(wt->data, v.data(), v.length()); + return wt; + } + static std::wstring fromWireType(WireType v) { + return std::wstring(v->data, v->length); + } + static void destroy(WireType v) { + free(v); + } + }; + template<typename T> struct BindingType<const T> : public BindingType<T> { }; diff --git a/system/lib/embind/bind.cpp b/system/lib/embind/bind.cpp index deb55138..6cacf1e2 100755 --- a/system/lib/embind/bind.cpp +++ b/system/lib/embind/bind.cpp @@ -44,6 +44,24 @@ namespace emscripten { }
}
+// TODO: fix in library.js or a proper emscripten libc
+extern "C" wchar_t *wmemset(wchar_t *dest, wchar_t c, size_t count) {
+ wchar_t *o = dest;
+ while (count--) {
+ *o++ = c;
+ }
+ return dest;
+}
+
+// TODO: fix in library.js or a proper emscripten libc
+extern "C" wchar_t *wmemcpy(wchar_t *dest, const wchar_t *src, size_t count) {
+ wchar_t *o = dest;
+ while (count--) {
+ *dest++ = *src++;
+ }
+ return dest;
+}
+
EMSCRIPTEN_BINDINGS(native_and_builtin_types) {
using namespace emscripten::internal;
@@ -64,6 +82,7 @@ EMSCRIPTEN_BINDINGS(native_and_builtin_types) { _embind_register_float(TypeID<float>::get(), "float");
_embind_register_float(TypeID<double>::get(), "double");
- _embind_register_cstring(TypeID<std::string>::get(), "std::string");
+ _embind_register_std_string(TypeID<std::string>::get(), "std::string");
+ _embind_register_std_wstring(TypeID<std::wstring>::get(), sizeof(wchar_t), "std::wstring");
_embind_register_emval(TypeID<val>::get(), "emscripten::val");
}
|