/* local stats = jit.util.stats(func) */ static int ju_stats(lua_State *L) { if (!(L->top > L->base)) luaL_argerror(L, 1, "Lua function expected"); if (isLfunction(L->base)) { Proto *pt = clvalue(L->base)->l.p; lua_createtable(L, 0, 11); setintfield("status", pt->jit_status); setintfield("stackslots", pt->maxstacksize); setintfield("params", pt->numparams); setintfield("bytecodes", pt->sizecode); setintfield("consts", pt->sizek); setintfield("upvalues", pt->nups); setintfield("subs", pt->sizep); lua_pushboolean(L, pt->is_vararg); lua_setfield(L, -2, "isvararg"); lua_getfenv(L, 1); lua_setfield(L, -2, "env"); if (pt->jit_szmcode != 0) { setintfield("mcodesize", (int)mcodesize(pt)); lua_pushnumber(L, (lua_Number)(size_t)pt->jit_mcode); lua_setfield(L, -2, "mcodeaddr"); } return 1; } else { return 0; /* Don't throw an error like the other util functions. */ } }
LUA_API void lua_getfenv (lua_State *L, int idx) { StkId o; lua_lock(L); o = luaA_index(L, idx); setobj2s(L->top, isLfunction(o) ? &clvalue(o)->l.g : gt(L)); api_incr_top(L); lua_unlock(L); }
/* Check that the first argument is a Lua function and return its closure. */ static Closure *check_LCL(lua_State *L) { StkId o = L->base; switch (lua_type(L, 1)) { case LUA_TBOOLEAN: o = (L->ci-1)->func; case LUA_TFUNCTION: if (isLfunction(o)) return clvalue(o); break; } luaL_argerror(L, 1, "Lua function expected"); return NULL; }
LUA_API int lua_setfenv (lua_State *L, int idx) { StkId o; int res = 0; lua_lock(L); api_checknelems(L, 1); o = luaA_index(L, idx); L->top--; api_check(L, ttistable(L->top)); if (isLfunction(o)) { res = 1; clvalue(o)->l.g = *(L->top); } lua_unlock(L); return res; }
LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { const char *name; lua_lock(L); if (ar == NULL) { /* information about non-active function? */ if (!isLfunction(L->top - 1)) /* not a Lua function? */ name = NULL; else /* consider live variables at function start (parameters) */ name = luaF_getlocalname(clLvalue(L->top - 1)->p, n, 0); } else { /* active function; get information through 'ar' */ StkId pos = 0; /* to avoid warnings */ name = findlocal(L, ar->i_ci, n, &pos); if (name) { setobj2s(L, L->top, pos); api_incr_top(L); } } lua_unlock(L); return name; }