diff options
| author | Mike Pall <mike> | 2017-04-07 12:31:06 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2017-04-07 12:31:06 +0200 |
| commit | cde968f91f28a4819e15443a5f32c89daddb4c15 (patch) | |
| tree | 465ec656f406328e4c335a46639bed72f4720026 /src | |
| parent | f2e2a3f757629c520ebcac44ba7fb12cb07e56e2 (diff) | |
| download | luajit-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')
| -rw-r--r-- | src/lauxlib.h | 1 | ||||
| -rw-r--r-- | src/lj_api.c | 12 |
2 files changed, 10 insertions, 3 deletions
diff --git a/src/lauxlib.h b/src/lauxlib.h index a8280c20..1ca0d74f 100644 --- a/src/lauxlib.h +++ b/src/lauxlib.h | |||
| @@ -88,6 +88,7 @@ LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, | |||
| 88 | LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup); | 88 | LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup); |
| 89 | LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname, | 89 | LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname, |
| 90 | int sizehint); | 90 | int sizehint); |
| 91 | LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname); | ||
| 91 | 92 | ||
| 92 | 93 | ||
| 93 | /* | 94 | /* |
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 | ||
| 878 | LUALIB_API void *luaL_checkudata(lua_State *L, int idx, const char *tname) | 878 | LUALIB_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 | |||
| 890 | LUALIB_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 ------------------------------------------------------ */ |
