From b986ff832b43fb042fcd41fce4e7e5140c81a7f8 Mon Sep 17 00:00:00 2001 From: olsner Date: Thu, 5 Aug 2004 12:04:20 +0000 Subject: [PATCH] Some Linux wchar_t/jschar stuff.. JS uses UTF-16/UCS-2, so convert wchar strings before handing to JS unicode interfaces. This was SVN commit r902. --- source/simulation/EntityProperties.cpp | 2 +- source/simulation/scripting/JSInterface_Entity.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/source/simulation/EntityProperties.cpp b/source/simulation/EntityProperties.cpp index f37297d9bc..f5d49da501 100755 --- a/source/simulation/EntityProperties.cpp +++ b/source/simulation/EntityProperties.cpp @@ -115,7 +115,7 @@ void CBoundObjectProperty::set( const jsval value ) jsval CBoundObjectProperty::tojsval() { - return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( g_ScriptingHost.getContext(), m_String.c_str() ) ) ); + return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( g_ScriptingHost.getContext(), utf16().c_str() ) ) ); } CBoundObjectProperty::CBoundObjectProperty() diff --git a/source/simulation/scripting/JSInterface_Entity.cpp b/source/simulation/scripting/JSInterface_Entity.cpp index 9c3b4ba972..db57baadab 100755 --- a/source/simulation/scripting/JSInterface_Entity.cpp +++ b/source/simulation/scripting/JSInterface_Entity.cpp @@ -136,8 +136,10 @@ JSBool JSI_Entity::toString( JSContext* cx, JSObject* obj, uintN argc, jsval* ar HEntity* e = (HEntity*)JS_GetPrivate( cx, obj ); wchar_t buffer[256]; - _snwprintf( buffer, 256, L"[object Entity: \"%ls\" (%ls)]", (const wchar_t*)(*e)->m_name, (const wchar_t*)(*e)->m_base->m_name ); + swprintf( buffer, 256, L"[object Entity: \"%ls\" (%ls)]", (*e)->m_name.c_str(), (*e)->m_base->m_name.c_str() ); buffer[255] = 0; - *rval = STRING_TO_JSVAL( JS_NewUCStringCopyZ( cx, buffer ) ); + utf16_t utfbuf[256]; + std::copy(buffer, buffer+256, utfbuf); + *rval = STRING_TO_JSVAL( JS_NewUCStringCopyZ( cx, utfbuf ) ); return( JS_TRUE ); }