lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


2015-01-12 5:50 GMT+02:00 tjhack <tjhack@foxmail.com>:

> I convert some lua script(it contains chinese character) from simplified
> chinese to traditional chinese, and now the chinese character is encoding
> with cp950.
>
> Now I switch my win7 machine locale to zh_TW, and restart. Everything seems
> okay, the script with traditional chinese character is correct displayed.
>
> But when I complied these script.It is error.Invalid escape string.
>
> for example:
>
> msg="外功系普攻攻擊"
> print(msg)
>
> the result is:
>
> 外巨t普攻攻擊

If I run your code by the interactive interpreter under Ubuntu,
I get this:

$ LANG="zh_TW" lua5.1
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> g3;ff.f;;f
stdin:1: '=' expected near ';'

I.e. the input is already mangled by the reader.

However, if I save the code to a file, and then run it, it is fine:

$ LANG="zh_TW" lua5.1 < /tmp/chinese.lua
外功系普攻攻擊

Interestingly, for LuaJIT the interactive interpreter also works.
Can the culprit be the readline library (not a default option for
LuaJIT)? Let's try. Remove the line
"#define LUA_USE_READLINE"
from luaconf.h and recompile.

lua-5.1-noreadline$ LANG="zh_TW" src/lua
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> msg="外功系普攻攻擊"
> print(msg)
外功系普攻攻擊

Yes!

But under Windows LUA_USE_READLINE is anyway not defined.
We must look for something else.

What happens under Windows if you run the program
as a script file instead of interactively?