Search code examples
unicodelua

How to write a unicode symbol in lua


How can I write a Unicode symbol in lua. For example I have to write symbol with 9658
when I write

string.char( 9658 );

I got an error. So how is it possible to write such a symbol.


Solution

  • Lua does not look inside strings. So, you can just write

    mychar = "►"
    

    (added in 2015)

    Lua 5.3 introduced support for UTF-8 escape sequences:

    The UTF-8 encoding of a Unicode character can be inserted in a literal string with the escape sequence \u{XXX} (note the mandatory enclosing brackets), where XXX is a sequence of one or more hexadecimal digits representing the character code point.

    You can also use utf8.char(9658).