| 154 | |
| 155 | |
| 156 | LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { |
| 157 | void *p = lua_touserdata(L, ud); |
| 158 | if (p != NULL) { /* value is a userdata? */ |
| 159 | if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ |
| 160 | lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ |
| 161 | if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */ |
| 162 | lua_pop(L, 2); /* remove both metatables */ |
| 163 | return p; |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | luaL_typerror(L, ud, tname); /* else error */ |
| 168 | return NULL; /* to avoid warnings */ |
| 169 | } |
| 170 | |
| 171 | |
| 172 | LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) { |
no test coverage detected