| 138 | |
| 139 | |
| 140 | LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) { /*BZ*/ |
| 141 | void *p = lua_touserdata(L, ud); |
| 142 | if (p == NULL) { /* value is a userdata? */ |
| 143 | return NULL; |
| 144 | } |
| 145 | |
| 146 | if (!lua_getmetatable(L, ud)) { /* does it have a metatable? */ |
| 147 | lua_pop(L, 1); |
| 148 | return NULL; |
| 149 | } |
| 150 | |
| 151 | /* get type metatable */ |
| 152 | lua_getfield(L, LUA_REGISTRYINDEX, tname); |
| 153 | |
| 154 | /* does it have the type's metatable */ |
| 155 | if (lua_rawequal(L, -1, -2)) { |
| 156 | lua_pop(L, 2); /* remove both metatables */ |
| 157 | return p; |
| 158 | } |
| 159 | |
| 160 | lua_pop(L, 2); /* remove both metatables */ |
| 161 | return NULL; |
| 162 | } |
| 163 | |
| 164 | |
| 165 | LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) { |