|
Something is terribly wrong with al_ustr_new() |
Aikei_c
Member #14,871
January 2013
|
I now work on a project which loads allegro unicode strings from lua script. It goes like this: first a function in lua creates strings, then it passes an array of these strings to c++ code which places them into a vector for later use.
1function CreateStrings(lang)
2 lang = lang or "english"
3 local strings = { }
4 if (lang == "english") then
5 strings =
6 {
7 "Select Class",
8 "Edit Class"
9 }
10 end
11
12 if (lang == "russian") then
13 strings =
14 {
15 "Выбор класса",
16 "Редактирование класса"
17 }
18 end
19 return strings
20end
21
22function GetStrings()
23 local strings = CreateStrings("russian")
24 return strings
25end
As you can see, it creates an array of strings either in Russian or in English. Then it gets passed to the c++ code here: 2void CPlGameView::LoadStringsFromLua()
3{
4 ALLEGRO_USTR* str;
5 LuaFunction<LuaObject> GetStrings = LuaManager.GetGlobalState()->GetGlobal("GetStrings");
6 LuaObject luaStrings = GetStrings();
7 for (int i = 0; i < STRID_LAST_ID; i++)
8 {
9 const char* ch;
10 ch = luaStrings[i+1].GetString();
11 strings.push_back(al_ustr_new(ch));
12 }
13}
These strings should be window titles. However, when I later try to display the text with al_draw_ustr:
I get empty window titles when choosing russian. Everything displays fine if I choose English. Look attachements.
- the situation is the same. No text. On the other hand, everything is again fine with literal string in english is used. So, maybe al_draw_ustr is to blame? No. I wrote code loading ALLEGRO_USTR right from a file without using al_ustr_new():
5bool CPlGameView::LoadStrings(const char* lang)
6{
7 ALLEGRO_USTR* str;
8 ALLEGRO_FILE* langfile;
9 if (strcmp(lang,"russian") == 0)
10 {
11 langfile = al_fopen("rus.l","r");
12 }
13 else
14 if (strcmp(lang,"english") == 0)
15 langfile = al_fopen("eng.l","r");
16 else
17 {
18 WRITE_VIEWLOG("error: wrong language file name!");
19 return false;
20 }
21
22 str = al_fget_ustr(langfile);
23 while (!al_feof(langfile))
24 {
25 str = al_fget_ustr(langfile);
26 al_ustr_rtrim_ws(str);
27 strings.push_back(str);
28 }
29 al_fclose(langfile);
30 return true;
31}
which loads russian text. Then this text gets displayed with al_draw_ustr() just fine. So, there is either a bug here with loading multibyte utf-8 characters with al_ustr_new(), or I am doing something wrong, which you probably can explain to me. Thank you for you patience if you read to the end |
Arthur Kalliokoski
Second in Command
February 2005
|
Usually these types of problems are caused by your source code editor not saving files as proper UTF8. They all watch too much MSNBC... they get ideas. |
Aikei_c
Member #14,871
January 2013
|
You know, I just checked it and it seems you were right. Thsnks. |
|