aboutsummaryrefslogtreecommitdiff
path: root/lauxlib.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-12-10 13:46:03 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-12-10 13:46:03 -0200
commit46beca5bed8a7700b18100fe48a78373be5055f9 (patch)
tree499de35c048605434d9adb7ace964adf673041ac /lauxlib.h
parent28d829c86712ce5bc453feccc5129a32f78d80c0 (diff)
downloadlua-46beca5bed8a7700b18100fe48a78373be5055f9.tar.gz
lua-46beca5bed8a7700b18100fe48a78373be5055f9.tar.bz2
lua-46beca5bed8a7700b18100fe48a78373be5055f9.zip
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...)
Diffstat (limited to 'lauxlib.h')
-rw-r--r--lauxlib.h5
1 files changed, 5 insertions, 0 deletions
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);
48LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); 48LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
49LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len); 49LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);
50LUALIB_API int (luaL_argerror) (lua_State *L, int arg, const char *extramsg); 50LUALIB_API int (luaL_argerror) (lua_State *L, int arg, const char *extramsg);
51LUALIB_API int (luaL_typeerror) (lua_State *L, int arg, const char *tname);
51LUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg, 52LUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg,
52 size_t *l); 53 size_t *l);
53LUALIB_API const char *(luaL_optlstring) (lua_State *L, int arg, 54LUALIB_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,
126 127
127#define luaL_argcheck(L, cond,arg,extramsg) \ 128#define luaL_argcheck(L, cond,arg,extramsg) \
128 ((void)((cond) || luaL_argerror(L, (arg), (extramsg)))) 129 ((void)((cond) || luaL_argerror(L, (arg), (extramsg))))
130
131#define luaL_argexpected(L,cond,arg,tname) \
132 ((void)((cond) || luaL_typeerror(L, (arg), (tname))))
133
129#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) 134#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
130#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) 135#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
131 136