commit 01fa1bc1146f74ba4a9fc7a5dd4c3109d971e257
parent aa003eba8e64046ebb5631eb9d94c2b556e2bab8
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Tue, 15 May 2007 15:45:49 -0300
luaL_testudata (a luaL_checkudata that does not raise errors) is
very needed.
Diffstat:
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/lauxlib.c b/lauxlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lauxlib.c,v 1.165 2007/02/07 17:51:21 roberto Exp roberto $
+** $Id: lauxlib.c,v 1.166 2007/04/19 20:21:53 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -125,7 +125,7 @@ LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) {
}
-LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
+LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) {
void *p = lua_touserdata(L, ud);
if (p != NULL) { /* value is a userdata? */
if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
@@ -136,8 +136,14 @@ LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
}
}
}
- luaL_typerror(L, ud, tname); /* else error */
- return NULL; /* to avoid warnings */
+ return NULL; /* value is not a userdata of the proper type */
+}
+
+
+LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
+ void *p = luaL_testudata(L, ud, tname);
+ if (p == NULL) luaL_typerror(L, ud, tname);
+ return p;
}
diff --git a/lauxlib.h b/lauxlib.h
@@ -1,5 +1,5 @@
/*
-** $Id: lauxlib.h,v 1.88 2006/04/12 20:31:15 roberto Exp roberto $
+** $Id: lauxlib.h,v 1.89 2007/02/07 17:51:21 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -64,6 +64,7 @@ LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);
LUALIB_API void (luaL_checkany) (lua_State *L, int narg);
LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
+LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);
LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
LUALIB_API void (luaL_where) (lua_State *L, int lvl);