From 125cc879884b19ffa9181b7a52d1b7b73759301e Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Mon, 24 Sep 2012 17:52:32 +0200 Subject: [PATCH] From Lua 5.2: Add debug.getuservalue() and debug.setuservalue(). Needs -DLUAJIT_ENABLE_LUA52COMPAT. --- src/lib_debug.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/lib_debug.c b/src/lib_debug.c index ebe0691f..07b025af 100644 --- a/src/lib_debug.c +++ b/src/lib_debug.c @@ -256,6 +256,31 @@ LJLIB_CF(debug_upvaluejoin) return 0; } +#if LJ_52 +LJLIB_CF(debug_getuservalue) +{ + TValue *o = L->base; + if (o < L->top && tvisudata(o)) + settabV(L, o, tabref(udataV(o)->env)); + else + setnilV(o); + L->top = o+1; + return 1; +} + +LJLIB_CF(debug_setuservalue) +{ + TValue *o = L->base; + if (!(o < L->top && tvisudata(o))) + lj_err_argt(L, 1, LUA_TUSERDATA); + if (!(o+1 < L->top && tvistab(o+1))) + lj_err_argt(L, 2, LUA_TTABLE); + L->top = o+2; + lua_setfenv(L, 1); + return 1; +} +#endif + /* ------------------------------------------------------------------------ */ static const char KEY_HOOK = 'h';