summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-10-10 19:23:04 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-10-10 19:23:04 -0300
commit56d45378796b881b638671655164a16bb8ad8a57 (patch)
tree45c72650efbf33f5e7f22697e26af29a3e469541
parent18014ef2fdffc6b7a1418ce3accecb273acc4b6d (diff)
downloadlua-56d45378796b881b638671655164a16bb8ad8a57.tar.gz
lua-56d45378796b881b638671655164a16bb8ad8a57.tar.bz2
lua-56d45378796b881b638671655164a16bb8ad8a57.zip
'$c' in 'lua_pushfstring' prints non-printable characters with
their codes
-rw-r--r--llex.c7
-rw-r--r--lobject.c7
2 files changed, 8 insertions, 6 deletions
diff --git a/llex.c b/llex.c
index 66a3e3c4..91de0ad8 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 2.80 2014/07/18 13:36:14 roberto Exp roberto $ 2** $Id: llex.c,v 2.81 2014/10/01 11:52:33 roberto Exp roberto $
3** Lexical Analyzer 3** Lexical Analyzer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -78,9 +78,8 @@ void luaX_init (lua_State *L) {
78 78
79const char *luaX_token2str (LexState *ls, int token) { 79const char *luaX_token2str (LexState *ls, int token) {
80 if (token < FIRST_RESERVED) { /* single-byte symbols? */ 80 if (token < FIRST_RESERVED) { /* single-byte symbols? */
81 lua_assert(token == cast(unsigned char, token)); 81 lua_assert(token == cast_uchar(token));
82 return (lisprint(token)) ? luaO_pushfstring(ls->L, LUA_QL("%c"), token) : 82 return luaO_pushfstring(ls->L, LUA_QL("%c"), token);
83 luaO_pushfstring(ls->L, "char(%d)", token);
84 } 83 }
85 else { 84 else {
86 const char *s = luaX_tokens[token - FIRST_RESERVED]; 85 const char *s = luaX_tokens[token - FIRST_RESERVED];
diff --git a/lobject.c b/lobject.c
index eb7cb28a..ebf3cf05 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 2.90 2014/10/01 11:52:33 roberto Exp roberto $ 2** $Id: lobject.c,v 2.91 2014/10/04 22:57:10 roberto Exp roberto $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -377,7 +377,10 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
377 } 377 }
378 case 'c': { 378 case 'c': {
379 char buff = cast(char, va_arg(argp, int)); 379 char buff = cast(char, va_arg(argp, int));
380 pushstr(L, &buff, 1); 380 if (lisprint(cast_uchar(buff)))
381 pushstr(L, &buff, 1);
382 else /* non-printable character; print its code */
383 luaO_pushfstring(L, "<\\%d>", cast_uchar(buff));
381 break; 384 break;
382 } 385 }
383 case 'd': { 386 case 'd': {