Re: Binding wstring
Łukasz Wołowiec <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <19F3E61F0A28414A84A43B0F370A2ABC1A85E78EF9@arcaWay.arcadiasoft.local> |
> Does luabind support binding of wstring?
You can do it by overloading luabind::default_converter for that. Mine solution below. Non-listed 'Widen' and 'Narrow' functions, are here to handle wide-string conversion to 8-bit lua strings.
namespace luabind
{
template <>
struct default_converter< std::wstring >
: native_converter_base< std::wstring >
{
static int compute_score( lua_State * s, int index )
{
return lua_type( s, index ) == LUA_TSTRING ? 0 : -1;
}
std::wstring from( lua_State * s, int index )
{
return StrUtils::Widen( lua_tostring( s, index ) );
}
void to( lua_State * s, const std::wstring & str )
{
lua_pushstring( s, StrUtils::Narrow( str ).c_str( ) );
}
};
/**/
template <>
struct default_converter< const std::wstring >
: default_converter< std::wstring >
{ };
template <>
struct default_converter< const std::wstring & >
: default_converter< std::wstring >
{ };
}
Łukasz Wołowiec
Architekt aplikacji | Dział rozwoju oprogramowania
tel: +48 426891126,
e-mail: [email protected]
----------------------------------------------------------------------------------
ArCADiasoft, 90-057 Łódź, ul. Sienkiewicza 85/87
tel.: +48 42 6891111, fax: +48 426891100, www.ArCADiasoft.pl
---------------------------------------------------------------------------------
www.arcadiasoft.pl | www.intersoft.pl | www.arcadiapress.pl
------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in
Real-Time with Splunk. Collect, index and harness all the fast moving IT data
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business
insights. http://p.sf.net/sfu/splunk-dev2dev