浏览代码

Detail

Slightly better error message for invalid conversions in 'string.format'.
Roberto Ierusalimschy 6 年之前
父节点
当前提交
da37ac9c78
共有 2 个文件被更改,包括 2 次插入3 次删除
  1. 1 2
      lstrlib.c
  2. 1 1
      testes/strings.lua

+ 1 - 2
lstrlib.c

@@ -1180,8 +1180,7 @@ static int str_format (lua_State *L) {
           break;
           break;
         }
         }
         default: {  /* also treat cases 'pnLlh' */
         default: {  /* also treat cases 'pnLlh' */
-          return luaL_error(L, "invalid option '%%%c' to 'format'",
-                               *(strfrmt - 1));
+          return luaL_error(L, "invalid conversion '%s' to 'format'", form);
         }
         }
       }
       }
       lua_assert(nb < MAX_ITEM);
       lua_assert(nb < MAX_ITEM);

+ 1 - 1
testes/strings.lua

@@ -302,7 +302,7 @@ check("%100.3d", "too long")
 check("%1"..aux..".3d", "too long")
 check("%1"..aux..".3d", "too long")
 check("%1.100d", "too long")
 check("%1.100d", "too long")
 check("%10.1"..aux.."004d", "too long")
 check("%10.1"..aux.."004d", "too long")
-check("%t", "invalid option")
+check("%t", "invalid conversion")
 check("%"..aux.."d", "repeated flags")
 check("%"..aux.."d", "repeated flags")
 check("%d %d", "no value")
 check("%d %d", "no value")