| 324 | |
| 325 | |
| 326 | LUALIB_API void *luaL_testudata(lua_State *L, int ud, const char *tname) { |
| 327 | void *p = lua_touserdata(L, ud); |
| 328 | if (p != nullptr) { /* value is a userdata? */ |
| 329 | if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ |
| 330 | luaL_getmetatable(L, tname); /* get correct metatable */ |
| 331 | if (!lua_rawequal(L, -1, -2)) /* not the same? */ |
| 332 | p = nullptr; /* value is a userdata with wrong metatable */ |
| 333 | lua_pop(L, 2); /* remove both metatables */ |
| 334 | return p; |
| 335 | } |
| 336 | } |
| 337 | return nullptr; /* value is not a userdata with a metatable */ |
| 338 | } |
| 339 | |
| 340 | |
| 341 | LUALIB_API void *luaL_checkudata(lua_State *L, int ud, const char *tname) { |
no test coverage detected