MCPcopy Create free account
hub / github.com/defold/defold / db_errorfb

Function db_errorfb

engine/lua/src/lua/ldblib.c:321–371  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

319#define LEVELS2 10 /* size of the second part of the stack */
320
321static int db_errorfb (lua_State *L) {
322 int level;
323 int firstpart = 1; /* still before eventual `...' */
324 int arg;
325 lua_State *L1 = getthread(L, &arg);
326 lua_Debug ar;
327 if (lua_isnumber(L, arg+2)) {
328 level = (int)lua_tointeger(L, arg+2);
329 lua_pop(L, 1);
330 }
331 else
332 level = (L == L1) ? 1 : 0; /* level 0 may be this own function */
333 if (lua_gettop(L) == arg)
334 lua_pushliteral(L, "");
335 else if (!lua_isstring(L, arg+1)) return 1; /* message is not a string */
336 else lua_pushliteral(L, "\n");
337 lua_pushliteral(L, "stack traceback:");
338 while (lua_getstack(L1, level++, &ar)) {
339 if (level > LEVELS1 && firstpart) {
340 /* no more than `LEVELS2' more levels? */
341 if (!lua_getstack(L1, level+LEVELS2, &ar))
342 level--; /* keep going */
343 else {
344 lua_pushliteral(L, "\n\t..."); /* too many levels */
345 while (lua_getstack(L1, level+LEVELS2, &ar)) /* find last levels */
346 level++;
347 }
348 firstpart = 0;
349 continue;
350 }
351 lua_pushliteral(L, "\n\t");
352 lua_getinfo(L1, "Snl", &ar);
353 lua_pushfstring(L, "%s:", ar.short_src);
354 if (ar.currentline > 0)
355 lua_pushfstring(L, "%d:", ar.currentline);
356 if (*ar.namewhat != '\0') /* is there a name? */
357 lua_pushfstring(L, " in function " LUA_QS, ar.name);
358 else {
359 if (*ar.what == 'm') /* main? */
360 lua_pushfstring(L, " in main chunk");
361 else if (*ar.what == 'C' || *ar.what == 't')
362 lua_pushliteral(L, " ?"); /* C function or tail call */
363 else
364 lua_pushfstring(L, " in function <%s:%d>",
365 ar.short_src, ar.linedefined);
366 }
367 lua_concat(L, lua_gettop(L) - arg);
368 }
369 lua_concat(L, lua_gettop(L) - arg);
370 return 1;
371}
372
373
374static const luaL_Reg dblib[] = {

Callers

nothing calls this directly

Calls 9

getthreadFunction · 0.85
lua_isnumberFunction · 0.85
lua_tointegerFunction · 0.85
lua_gettopFunction · 0.85
lua_isstringFunction · 0.85
lua_getstackFunction · 0.85
lua_getinfoFunction · 0.85
lua_pushfstringFunction · 0.85
lua_concatFunction · 0.85

Tested by

no test coverage detected