diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-02-11 13:32:31 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-02-11 13:32:31 -0200 |
| commit | 2fef8c772b5d9c175941d4c8a64dedf736567466 (patch) | |
| tree | 8f3dfdc15801803d5da1c876d6c2b8f5bd8390f9 | |
| parent | 7285fa393ba4ef62e33f490cd23fc8aba2b7b6a4 (diff) | |
| download | lua-2fef8c772b5d9c175941d4c8a64dedf736567466.tar.gz lua-2fef8c772b5d9c175941d4c8a64dedf736567466.tar.bz2 lua-2fef8c772b5d9c175941d4c8a64dedf736567466.zip | |
auxiliary function to check userdata with types
| -rw-r--r-- | lauxlib.c | 15 | ||||
| -rw-r--r-- | lauxlib.h | 3 |
2 files changed, 16 insertions, 2 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.93 2003/01/27 13:46:16 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.94 2003/02/11 09:44:38 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 | */ |
| @@ -121,6 +121,19 @@ LUALIB_API void luaL_checkany (lua_State *L, int narg) { | |||
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | 123 | ||
| 124 | LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { | ||
| 125 | if (!lua_getmetatable(L, ud)) return NULL; /* no metatable? */ | ||
| 126 | lua_pushstring(L, tname); | ||
| 127 | lua_rawget(L, LUA_REGISTRYINDEX); | ||
| 128 | if (!lua_rawequal(L, -1, -2)) { | ||
| 129 | lua_pop(L, 2); | ||
| 130 | return NULL; | ||
| 131 | } | ||
| 132 | lua_pop(L, 2); | ||
| 133 | return lua_touserdata(L, ud); | ||
| 134 | } | ||
| 135 | |||
| 136 | |||
| 124 | LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) { | 137 | LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) { |
| 125 | const char *s = lua_tostring(L, narg); | 138 | const char *s = lua_tostring(L, narg); |
| 126 | if (!s) tag_error(L, narg, LUA_TSTRING); | 139 | if (!s) tag_error(L, narg, LUA_TSTRING); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.h,v 1.56 2003/01/17 15:28:09 roberto Exp roberto $ | 2 | ** $Id: lauxlib.h,v 1.57 2003/01/27 13:46:16 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 | */ |
| @@ -33,6 +33,7 @@ LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *e); | |||
| 33 | LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *e); | 33 | LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *e); |
| 34 | LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname); | 34 | LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname); |
| 35 | LUALIB_API int luaL_argerror (lua_State *L, int numarg, const char *extramsg); | 35 | LUALIB_API int luaL_argerror (lua_State *L, int numarg, const char *extramsg); |
| 36 | LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname); | ||
| 36 | LUALIB_API const char *luaL_checklstring (lua_State *L, int numArg, size_t *l); | 37 | LUALIB_API const char *luaL_checklstring (lua_State *L, int numArg, size_t *l); |
| 37 | LUALIB_API const char *luaL_optlstring (lua_State *L, int numArg, | 38 | LUALIB_API const char *luaL_optlstring (lua_State *L, int numArg, |
| 38 | const char *def, size_t *l); | 39 | const char *def, size_t *l); |
