wstring in luabind via LuaPlus

View: New views
2 Messages — Rating Filter:   Alert me  

wstring in luabind via LuaPlus

by Daniel Wyatt :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I need to use wstring in luabind.
I've read this isn't really possible but I thought it may be with LuaPlus.
But i'm having problems.

First, to be clear, here is an example of what I wish to do:
~C++~
void printString(wstring s)
{
    //do something
}

int main(int argc, char *argv[])
{
        lua_State* luaState = lua_open();
        luaopen_base(luaState);
        luaopen_string(luaState);
        luaopen_wstring(luaState);
        luabind::open(luaState);

        luabind::module(luaState)
                [
                        luabind::def("printString", printString)
                ];

        luaL_dofile(luaState, "Script.lua");
        luabind::call_function<void>(luaState, "Test");
}
~Lua~
function Test()
printString(L"Test string");
end

But i'll get an error like this when running that script:
no match for function call 'printString' with the parameters (wstring)
candidates are:
printString(custom [class std::basic_string<wchar_t,struct
std::char_traits<wchar_t>,class std::allocator<wchar_t> >])

I just don't know what to do from here.
I've searched through the code for luabind and LuaPlus for hours but I
can't find the problem.
Can anyone point me in the right direction?

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
luabind-user mailing list
luabind-user@...
https://lists.sourceforge.net/lists/listinfo/luabind-user

Re: wstring in luabind via LuaPlus

by Enno Rehling :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Daniel Wyatt wrote:
> I need to use wstring in luabind.
> I've read this isn't really possible but I thought it may be with LuaPlus.

I don't think that'll work. There's no lua datatype tht wstring would
naturally translate to. Generally, wchar_t is a portability liability -
it's not the same size on all platforms, it's not equally supported
everywhere, etc., etc.

For unicode, I use regular char * or string satatypes that contain UTF8
data, and when an API I'm using requires 2-byte characters (Windows GUI
libraries for example) I convert from the UTF8 source strings and back.
I find that as long as you know at which level in your code's
architecture you use what, and don't get your encodings mixed up, it's
not an issue to use more than one.

Enno.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
luabind-user mailing list
luabind-user@...
https://lists.sourceforge.net/lists/listinfo/luabind-user
LightInTheBox - Buy quality products at wholesale price!