How to print accents on Moon

I'm starting to learn Moon now, and I can't print accents

print("Olá mundo")

Returns

Olá mundo

In both VS Code terminal and powershell, is there a way to fix this?

 3
lua
Author: Márcio Levy, 2020-09-22

2 answers

Has to do with encoding - You can either create your Lua source file in the encoding used by the terminal - or use a terminal program that works with utf-8

On windows, one of the ways can be to use the 'terminal' application that you pick up from the official Windows Store. https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701?activetab=pivot:overviewtab

But more important than "make it work" - you need to understand what is coding of texts, if not you will be able to make programs that work cross-platform or exchange data with networked systems without destroying all accented characters.

A good read to understand this is this 2003 article by the creator of stackoverflow: http://augustoberziner.blogspot.com/2010/04/o-minimo-absoluto-que-cada.html .

[continuing] - once you understand this, and see the Lua documentation, you will see that the language actually works with "bytes": this is the text you appreciate in the source code it is considered "already encoded". In contrast to languages like Java or Python that have a more "chubby" runtime, and work with "Agnostic" text encoding, and can do the encoding transparently or explicitly when printing or writing to a file.

The implication of this is that the encoding that is used in the editor to write your code is always the same that will be used in printing. Your editor is set to utf-8 (let's know why clues like "each accented character turns two characters in the terminal"), but even if it were in the normal Windows encoding-latin-1 for Windows in Portuguese, it would still be different from the terminal encoding, which for historical reasons is CP-852 - that is, the accents would go wrong the same way.

In Lua, to be able to change the encoding, it has to be made use of an external library.

 3
Author: jsbueno, 2020-09-23 02:03:53

Is not quite an answer...

  • I suggest you install lua 5.3 (which has better unicode support)
  • on linux this runs perfectly. I do not use or know windows but:
    • I suggest you find a good terminal for windows (the line command Windows default is very old and lousy)
    • the general trend is to use unicode, allowing text with accents, mathematical characters, Greek, Russian symbols, etc. In windows you can configure the default encoding (via registry also you can configure encoding / locales even from the old command-line)

In Windows 10 I've managed to permanently solve this by going to the system's Language settings, selecting Administrative Language settings, clicking Change System locale... and checking the Beta: Use Unicode UTF-8 for worldwide language support box and then restarting my pc

 0
Author: JJoao, 2020-09-24 09:59:06