Unicode 識別字 |
|
沒有此變更的情況
char
-> wchar_t
)時會有額外的負擔。此外,Lua 的大部分必須變更為使用 TCHAR 和相關函式。_G["some utf8 characters"]
(這樣做可行,但很繁瑣)將這段內容新增到 [在地設定](luaconf.h) 區段
#ifdef LUA_CORE // all utf-8 chars are always alphabetic character (everything higher then // 2^7 is always a valid char), end of stream (-1) is not valid #define isalpha(zeich) (((0x80&zeich)||isalpha(zeich))&&zeich!=-1) // all utf-8 chars are always alphabetic character or numbers, end of // stream (-1) is not valid #define isalnum(zeich) (((0x80&zeich)||isalnum(zeich))&&zeich!=-1) // all utf-8 chars are never numbers, end of stream (-1) is not valid #define isdigit(zeich) ((!(0x80&zeich)&&isdigit(zeich))&&zeich!=-1) // all utf-8 chars are never whitespace characters, end of stream (-1) is // not valid #define isspace(zeich) ((!(0x80&zeich)&&isspace(zeich))&&zeich!=-1) #endif
請注意,所有 Unicode 字元都將被允許。(這可能是一個問題,因為有些字元看起來與 Lua 關鍵字、運算子及空白很相似。)
然後重新編譯 Lua 並嘗試以下範例
local function Gr��e(message) print(message) end Gr��eAusDeutschland = "Hallo Welt ����" -- As you see we are using a global variable with UTF-8 characters Gr��e(Gr��eAusDeutschland) -- call to local function with UTF-8 characters -- Please add other Language samples here ;) -- Just to prove my point some google translate gibberish: 日本からのご挨拶 = "ハローワールド" -- japanese Gr��e(日本からのご挨拶)
HendrikPolczynski 2009-11-20 - 第一次校訂
如需 Unicode 字串支援和驗證,請參閱
如需 Lua 中 Unicode 的一般資訊,請參閱