lua with chinese character set

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

lua with chinese character set

mos-4


Hi!
        �\ is a character character

        print('�\')
        --out
        unfinished string near ''?)'

        print(string.byte([[�\]],1,2))
        -- out
        179 92

        92 = '\\' so lua report error

        I add some code at the llex.c line 278
          while (ls->current != del) {
        +  if (ls->current >= 128) { //a chinese character
        +  save_and_next(ls);
        +  save_and_next(ls);
        +  continue;}
            switch (ls->current) {

        and it seems ok now . am I right ? or any better suggestion ?

mos


Reply | Threaded
Open this post in threaded view
|

Re: lua with chinese character set

David Given
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

mos wrote:
[...]
> print(string.byte([[砛]],1,2))
> -- out
> 179 92

Yes, patching the parser is perfectly feasible, but Lua fundamentally
likes encodings that degrade gracefully into ASCII --- so if you were to
use an encoding such as UTF-8 rather than GB2312 it might make your life
easier. (Because all non-ASCII UTF-8 characters turn into strings of
high-bit bytes, which Lua will quietly pass through unchanged. You don't
need to special-case them the way you have to with GB2312.)

- --
+- David Given --McQ-+
|  [hidden email]    | "Those that repeat truisms, are also forced to
| ([hidden email]) | repeat them." --- Anonymous from Slashdot
+- www.cowlark.com --+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFER2Akf9E0noFvlzgRAhjmAJ9t1sfnd3PU6U3It9lLJ/H8O/dTuQCdGd4Q
94iFHxNwtZVLZ53nsOCkUl4=
=xOLD
-----END PGP SIGNATURE-----
Reply | Threaded
Open this post in threaded view
|

Re: lua with chinese character set

Luiz Henrique de Figueiredo
In reply to this post by mos-4
>or any better suggestion ?

Try to avoid the '...' or "..." variants for strings containing Chinese
characters :-) In this case, stick to [[...]], unless some other character
breaks that :-(