Re: Implicit conversion : const char * -> QString

Łukasz Wołowiec <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <19F3E61F0A28414A84A43B0F370A2ABC0FA57AF775@arcaWay.arcadiasoft.local>
> Does luabind provide such implicit conversion ?

Yes, but with a little help. You should overload luabind::default_converter for that. For example, this is mine that I wrote to support std::wstring conversion. Just ignore that 'Widen' and 'Narrow' thing, it's just my handling of wide-string conversion to 8-bit lua strings. I think adding the support for QString will be similar.

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 >
		{ };
}


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.