Inconsistent handling of invalid escape sequences

55 views
Skip to first unread message

Martin Eden

unread,
Aug 8, 2026, 8:10:06 AM (5 days ago) Aug 8
to lu...@googlegroups.com
Invalid characters after backslash are accepted in Lua command-line
interpreter but rejected when compiling code:

  Lua 5.5.1  Copyright (C) 1994-2026 Lua.org, PUC-Rio
  > print('\\c')
  \c
  > load('print("\\c")')
  nil [string "print("\c")"]:1: invalid escape sequence near '"\c'

Is there official policy for them?

-- Martin

Martin Eden

unread,
Aug 8, 2026, 8:13:58 AM (5 days ago) Aug 8
to lu...@googlegroups.com
Sorry for noise. My bad.

On 2026-08-08 14:09, 'Martin Eden' via lua-l wrote:
>   > print('\\c')

Should be

  > print('\c')
  stdin:1: invalid escape sequence near ''\c'

Which give expected error.

-- Martin


Spar

unread,
Aug 8, 2026, 8:16:26 AM (5 days ago) Aug 8
to lu...@googlegroups.com
You need to escape twice.
In the command line it interpreted as you type, but in load you wrapped string into a string. You need to escape the escape in order to preserve it in parsing.
 
"\\c" -> \c
'"\\c"' -> "\c"
'"\\\\c"' -> "\\c" -> \c
--
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lua-l+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/lua-l/063f43a8-5001-47dc-8337-d749193cb73a%40disroot.org.
Reply all
Reply to author
Forward
0 new messages