Skip to content

string scape must be integer #1652

@RodrigoDornelles

Description

@RodrigoDornelles

If we are going to use hex escapes or even special characters like ã, á, à in TypeScript targeting Lua, it is important that they are escaped in Lua 5.1’s decimal escape format (\ddd) for better compatibility. This is because Lua 5.1 does not support hexadecimal escapes, and using decimal escapes is the best way to correctly represent UTF-8 bytes.

Currently, even if characters are escaped in hex in TypeScript, they remain special characters in Lua, which can cause compatibility issues and incorrect string interpretation.

typescript

console.log('atenção')
console.log('aten\xC3\xA7\xC3\xA3o')

lua (current)

print('atenção')
print('atenção')

lua (proposal)

print('aten\195\167\195\163o')
print('aten\195\167\195\163o')

As a practical example, I have created a JavaScript tool that performs this conversion and that I use daily for Lua 5.1 string escaping:

https://gly-engine.github.io/tool-lua51-text-escape

I would like to open a GitHub issue to have this considered and fixed, since it affects portability and proper UTF-8 string handling when converting TS code to Lua 5.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions