Esempio n. 1
0
        public void L_Traceback(ILuaState otherLua, string msg, int level)
        {
            LuaState oLua      = otherLua as LuaState;
            LuaDebug ar        = new LuaDebug();
            int      top       = API.GetTop();
            int      numLevels = oLua.CountLevels();
            int      mark      = (numLevels > LEVELS1 + LEVELS2) ? LEVELS1 : 0;

            if (msg != null)
            {
                API.PushString(string.Format("{0}\n", msg));
            }
            API.PushString("stack traceback:");
            while (otherLua.GetStack(level++, ar))
            {
                if (level == mark) // too many levels?
                {
                    API.PushString("\n\t...");
                    level = numLevels - LEVELS2; // and skip to last ones
                }
                else
                {
                    oLua.GetInfo("Slnt", ar);
                    API.PushString(string.Format("\n\t{0}:", ar.ShortSrc));
                    if (ar.CurrentLine > 0)
                    {
                        API.PushString(string.Format("{0}:", ar.CurrentLine));
                    }
                    API.PushString(" in ");
                    PushFuncName(ar);
                    if (ar.IsTailCall)
                    {
                        API.PushString("\n\t(...tail calls...)");
                    }
                    API.Concat(API.GetTop() - top);
                }
            }

            API.Concat(API.GetTop() - top);
        }