** Calls 'lua_getinfo' and collects all results in a new table. ** L1 needs stack space for an optional input (function) plus ** two optional outputs (function and line table) from function ** 'lua_getinfo'. */
| 147 | ** 'lua_getinfo'. |
| 148 | */ |
| 149 | static int db_getinfo (lua_State *L) { |
| 150 | lua_Debug ar; |
| 151 | int arg; |
| 152 | lua_State *L1 = getthread(L, &arg); |
| 153 | const char *options = luaL_optstring(L, arg+2, "flnSrtu"); |
| 154 | checkstack(L, L1, 3); |
| 155 | if (lua_isfunction(L, arg + 1)) { /* info about a function? */ |
| 156 | options = lua_pushfstring(L, ">%s", options); /* add '>' to 'options' */ |
| 157 | lua_pushvalue(L, arg + 1); /* move function to 'L1' stack */ |
| 158 | lua_xmove(L, L1, 1); |
| 159 | } |
| 160 | else { /* stack level */ |
| 161 | if (!lua_getstack(L1, (int)luaL_checkinteger(L, arg + 1), &ar)) { |
| 162 | luaL_pushfail(L); /* level out of range */ |
| 163 | return 1; |
| 164 | } |
| 165 | } |
| 166 | if (!lua_getinfo(L1, options, &ar)) |
| 167 | return luaL_argerror(L, arg+2, "invalid option"); |
| 168 | lua_newtable(L); /* table to collect results */ |
| 169 | if (strchr(options, 'S')) { |
| 170 | lua_pushlstring(L, ar.source, ar.srclen); |
| 171 | lua_setfield(L, -2, "source"); |
| 172 | settabss(L, "short_src", ar.short_src); |
| 173 | settabsi(L, "linedefined", ar.linedefined); |
| 174 | settabsi(L, "lastlinedefined", ar.lastlinedefined); |
| 175 | settabss(L, "what", ar.what); |
| 176 | } |
| 177 | if (strchr(options, 'l')) |
| 178 | settabsi(L, "currentline", ar.currentline); |
| 179 | if (strchr(options, 'u')) { |
| 180 | settabsi(L, "nups", ar.nups); |
| 181 | settabsi(L, "nparams", ar.nparams); |
| 182 | settabsb(L, "isvararg", ar.isvararg); |
| 183 | } |
| 184 | if (strchr(options, 'n')) { |
| 185 | settabss(L, "name", ar.name); |
| 186 | settabss(L, "namewhat", ar.namewhat); |
| 187 | } |
| 188 | if (strchr(options, 'r')) { |
| 189 | settabsi(L, "ftransfer", ar.ftransfer); |
| 190 | settabsi(L, "ntransfer", ar.ntransfer); |
| 191 | } |
| 192 | if (strchr(options, 't')) |
| 193 | settabsb(L, "istailcall", ar.istailcall); |
| 194 | if (strchr(options, 'L')) |
| 195 | treatstackoption(L, L1, "activelines"); |
| 196 | if (strchr(options, 'f')) |
| 197 | treatstackoption(L, L1, "func"); |
| 198 | return 1; /* return table */ |
| 199 | } |
| 200 | |
| 201 | |
| 202 | static int db_getlocal (lua_State *L) { |
nothing calls this directly
no test coverage detected