I have this legacy code snippet, which (apparently) decodes double-encoded UTF-8 text back to normal UTF-8:
# Run with python3!
import codecs
import sys
s=codecs.open('doubleutf8.dat', 'r', 'utf-8').read()
sys.stdout.write(
s
.encode('raw_unicode_escape')
.decode('utf-8')
)
I need to translate it to Lua, and imitate all possible decoding side-effects (if any).
Limitations: I may use any of available Lua modules for UTF-8 handling, but preferably the stable one, with LuaRocks support. I will not use Lupa or other Lua-Python bridging solution, neither will I call os.execute()
to invoke Python.