Better error messages for some polymorphic functions

New auxiliary functions/macros 'luaL_argexpected'/'luaL_typeerror'
ease the creation of error messages such as

  bad argument #2 to 'setmetatable' (nil or table expected, got boolean)

(The novelty being the "got boolean" part...)
This commit is contained in:
Roberto Ierusalimschy
2018-12-10 13:46:03 -02:00
parent 28d829c867
commit 46beca5bed
7 changed files with 41 additions and 12 deletions

View File

@@ -857,9 +857,9 @@ static int str_gsub (lua_State *L) {
lua_Integer n = 0; /* replacement count */
MatchState ms;
luaL_Buffer b;
luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING ||
luaL_argexpected(L, tr == LUA_TNUMBER || tr == LUA_TSTRING ||
tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3,
"string/function/table expected");
"string/function/table");
luaL_buffinit(L, &b);
if (anchor) {
p++; lp--; /* skip anchor character */