|
From: Victor B. <so...@te...> - 2015-03-02 09:59:03
|
This is lua2wx, it seems that it takes utf8 strings instead or ANSI with
local codepage
WXLUA_USE_WXSTR_CONVCURRENT 1 should be tried?
------------------------------------------------------------
#define WXLUA_USE_WXSTR_CONVUTF8 1
#define WXLUA_USE_WXSTR_CONVCURRENT 0
// Convert a 8-bit ANSI C Lua String into a wxString
inline WXDLLIMPEXP_WXLUA wxString lua2wx(const char* luastr)
{
if (luastr == NULL) return wxEmptyString; // check for NULL
#if WXLUA_USE_WXSTR_CONVUTF8
return wxString(luastr, wxConvUTF8);
#elif WXLUA_USE_WXSTR_CONVCURRENT
return wxString(luastr, *wxConvCurrent);
#else //!WXLUA_USE_WXSTR_CONVCURRENT
#if wxUSE_UNICODE
wxString str(luastr, wxConvUTF8);
#else
wxString str(wxConvUTF8.cMB2WC(luastr), *wxConvCurrent);
#endif // wxUSE_UNICODE
if (str.IsEmpty())
str = wxConvertMB2WX(luastr); // old way that mostly works
return str;
#endif //WXLUA_USE_WXSTR_CONVCURRENT
}
--------------------------------------------------------------
As an example compare wxLua with iconv:
It seems wxLua dont take ANSI but UTF-8
--------------------------------------------------
local iconv = require("iconv")
oldprint = print
require"wx"
print=oldprint
local str = ""
for i=0,255 do
str = str .. string.char(i)
end
local cd = iconv.new("utf-8" .. "//TRANSLIT", "iso-8859-1")--IGNORE
--local cd = iconv.new("iso-8859-1" .. "//TRANSLIT", "utf-8")
assert(cd, "Failed to create a converter object.")
function showerr(err)
if err == iconv.ERROR_INCOMPLETE then
print("ERROR: Incomplete input.")
elseif err == iconv.ERROR_INVALID then
print("ERROR: Invalid input.")
elseif err == iconv.ERROR_NO_MEMORY then
print("ERROR: Failed to allocate memory.")
elseif err == iconv.ERROR_UNKNOWN then
print("ERROR: There was an unknown error.")
end
end
for i=1,#str do
local char = tostring(str:byte(i))
--ANSI to UTF8
local conv ,err= cd:iconv(str:sub(i,i))
showerr(err)
print(str:byte(i) , conv:byte(1,#conv))
--ANSI to UTF8 in wx
local convwx = wx.wxString(str:sub(i,i)):GetData()
print(str:byte(i) , convwx:byte(1,#convwx))
--UTF8 to UTF8 in wx
local convwx2 = wx.wxString(conv):GetData()
print(str:byte(i) , convwx2:byte(1,#convwx2))
end
|