How to print accents in Lua

Asked

Viewed 93 times

3

I’m starting to learn moon now, and I can’t print accents

print("Olá mundo")

returns

Olá mundo

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

2 answers

4

It 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

in windows, one of the ways can be use the 'terminal' application that you take in 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 text coding is, otherwise you won’t be able to make programs that work Platform or exchange data with networked systems without destroying all accented characters.

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

[continue] - after you understand this, and see the documentation of the Moon, you will see that the language actually works with "bytes": this is the text that appears in the source code is considered "already encoded". In contrast to languages like Java or Python that have a more "chubby" Runtime, and work with "agnostic" text coding, and can do the coding 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 (you can tell by clues like "each accented character turns into two characters in the terminal") but even if it were in the normal Windows - latin-1 encoding for Windows in English, it would still be different from the terminal encoding, that for historical reasons is CP-852 - that is, the accents would go wrong in the same way.

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

0

It’s not really an answer...

  • I suggest you install the moon 5.3 (which has better support for Unicode)
  • In linux this runs perfectly. I do not use or know windows but:
    • I suggest you get a good terminal for windows (the line command Windows default is old and bad)
    • The general trend is to use Unicode, allowing text with accents, mathematical characters, Greek, Russian symbols, etc. In windows it is possible to configure the default encoding (via Registry also can be configured 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.