Binding wstring

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Binding wstring

Kristoffer Danielsson
Does luabind support binding of wstring?
 
I know lua does not support unicode strings, but I think wstrings should be bound as byte arrays. This way, wstrings could be sent back and forth between C++ and Lua:
 
function foo(wstringFromCPP)
    CppFunction(wstringFromCPP)
end
 
Sure, patterns and stuff would not work, but it's a start...
 
Thanks

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Binding wstring

Łukasz Wołowiec
> 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: [hidden email]

----------------------------------------------------------------------------------
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 
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Binding wstring

Kristoffer Danielsson
Very nice! Will try it soon. Thanks a lot! :)
 
> From: [hidden email]

> To: [hidden email]
> Date: Thu, 24 Feb 2011 14:55:13 +0100
> Subject: Re: [luabind] Binding wstring
>
> > 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: [hidden email]
>
> ----------------------------------------------------------------------------------
> 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
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user

------------------------------------------------------------------------------
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 
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user