Browse Source

auxiliary function to check userdata with types

v5-2
Roberto Ierusalimschy 22 years ago
parent
commit
2fef8c772b
  1. 15
      lauxlib.c
  2. 3
      lauxlib.h

15
lauxlib.c

@ -1,5 +1,5 @@
/*
** $Id: lauxlib.c,v 1.93 2003/01/27 13:46:16 roberto Exp roberto $
** $Id: lauxlib.c,v 1.94 2003/02/11 09:44:38 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@ -121,6 +121,19 @@ LUALIB_API void luaL_checkany (lua_State *L, int narg) {
}
LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
if (!lua_getmetatable(L, ud)) return NULL; /* no metatable? */
lua_pushstring(L, tname);
lua_rawget(L, LUA_REGISTRYINDEX);
if (!lua_rawequal(L, -1, -2)) {
lua_pop(L, 2);
return NULL;
}
lua_pop(L, 2);
return lua_touserdata(L, ud);
}
LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) {
const char *s = lua_tostring(L, narg);
if (!s) tag_error(L, narg, LUA_TSTRING);

3
lauxlib.h

@ -1,5 +1,5 @@
/*
** $Id: lauxlib.h,v 1.56 2003/01/17 15:28:09 roberto Exp roberto $
** $Id: lauxlib.h,v 1.57 2003/01/27 13:46:16 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@ -33,6 +33,7 @@ LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *e);
LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *e);
LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname);
LUALIB_API int luaL_argerror (lua_State *L, int numarg, const char *extramsg);
LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname);
LUALIB_API const char *luaL_checklstring (lua_State *L, int numArg, size_t *l);
LUALIB_API const char *luaL_optlstring (lua_State *L, int numArg,
const char *def, size_t *l);

Loading…
Cancel
Save