Skip to content

Instantly share code, notes, and snippets.

@PilzAdam
Created August 19, 2013 15:44
Show Gist options
  • Save PilzAdam/6270584 to your computer and use it in GitHub Desktop.
Save PilzAdam/6270584 to your computer and use it in GitHub Desktop.
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp
index 6417d1e..832069f 100644
--- a/src/script/lua_api/l_mainmenu.cpp
+++ b/src/script/lua_api/l_mainmenu.cpp
@@ -980,8 +980,15 @@ int ModApiMainMenu::l_download_file(lua_State *L)
int ModApiMainMenu::l_gettext(lua_State *L)
{
const char* str = luaL_checkstring(L, 1);
- str = gettext(str);
- lua_pushstring(L, str);
+
+ wchar_t *wideString = wgettext(str);
+
+ size_t len = wcslen(wideString);
+ size_t maxUtf8len = 4 * len + 1; // Each wchar_t encodes to a max of 4 bytes
+ char *utf8String = new char[maxUtf8len];
+ wcstombs(utf8String, wideString, maxUtf8len);
+
+ lua_pushstring(L, utf8String);
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment