aboutsummaryrefslogtreecommitdiff
path: root/lauxlib.c
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.c
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.c')
-rw-r--r--lauxlib.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/lauxlib.c b/lauxlib.c
index fd4acbd1..769586b6 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -185,7 +185,7 @@ LUALIB_API int luaL_argerror (lua_State *L, int arg, const char *extramsg) {
185} 185}
186 186
187 187
188static int typeerror (lua_State *L, int arg, const char *tname) { 188int 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
202static void tag_error (lua_State *L, int arg, int tag) { 202static 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
340LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { 340LUALIB_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