Sol2: Adding wide string support?

Created on 12 Aug 2016  路  7Comments  路  Source: ThePhD/sol2

Hello again. :)

In my application I tend to use a lot of national characters in wide character format, mainly in interface element placement. Apparently I cannot use methods that take a std::wstring or just const wchar_t * as LUA state just panics when I try to use them.

Basically I can have methods like:

void PrintWide(const wchar_t * characters)
{
    wprintf(L"%s", characters);
}

void PrintWideStr(std::wstring str)
{
    wprintf(L"%s", str.c_str());
}

And then call it from LUA like:

PrintWide("膮膷臋臈寞拧懦奴")
PrintWideStr("膮膷臋臈寞拧懦奴")

and it just fails with wrong userdata.

What are the solutions to add such support?

Thank you very much for such a great library, too. :)

Feature.Can Do Feature.Shiny

All 7 comments

Would #140 be helpful?

140 would be a one-person, one-time fix. I'm working on adding it in for everyone, albeit it's hard with codecvt and locales not always playing nice.

As a side note, wstring is not a Unicode string. You should be using std::u16string or std::u32string to handle localization. wstring is an implementation-defined string of wchar_t which can have any encoding that the implementation/locale sees fit.

Thanks for the sugestions. :) I might be too old-schooled at that. I will investigate both #140 and the u16/u32 strings for now. :)

Codecvt is a piece of shit: >:C

Support is in now: https://github.com/ThePhD/sol2/releases/tag/v2.11.3

The code you wrote at first should work.

Awesome! It does work. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

patlecat picture patlecat  路  7Comments

spin-scenario picture spin-scenario  路  5Comments

Moneyl picture Moneyl  路  10Comments

sagunkho picture sagunkho  路  4Comments

cgloeckner picture cgloeckner  路  3Comments