MCPcopy Create free account
hub / github.com/DFHack/dfhack / db_getinfo

Function db_getinfo

depends/lua/src/ldblib.c:145–190  ·  view source on GitHub ↗

** 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'. */

Source from the content-addressed store, hash-verified

143** 'lua_getinfo'.
144*/
145static 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
193static int db_getlocal (lua_State *L) {

Callers

nothing calls this directly

Calls 14

getthreadFunction · 0.85
checkstackFunction · 0.85
lua_pushfstringFunction · 0.85
lua_pushvalueFunction · 0.85
lua_xmoveFunction · 0.85
lua_getstackFunction · 0.85
luaL_checkintegerFunction · 0.85
lua_pushnilFunction · 0.85
lua_getinfoFunction · 0.85
luaL_argerrorFunction · 0.85
settabssFunction · 0.85
settabsiFunction · 0.85

Tested by

no test coverage detected