diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-11-10 16:06:10 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-11-10 16:06:10 -0200 |
| commit | 1b54197491f3305be08a5a77745865f268c790b5 (patch) | |
| tree | 8f469af3709fd7ae159f1180be3b9157a7663f65 | |
| parent | c97aa9485caf253eceebc00cf08cfa8b179fe35e (diff) | |
| download | lua-1b54197491f3305be08a5a77745865f268c790b5.tar.gz lua-1b54197491f3305be08a5a77745865f268c790b5.tar.bz2 lua-1b54197491f3305be08a5a77745865f268c790b5.zip | |
better error message when light userdata is used instead of a
full userdata
| -rw-r--r-- | ldblib.c | 13 |
1 files changed, 10 insertions, 3 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldblib.c,v 1.123 2010/07/02 11:38:13 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.124 2010/07/25 15:18:19 roberto Exp roberto $ |
| 3 | ** Interface from Lua to its debug API | 3 | ** Interface from Lua to its debug API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -44,15 +44,22 @@ static int db_setmetatable (lua_State *L) { | |||
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | 46 | ||
| 47 | static void checkudata (lua_State *L, int narg) { | ||
| 48 | if (lua_type(L, narg) == LUA_TLIGHTUSERDATA) | ||
| 49 | luaL_argerror(L, narg, "full userdata expected, got light userdata"); | ||
| 50 | luaL_checktype(L, narg, LUA_TUSERDATA); | ||
| 51 | } | ||
| 52 | |||
| 53 | |||
| 47 | static int db_getuservalue (lua_State *L) { | 54 | static int db_getuservalue (lua_State *L) { |
| 48 | luaL_checktype(L, 1, LUA_TUSERDATA); | 55 | checkudata(L, 1); |
| 49 | lua_getuservalue(L, 1); | 56 | lua_getuservalue(L, 1); |
| 50 | return 1; | 57 | return 1; |
| 51 | } | 58 | } |
| 52 | 59 | ||
| 53 | 60 | ||
| 54 | static int db_setuservalue (lua_State *L) { | 61 | static int db_setuservalue (lua_State *L) { |
| 55 | luaL_checktype(L, 1, LUA_TUSERDATA); | 62 | checkudata(L, 1); |
| 56 | if (!lua_isnoneornil(L, 2)) | 63 | if (!lua_isnoneornil(L, 2)) |
| 57 | luaL_checktype(L, 2, LUA_TTABLE); | 64 | luaL_checktype(L, 2, LUA_TTABLE); |
| 58 | lua_settop(L, 2); | 65 | lua_settop(L, 2); |
