From 46beca5bed8a7700b18100fe48a78373be5055f9 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 10 Dec 2018 13:46:03 -0200 Subject: 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...) --- lbaselib.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lbaselib.c') diff --git a/lbaselib.c b/lbaselib.c index e776c2a2..201c93e3 100644 --- a/lbaselib.c +++ b/lbaselib.c @@ -125,8 +125,7 @@ static int luaB_getmetatable (lua_State *L) { static int luaB_setmetatable (lua_State *L) { int t = lua_type(L, 2); luaL_checktype(L, 1, LUA_TTABLE); - luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, - "nil or table expected"); + luaL_argexpected(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil or table"); if (luaL_getmetafield(L, 1, "__metatable") != LUA_TNIL) return luaL_error(L, "cannot change a protected metatable"); lua_settop(L, 2); @@ -145,8 +144,8 @@ static int luaB_rawequal (lua_State *L) { static int luaB_rawlen (lua_State *L) { int t = lua_type(L, 1); - luaL_argcheck(L, t == LUA_TTABLE || t == LUA_TSTRING, 1, - "table or string expected"); + luaL_argexpected(L, t == LUA_TTABLE || t == LUA_TSTRING, 1, + "table or string"); lua_pushinteger(L, lua_rawlen(L, 1)); return 1; } -- cgit v1.2.3-55-g6feb