static void hookf (lv_State *L, lv_Debug *ar) { static const char *const hooknames[] = {"call", "return", "line", "count", "tail return"}; lv_pushlightuserdata(L, (void *)&KEY_HOOK); lv_rawget(L, LV_REGISTRYINDEX); lv_pushlightuserdata(L, L); lv_rawget(L, -2); if (lv_isfunction(L, -1)) { lv_pushstring(L, hooknames[(int)ar->event]); if (ar->currentline >= 0) lv_pushinteger(L, ar->currentline); else lv_pushnil(L); lv_assert(lv_getinfo(L, "lS", ar)); lv_call(L, 2, 0); } }
static int db_getinfo (lv_State *L) { lv_Debug ar; int arg; lv_State *L1 = getthread(L, &arg); const char *options = lvL_optstring(L, arg+2, "flnSu"); if (lv_isnumber(L, arg+1)) { if (!lv_getstack(L1, (int)lv_tointeger(L, arg+1), &ar)) { lv_pushnil(L); /* level out of range */ return 1; } } else if (lv_isfunction(L, arg+1)) { lv_pushfstring(L, ">%s", options); options = lv_tostring(L, -1); lv_pushvalue(L, arg+1); lv_xmove(L, L1, 1); } else return lvL_argerror(L, arg+1, "function or level expected"); if (!lv_getinfo(L1, options, &ar)) return lvL_argerror(L, arg+2, "invalid option"); lv_createtable(L, 0, 2); if (strchr(options, 'S')) { settabss(L, "source", ar.source); settabss(L, "short_src", ar.short_src); settabsi(L, "linedefined", ar.linedefined); settabsi(L, "lastlinedefined", ar.lastlinedefined); settabss(L, "what", ar.what); } if (strchr(options, 'l')) settabsi(L, "currentline", ar.currentline); if (strchr(options, 'u')) settabsi(L, "nups", ar.nups); if (strchr(options, 'n')) { settabss(L, "name", ar.name); settabss(L, "namewhat", ar.namewhat); } if (strchr(options, 'L')) treatstackoption(L, L1, "activelines"); if (strchr(options, 'f')) treatstackoption(L, L1, "func"); return 1; /* return table */ }
/** * @brief Get the function associated with the given value * * It is considered a fatal error to call this function when the type of the * value is not a function * * @param value the lua value which is a function * @return the pointer to the function */ lclosure_t* lv_getfunction(luav value, u32 argnum) { if (!lv_isfunction(value)) { err_badtype(argnum, LFUNCTION, lv_gettype(value)); } return (lclosure_t*) lv_getptr(value); }