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 /lbaselib.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 'lbaselib.c')
-rw-r--r-- | lbaselib.c | 7 |
1 files changed, 3 insertions, 4 deletions
@@ -125,8 +125,7 @@ static int luaB_getmetatable (lua_State *L) { | |||
125 | static int luaB_setmetatable (lua_State *L) { | 125 | static int luaB_setmetatable (lua_State *L) { |
126 | int t = lua_type(L, 2); | 126 | int t = lua_type(L, 2); |
127 | luaL_checktype(L, 1, LUA_TTABLE); | 127 | luaL_checktype(L, 1, LUA_TTABLE); |
128 | luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, | 128 | luaL_argexpected(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil or table"); |
129 | "nil or table expected"); | ||
130 | if (luaL_getmetafield(L, 1, "__metatable") != LUA_TNIL) | 129 | if (luaL_getmetafield(L, 1, "__metatable") != LUA_TNIL) |
131 | return luaL_error(L, "cannot change a protected metatable"); | 130 | return luaL_error(L, "cannot change a protected metatable"); |
132 | lua_settop(L, 2); | 131 | lua_settop(L, 2); |
@@ -145,8 +144,8 @@ static int luaB_rawequal (lua_State *L) { | |||
145 | 144 | ||
146 | static int luaB_rawlen (lua_State *L) { | 145 | static int luaB_rawlen (lua_State *L) { |
147 | int t = lua_type(L, 1); | 146 | int t = lua_type(L, 1); |
148 | luaL_argcheck(L, t == LUA_TTABLE || t == LUA_TSTRING, 1, | 147 | luaL_argexpected(L, t == LUA_TTABLE || t == LUA_TSTRING, 1, |
149 | "table or string expected"); | 148 | "table or string"); |
150 | lua_pushinteger(L, lua_rawlen(L, 1)); | 149 | lua_pushinteger(L, lua_rawlen(L, 1)); |
151 | return 1; | 150 | return 1; |
152 | } | 151 | } |