** 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'. */
| 143 | ** 'lua_getinfo'. |
| 144 | */ |
| 145 | static int db_getinfo (lua_State *L) { |
| 146 | lua_Debug ar; |
| 147 | int arg; |
| 148 | lua_State *L1 = getthread(L, &arg); |
| 149 | const char *options = luaL_optstring(L, arg+2, "flnStu"); |
| 150 | checkstack(L, L1, 3); |
| 151 | if (lua_isfunction(L, arg + 1)) { /* info about a function? */ |
| 152 | options = lua_pushfstring(L, ">%s", options); /* add '>' to 'options' */ |
| 153 | lua_pushvalue(L, arg + 1); /* move function to 'L1' stack */ |
| 154 | lua_xmove(L, L1, 1); |
| 155 | } |
| 156 | else { /* stack level */ |
| 157 | if (!lua_getstack(L1, (int)luaL_checkinteger(L, arg + 1), &ar)) { |
| 158 | lua_pushnil(L); /* level out of range */ |
| 159 | return 1; |
| 160 | } |
| 161 | } |
| 162 | if (!lua_getinfo(L1, options, &ar)) |
| 163 | return luaL_argerror(L, arg+2, "invalid option"); |
| 164 | lua_newtable(L); /* table to collect results */ |
| 165 | if (strchr(options, 'S')) { |
| 166 | settabss(L, "source", ar.source); |
| 167 | settabss(L, "short_src", ar.short_src); |
| 168 | settabsi(L, "linedefined", ar.linedefined); |
| 169 | settabsi(L, "lastlinedefined", ar.lastlinedefined); |
| 170 | settabss(L, "what", ar.what); |
| 171 | } |
| 172 | if (strchr(options, 'l')) |
| 173 | settabsi(L, "currentline", ar.currentline); |
| 174 | if (strchr(options, 'u')) { |
| 175 | settabsi(L, "nups", ar.nups); |
| 176 | settabsi(L, "nparams", ar.nparams); |
| 177 | settabsb(L, "isvararg", ar.isvararg); |
| 178 | } |
| 179 | if (strchr(options, 'n')) { |
| 180 | settabss(L, "name", ar.name); |
| 181 | settabss(L, "namewhat", ar.namewhat); |
| 182 | } |
| 183 | if (strchr(options, 't')) |
| 184 | settabsb(L, "istailcall", ar.istailcall); |
| 185 | if (strchr(options, 'L')) |
| 186 | treatstackoption(L, L1, "activelines"); |
| 187 | if (strchr(options, 'f')) |
| 188 | treatstackoption(L, L1, "func"); |
| 189 | return 1; /* return table */ |
| 190 | } |
| 191 | |
| 192 | |
| 193 | static int db_getlocal (lua_State *L) { |
nothing calls this directly
no test coverage detected