From 1b54197491f3305be08a5a77745865f268c790b5 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 10 Nov 2010 16:06:10 -0200 Subject: [PATCH] better error message when light userdata is used instead of a full userdata --- ldblib.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ldblib.c b/ldblib.c index 3a773080..1127fbf2 100644 --- a/ldblib.c +++ b/ldblib.c @@ -1,5 +1,5 @@ /* -** $Id: ldblib.c,v 1.123 2010/07/02 11:38:13 roberto Exp roberto $ +** $Id: ldblib.c,v 1.124 2010/07/25 15:18:19 roberto Exp roberto $ ** Interface from Lua to its debug API ** See Copyright Notice in lua.h */ @@ -44,15 +44,22 @@ static int db_setmetatable (lua_State *L) { } +static void checkudata (lua_State *L, int narg) { + if (lua_type(L, narg) == LUA_TLIGHTUSERDATA) + luaL_argerror(L, narg, "full userdata expected, got light userdata"); + luaL_checktype(L, narg, LUA_TUSERDATA); +} + + static int db_getuservalue (lua_State *L) { - luaL_checktype(L, 1, LUA_TUSERDATA); + checkudata(L, 1); lua_getuservalue(L, 1); return 1; } static int db_setuservalue (lua_State *L) { - luaL_checktype(L, 1, LUA_TUSERDATA); + checkudata(L, 1); if (!lua_isnoneornil(L, 2)) luaL_checktype(L, 2, LUA_TTABLE); lua_settop(L, 2);