def lua_bytes(text):
    """Convert some bytes into an escaped lua string literal."""
    out = b''
    for byte in text:
        byte = byte if isinstance(byte, int) else ord(byte)
        if byte == ord('\\'):
            out += b'\\\\'
        elif byte == ord("'"):
            out += b"\\'"
        elif 32 <= byte < 127:
            out += chr(byte).encode('ascii')
        else:
            out += '\\x{:02X}'.format(byte).encode('ascii')
    return b"'" + out + b"'"
