lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,
           I was trying to find out an equivalent to the python encode function. For example when I start Python 3.8 on windows cmd shell and I do:

a = "pythön!"
a.encode("utf-8")

it generates:
b'pyth\xc3\xb6n!'

I was looking into the utf8 library in Lua. So in the windows cmd shell if I do:
utf8.codepoint("pythön!",1,-1)

I get: 
stdin:1: invalid UTF-8 code
stack traceback:
        [C]: in function 'utf8.codepoint'
        stdin:1: in main chunk
        [C]: in ?

After some searching I found the command chcp and I start a new cmd and run the command:
chcp 65001
and then run Lua and do
  utf8.codepoint("pythön!",1,-1) 

this it takes as an incomplete statement. It says:
stdin:1: unfinished string near '"pyth'

How can I emulate the python encode function? 
Why does that work on the windows cmd and utf8.codepoint does not? 

Thanks,
Milind