aboutsummaryrefslogtreecommitdiff
path: root/src/lj_api.c
diff options
context:
space:
mode:
authorMike Pall <mike>2017-04-07 12:31:06 +0200
committerMike Pall <mike>2017-04-07 12:31:06 +0200
commitcde968f91f28a4819e15443a5f32c89daddb4c15 (patch)
tree465ec656f406328e4c335a46639bed72f4720026 /src/lj_api.c
parentf2e2a3f757629c520ebcac44ba7fb12cb07e56e2 (diff)
downloadluajit-cde968f91f28a4819e15443a5f32c89daddb4c15.tar.gz
luajit-cde968f91f28a4819e15443a5f32c89daddb4c15.tar.bz2
luajit-cde968f91f28a4819e15443a5f32c89daddb4c15.zip
From Lua 5.2: Add luaL_testudata().
Contributed by François Perrad.
Diffstat (limited to 'src/lj_api.c')
-rw-r--r--src/lj_api.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/lj_api.c b/src/lj_api.c
index c417af7e..c784ed3f 100644
--- a/src/lj_api.c
+++ b/src/lj_api.c
@@ -875,7 +875,7 @@ LUA_API void lua_upvaluejoin(lua_State *L, int idx1, int n1, int idx2, int n2)
875 lj_gc_objbarrier(L, fn1, gcref(fn1->l.uvptr[n1])); 875 lj_gc_objbarrier(L, fn1, gcref(fn1->l.uvptr[n1]));
876} 876}
877 877
878LUALIB_API void *luaL_checkudata(lua_State *L, int idx, const char *tname) 878LUALIB_API void *luaL_testudata(lua_State *L, int idx, const char *tname)
879{ 879{
880 cTValue *o = index2adr(L, idx); 880 cTValue *o = index2adr(L, idx);
881 if (tvisudata(o)) { 881 if (tvisudata(o)) {
@@ -884,8 +884,14 @@ LUALIB_API void *luaL_checkudata(lua_State *L, int idx, const char *tname)
884 if (tv && tvistab(tv) && tabV(tv) == tabref(ud->metatable)) 884 if (tv && tvistab(tv) && tabV(tv) == tabref(ud->metatable))
885 return uddata(ud); 885 return uddata(ud);
886 } 886 }
887 lj_err_argtype(L, idx, tname); 887 return NULL; /* value is not a userdata with a metatable */
888 return NULL; /* unreachable */ 888}
889
890LUALIB_API void *luaL_checkudata(lua_State *L, int idx, const char *tname)
891{
892 void *p = luaL_testudata(L, idx, tname);
893 if (!p) lj_err_argtype(L, idx, tname);
894 return p;
889} 895}
890 896
891/* -- Object setters ------------------------------------------------------ */ 897/* -- Object setters ------------------------------------------------------ */