add luaL_testudata()

see 01fa1bc114
This commit is contained in:
Francois Perrad 2017-03-30 15:16:45 +02:00
parent bee331e23d
commit 84cc63f856
2 changed files with 10 additions and 3 deletions

View File

@ -88,6 +88,7 @@ LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,
LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname,
int sizehint);
LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);
/*

View File

@ -872,7 +872,7 @@ LUA_API void lua_upvaluejoin(lua_State *L, int idx1, int n1, int idx2, int n2)
lj_gc_objbarrier(L, fn1, gcref(fn1->l.uvptr[n1]));
}
LUALIB_API void *luaL_checkudata(lua_State *L, int idx, const char *tname)
LUALIB_API void *luaL_testudata(lua_State *L, int idx, const char *tname)
{
cTValue *o = index2adr(L, idx);
if (tvisudata(o)) {
@ -881,8 +881,14 @@ LUALIB_API void *luaL_checkudata(lua_State *L, int idx, const char *tname)
if (tv && tvistab(tv) && tabV(tv) == tabref(ud->metatable))
return uddata(ud);
}
lj_err_argtype(L, idx, tname);
return NULL; /* unreachable */
return NULL; /* value is not a userdata with a metatable */
}
LUALIB_API void *luaL_checkudata(lua_State *L, int idx, const char *tname)
{
void *p = luaL_testudata(L, idx, tname);
if (p == NULL) lj_err_argtype(L, idx, tname);
return p;
}
/* -- Object setters ------------------------------------------------------ */