コード例 #1
0
ファイル: LuaStateDebug.cs プロジェクト: tamashi-games/UniLua
        private void FuncInfo(LuaDebug ar, StkId func)
        {
            Utl.Assert(func.V.TtIsFunction());
            if (func.V.ClIsLuaClosure())
            {
                var lcl = func.V.ClLValue();
                var p   = lcl.Proto;
                ar.Source          = string.IsNullOrEmpty(p.Source) ? "=?" : p.Source;
                ar.LineDefined     = p.LineDefined;
                ar.LastLineDefined = p.LastLineDefined;
                ar.What            = (ar.LineDefined == 0) ? "main" : "Lua";
            }
            else if (func.V.ClIsCsClosure())
            {
                ar.Source          = "=[C#]";
                ar.LineDefined     = -1;
                ar.LastLineDefined = -1;
                ar.What            = "C#";
            }
            else
            {
                throw new System.NotImplementedException();
            }

            if (ar.Source.Length > LuaDef.LUA_IDSIZE)
            {
                ar.ShortSrc = ar.Source.Substring(0, LuaDef.LUA_IDSIZE);
            }
            else
            {
                ar.ShortSrc = ar.Source;
            }
        }
コード例 #2
0
ファイル: LuaStateDebug.cs プロジェクト: tamashi-games/UniLua
 private void CollectValidLines(StkId func)
 {
     Utl.Assert(func.V.TtIsFunction());
     if (func.V.ClIsLuaClosure())
     {
         var lcl      = func.V.ClLValue();
         var p        = lcl.Proto;
         var lineinfo = p.LineInfo;
         var t        = new LuaTable(this);
         Top.V.SetHValue(t);
         IncrTop();
         var v = new TValue();
         v.SetBValue(true);
         for (int i = 0; i < lineinfo.Count; ++i)
         {
             t.SetInt(lineinfo[i], ref v);
         }
     }
     else if (func.V.ClIsCsClosure())
     {
         Top.V.SetNilValue();
         IncrTop();
     }
     else
     {
         throw new System.NotImplementedException();
     }
 }
コード例 #3
0
        private string GetUpvalueName(CallInfo ci, StkId o, out string name)
        {
            var func = Stack[ci.FuncIndex];

            Utl.Assert(func.V.TtIsFunction() && func.V.ClIsLuaClosure());
            var lcl = func.V.ClLValue();

            for (int i = 0; i < lcl.Upvals.Length; ++i)
            {
                if (lcl.Upvals[i].V == o)
                {
                    name = UpvalName(lcl.Proto, i);
                    return("upvalue");
                }
            }
            name = default(string);
            return(null);
        }
コード例 #4
0
ファイル: LuaStateDebug.cs プロジェクト: tamashi-games/UniLua
        public int GetInfo(string what, LuaDebug ar)
        {
            CallInfo ci;
            StkId    func;

            int pos = 0;

            if (what[pos] == '>')
            {
                ci   = null;
                func = Stack[Top.Index - 1];

                Utl.ApiCheck(func.V.TtIsFunction(), "function expected");
                pos++;

                Top = Stack[Top.Index - 1];
            }
            else
            {
                ci   = BaseCI[ar.ActiveCIIndex];
                func = Stack[ci.FuncIndex];
                Utl.Assert(Stack[ci.FuncIndex].V.TtIsFunction());
            }

            // var IsClosure( func.Value ) ? func.Value
            int status = AuxGetInfo(what, ar, func, ci);

            if (what.Contains("f"))
            {
                Top.V.SetObj(ref func.V);
                IncrTop();
            }

            if (what.Contains("L"))
            {
                CollectValidLines(func);
            }

            return(status);
        }
コード例 #5
0
ファイル: LuaStateDebug.cs プロジェクト: tamashi-games/UniLua
        private int AuxGetInfo(string what, LuaDebug ar, StkId func, CallInfo ci)
        {
            int status = 1;

            for (int i = 0; i < what.Length; ++i)
            {
                char c = what[i];
                switch (c)
                {
                case 'S': {
                    FuncInfo(ar, func);
                    break;
                }

                case 'l': {
                    ar.CurrentLine = (ci != null && ci.IsLua) ? GetCurrentLine(ci) : -1;
                    break;
                }

                case 'u': {
                    Utl.Assert(func.V.TtIsFunction());
                    if (func.V.ClIsLuaClosure())
                    {
                        var lcl = func.V.ClLValue();
                        ar.NumUps    = lcl.Upvals.Length;
                        ar.IsVarArg  = lcl.Proto.IsVarArg;
                        ar.NumParams = lcl.Proto.NumParams;
                    }
                    else if (func.V.ClIsCsClosure())
                    {
                        var ccl = func.V.ClCsValue();
                        ar.NumUps    = ccl.Upvals.Length;
                        ar.IsVarArg  = true;
                        ar.NumParams = 0;
                    }
                    else
                    {
                        throw new System.NotImplementedException();
                    }

                    break;
                }

                case 't': {
                    ar.IsTailCall = (ci != null)
              ? ((ci.CallStatus & CallStatus.CIST_TAIL) != 0)
              : false;
                    break;
                }

                case 'n': {
                    var prevCI = BaseCI[ci.Index - 1];
                    if (ci != null &&
                        ((ci.CallStatus & CallStatus.CIST_TAIL) == 0) &&
                        prevCI.IsLua)
                    {
                        ar.NameWhat = GetFuncName(prevCI, out ar.Name);
                    }
                    else
                    {
                        ar.NameWhat = null;
                    }

                    if (ar.NameWhat == null)
                    {
                        ar.NameWhat = ""; // not found
                        ar.Name     = null;
                    }

                    break;
                }

                case 'L':
                case 'f': // handled by GetInfo
                    break;

                default:
                    status = 0; // invalid option
                    break;
                }
            }

            return(status);
        }