diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-12-10 13:46:03 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-12-10 13:46:03 -0200 |
commit | 46beca5bed8a7700b18100fe48a78373be5055f9 (patch) | |
tree | 499de35c048605434d9adb7ace964adf673041ac /lauxlib.c | |
parent | 28d829c86712ce5bc453feccc5129a32f78d80c0 (diff) | |
download | lua-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.c')
-rw-r--r-- | lauxlib.c | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -185,7 +185,7 @@ LUALIB_API int luaL_argerror (lua_State *L, int arg, const char *extramsg) { | |||
185 | } | 185 | } |
186 | 186 | ||
187 | 187 | ||
188 | static int typeerror (lua_State *L, int arg, const char *tname) { | 188 | int luaL_typeerror (lua_State *L, int arg, const char *tname) { |
189 | const char *msg; | 189 | const char *msg; |
190 | const char *typearg; /* name for the type of the actual argument */ | 190 | const char *typearg; /* name for the type of the actual argument */ |
191 | if (luaL_getmetafield(L, arg, "__name") == LUA_TSTRING) | 191 | if (luaL_getmetafield(L, arg, "__name") == LUA_TSTRING) |
@@ -200,7 +200,7 @@ static int typeerror (lua_State *L, int arg, const char *tname) { | |||
200 | 200 | ||
201 | 201 | ||
202 | static void tag_error (lua_State *L, int arg, int tag) { | 202 | static void tag_error (lua_State *L, int arg, int tag) { |
203 | typeerror(L, arg, lua_typename(L, tag)); | 203 | luaL_typeerror(L, arg, lua_typename(L, tag)); |
204 | } | 204 | } |
205 | 205 | ||
206 | 206 | ||
@@ -339,7 +339,7 @@ LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) { | |||
339 | 339 | ||
340 | LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { | 340 | LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { |
341 | void *p = luaL_testudata(L, ud, tname); | 341 | void *p = luaL_testudata(L, ud, tname); |
342 | if (p == NULL) typeerror(L, ud, tname); | 342 | luaL_argexpected(L, p != NULL, ud, tname); |
343 | return p; | 343 | return p; |
344 | } | 344 | } |
345 | 345 | ||