diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-05-15 15:46:12 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-05-15 15:46:12 -0300 |
commit | 01fa1bc1146f74ba4a9fc7a5dd4c3109d971e257 (patch) | |
tree | 8333f36b434f0b30b7a309cedb22e1107ae50b1a | |
parent | aa003eba8e64046ebb5631eb9d94c2b556e2bab8 (diff) | |
download | lua-01fa1bc1146f74ba4a9fc7a5dd4c3109d971e257.tar.gz lua-01fa1bc1146f74ba4a9fc7a5dd4c3109d971e257.tar.bz2 lua-01fa1bc1146f74ba4a9fc7a5dd4c3109d971e257.zip |
luaL_testudata (a luaL_checkudata that does not raise errors) is
very needed.
-rw-r--r-- | lauxlib.c | 14 | ||||
-rw-r--r-- | lauxlib.h | 3 |
2 files changed, 12 insertions, 5 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.165 2007/02/07 17:51:21 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.166 2007/04/19 20:21:53 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -125,7 +125,7 @@ LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) { | |||
125 | } | 125 | } |
126 | 126 | ||
127 | 127 | ||
128 | LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { | 128 | LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) { |
129 | void *p = lua_touserdata(L, ud); | 129 | void *p = lua_touserdata(L, ud); |
130 | if (p != NULL) { /* value is a userdata? */ | 130 | if (p != NULL) { /* value is a userdata? */ |
131 | if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ | 131 | 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) { | |||
136 | } | 136 | } |
137 | } | 137 | } |
138 | } | 138 | } |
139 | luaL_typerror(L, ud, tname); /* else error */ | 139 | return NULL; /* value is not a userdata of the proper type */ |
140 | return NULL; /* to avoid warnings */ | 140 | } |
141 | |||
142 | |||
143 | LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { | ||
144 | void *p = luaL_testudata(L, ud, tname); | ||
145 | if (p == NULL) luaL_typerror(L, ud, tname); | ||
146 | return p; | ||
141 | } | 147 | } |
142 | 148 | ||
143 | 149 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.h,v 1.88 2006/04/12 20:31:15 roberto Exp roberto $ | 2 | ** $Id: lauxlib.h,v 1.89 2007/02/07 17:51:21 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -64,6 +64,7 @@ LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); | |||
64 | LUALIB_API void (luaL_checkany) (lua_State *L, int narg); | 64 | LUALIB_API void (luaL_checkany) (lua_State *L, int narg); |
65 | 65 | ||
66 | LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); | 66 | LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); |
67 | LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname); | ||
67 | LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); | 68 | LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); |
68 | 69 | ||
69 | LUALIB_API void (luaL_where) (lua_State *L, int lvl); | 70 | LUALIB_API void (luaL_where) (lua_State *L, int lvl); |