From 2f2b4a42a95c7a96e5e16b74ba1167690fcd6231 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 17 Aug 2005 16:05:04 -0300 Subject: luaL_checkudata raises an error if value is not correct (like other luaL_check functions) --- lauxlib.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'lauxlib.c') diff --git a/lauxlib.c b/lauxlib.c index 93cbff51..a828e612 100644 --- a/lauxlib.c +++ b/lauxlib.c @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.c,v 1.143 2005/08/10 18:47:09 roberto Exp roberto $ +** $Id: lauxlib.c,v 1.144 2005/08/15 14:12:32 roberto Exp roberto $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -130,18 +130,19 @@ LUALIB_API void luaL_getmetatable (lua_State *L, const char *tname) { LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { - const char *tn; - if (!lua_getmetatable(L, ud)) return NULL; /* no metatable? */ - lua_rawget(L, LUA_REGISTRYINDEX); /* get registry[metatable] */ - tn = lua_tostring(L, -1); - if (tn && (strcmp(tn, tname) == 0)) { - lua_pop(L, 1); - return lua_touserdata(L, ud); - } - else { - lua_pop(L, 1); - return NULL; + void *p = NULL; + if (lua_getmetatable(L, ud)) { + const char *tn; + lua_rawget(L, LUA_REGISTRYINDEX); /* get registry[metatable] */ + tn = lua_tostring(L, -1); + if (tn && (strcmp(tn, tname) == 0)) { + lua_pop(L, 1); + p = lua_touserdata(L, ud); + } } + if (p == NULL) + luaL_typerror(L, ud, tname); + return p; } -- cgit v1.2.3-55-g6feb