|
@ -1,5 +1,5 @@ |
|
|
/*
|
|
|
/*
|
|
|
** $Id: lauxlib.c,v 1.157 2005/12/29 15:32:11 roberto Exp roberto $ |
|
|
** $Id: lauxlib.c,v 1.158 2006/01/16 12:42:21 roberto Exp roberto $ |
|
|
** Auxiliary functions for building Lua libraries |
|
|
** Auxiliary functions for building Lua libraries |
|
|
** See Copyright Notice in lua.h |
|
|
** See Copyright Notice in lua.h |
|
|
*/ |
|
|
*/ |
|
@ -123,11 +123,17 @@ 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_checkudata (lua_State *L, int ud, const char *tname) { |
|
|
void *p = lua_touserdata(L, ud); |
|
|
void *p = lua_touserdata(L, ud); |
|
|
lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ |
|
|
if (p != NULL) { /* value is a userdata? */ |
|
|
if (p == NULL || !lua_getmetatable(L, ud) || !lua_rawequal(L, -1, -2)) |
|
|
if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ |
|
|
luaL_typerror(L, ud, tname); |
|
|
lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ |
|
|
lua_pop(L, 2); /* remove both metatables */ |
|
|
if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */ |
|
|
return p; |
|
|
lua_pop(L, 2); /* remove both metatables */ |
|
|
|
|
|
return p; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
luaL_typerror(L, ud, tname); /* else error */ |
|
|
|
|
|
return NULL; /* to avoid warnings */ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|