Reputation: 2926
I downloaded the latest binary for Windows of LUA 5.4.0, through the official source.
When using the live demo if I write the following code :
print(string.byte("§",1))
print(string.byte("§",2))
It returns
194
167
However, if I use the windows binary :
PS C:\Users\200207121> lua54
Lua 5.4.0 Copyright (C) 1994-2020 Lua.org, PUC-Rio
> print(string.byte("§",1)); print(string.byte("§",2))
It returns
245
>
Both the live demo and my installation use LUA 5.4.0. There is no other LUA libraries installed on my system.
Why do the outputs differ ?
Upvotes: 1
Views: 94
Reputation: 13207
§ (U+00A7) is a non-ASCII character, thus its encoding can differ between platforms.
There is no difference between the binaries; the web version simply uses UTF-8 for input. Lua strings are encoding-agnostic, so it will simply treat the characters you input as bytes (0xC2 0xA7).
Your terminal where you run Lua uses an old (single-byte) OEM code page, where § is 0xF5, hence the single byte. Lua again simply treats your input as bytes, and it only displays what you enter.
This has been true for all Lua versions.
Upvotes: 2