aboutsummaryrefslogtreecommitdiff
path: root/lbaselib.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 /lbaselib.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 'lbaselib.c')
-rw-r--r--lbaselib.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/lbaselib.c b/lbaselib.c
index e776c2a2..201c93e3 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -125,8 +125,7 @@ static int luaB_getmetatable (lua_State *L) {
125static int luaB_setmetatable (lua_State *L) { 125static 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
146static int luaB_rawlen (lua_State *L) { 145static 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}