|
Following up on my previous posts and with the suggestion of Peter Cawley on the return value, I come up with the following code suggestion (clipped from the auxlib): LUALIB_API void *luaL_isuserdata (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? */ lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */ lua_pop(L, 2); /* remove both metatables */ return p; /* this is good! */ } else lua_pop(L, 1); /* remove 2nd metatable */ } else lua_pop(L, 1); /* remove 1st metatable */ } return NULL; /* not what is wanted */ } On 20 jun 2009, at 20:48, Hans van der Meer wrote:
Hans van der Meer |