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...) --- lauxlib.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lauxlib.h') diff --git a/lauxlib.h b/lauxlib.h index 9ec0f531..e5d378ae 100644 --- a/lauxlib.h +++ b/lauxlib.h @@ -48,6 +48,7 @@ LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len); LUALIB_API int (luaL_argerror) (lua_State *L, int arg, const char *extramsg); +LUALIB_API int (luaL_typeerror) (lua_State *L, int arg, const char *tname); LUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg, size_t *l); LUALIB_API const char *(luaL_optlstring) (lua_State *L, int arg, @@ -126,6 +127,10 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname, #define luaL_argcheck(L, cond,arg,extramsg) \ ((void)((cond) || luaL_argerror(L, (arg), (extramsg)))) + +#define luaL_argexpected(L,cond,arg,tname) \ + ((void)((cond) || luaL_typeerror(L, (arg), (tname)))) + #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) -- cgit v1.2.3-55-g6feb