Unicode 識別字

lua-users home
wiki

Lua 中 Unicode 文字的平台獨立方法。

沒有此變更的情況

將這段內容新增到 [在地設定](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 的一般資訊,請參閱


最近的變更 · 喜好設定
編輯 · 歷程
最後編輯時間為 2018 年 2 月 22 日,早上 5:49 (GMT) (比較)