Example #1
0
LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1,
								const char *msg, int level) {
  lua_Debug ar;
  int top = lua_gettop(L);
  int numlevels = countlevels(L1);
  int mark = (numlevels > LEVELS1 + LEVELS2) ? LEVELS1 : 0;
  if (msg) lua_pushfstring(L, "%s\n", msg);
  lua_pushliteral(L, "stack traceback:");
  while (lua_getstack(L1, level++, &ar)) {
	if (level == mark) {  /* too many levels? */
	  lua_pushliteral(L, "\n\t...");  /* add a '...' */
	  level = numlevels - LEVELS2;  /* and skip to last ones */
	}
	else {
	  lua_getinfo(L1, "Slnt", &ar);
	  lua_pushfstring(L, "\n\t%s:", ar.short_src);
	  if (ar.currentline > 0)
		lua_pushfstring(L, "%d:", ar.currentline);
	  lua_pushliteral(L, " in ");
	  pushfuncname(L, &ar);
	  if (ar.istailcall)
		lua_pushliteral(L, "\n\t(...tail calls...)");
	  lua_concat(L, lua_gettop(L) - top);
	}
  }
  lua_concat(L, lua_gettop(L) - top);
}
Example #2
0
void luaL_traceback (LuaThread *L, LuaThread *L1,
                                const char *msg, int level) {
  THREAD_CHECK(L);
  LuaDebug ar;
  int top = L->stack_.getTopIndex();
  int numlevels;
  {
    THREAD_CHANGE(L1);
    numlevels = countlevels(L1);
  }
  int mark = (numlevels > LEVELS1 + LEVELS2) ? LEVELS1 : 0;
  if (msg) {
    lua_pushfstring(L, "%s\n", msg);
  }
  lua_pushliteral(L, "stack traceback:");
  {
    THREAD_CHANGE(L1);
    while (lua_getstack(L1, level++, &ar)) {
      if (level == mark) {  /* too many levels? */
        {
          THREAD_CHANGE(L);
          lua_pushliteral(L, "\n\t...");  /* add a '...' */
        }
        level = numlevels - LEVELS2;  /* and skip to last ones */
      }
      else {
        lua_getinfo(L1, "Slnt", &ar);
        {
          THREAD_CHANGE(L);
          lua_pushfstring(L, "\n\t%s:", ar.short_src2.c_str());
          if (ar.currentline > 0) {
            lua_pushfstring(L, "%d:", ar.currentline);
          }
          lua_pushliteral(L, " in ");
          pushfuncname(L, &ar);
          if (ar.istailcall) {
            lua_pushliteral(L, "\n\t(...tail calls...)");
          }
          lua_concat(L, L->stack_.getTopIndex() - top);
        }
      }
    }
  }
  lua_concat(L, L->stack_.getTopIndex() - top);
}