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;
            }
        }
Exemple #2
0
        static void HookCallback(IntPtr p, IntPtr ar)
        {
            var state = Lua.FromIntPtr(p);
            var debug = LuaDebug.FromIntPtr(ar);

            Assert.NotNull(state, "#state shouldn't be null");
            Assert.NotNull(debug, "#debug shouldn't be null");

            if (debug.Event != LuaHookEvent.Line)
            {
                return;
            }

            state.GetStack(0, ar);

            if (!state.GetInfo("Snlu", ar))
            {
                return;
            }

            debug = LuaDebug.FromIntPtr(ar);
            string source = debug.Source.Substring(1);

            source = System.IO.Path.GetFileName(source);
            hookLog.AppendLine($"{source}:{debug.CurrentLine} ({debug.What})");
        }
Exemple #3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="luaDebug">Lua debug structure.</param>
 /// <param name="fileName">Filename</param>
 /// <param name="line">Line number</param>
 /// <param name="action">Action</param>
 /// <param name="breakpoint">Brewakpoint</param>
 public StopingEventArgs(LuaDebug luaDebug, string fileName, int line, DebuggerActions action, LuaDebugBreakpoint breakpoint)
 {
     LuaDebug   = luaDebug;
     FileName   = fileName;
     Line       = line;
     Action     = action;
     Breakpoint = breakpoint;
 }
Exemple #4
0
 /// <summary>
 /// Sets a new value for a local variable.
 /// </summary>
 /// <param name="luaDebug">Current LuaDebug structure.</param>
 /// <param name="var">Variable that was returned by GetLocalVars.</param>
 /// <param name="newValue">New value. The type don't have to match.</param>
 public void SetLocalVar(LuaDebug luaDebug, ref LuaVar var, object newValue)
 {
     if (m_State == LuaDebuggerState.Stoped)
     {
         var.Value = newValue;
         m_Lua.Push(newValue);
         m_Lua.SetLocal(luaDebug, var.Index);
     }
 }
Exemple #5
0
 private static int DBErrorFB(LuaState L)
 {
     int level;
     bool firstpart = true;  /* still before eventual `...' */
     int arg;
     LuaState L1 = GetThread(L, out arg);
     LuaDebug ar = new LuaDebug();
     if (LuaIsNumber(L, arg + 2) != 0)
     {
         level = (int)LuaToInteger(L, arg + 2);
         LuaPop(L, 1);
     }
     else
         level = (L == L1) ? 1 : 0;  /* level 0 may be this own function */
     if (LuaGetTop(L) == arg)
         LuaPushLiteral(L, "");
     else if (LuaIsString(L, arg + 1) == 0) return 1;  /* message is not a string */
     else LuaPushLiteral(L, "\n");
     LuaPushLiteral(L, "stack traceback:");
     while (LuaGetStack(L1, level++, ar) != 0)
     {
         if (level > LEVELS1 && firstpart)
         {
             /* no more than `LEVELS2' more levels? */
             if (LuaGetStack(L1, level + LEVELS2, ar) == 0)
                 level--;  /* keep going */
             else
             {
                 LuaPushLiteral(L, "\n\t...");  /* too many levels */
                 while (LuaGetStack(L1, level + LEVELS2, ar) != 0)  /* find last levels */
                     level++;
             }
             firstpart = false;
             continue;
         }
         LuaPushLiteral(L, "\n\t");
         LuaGetInfo(L1, "Snl", ar);
         LuaPushFString(L, "%s:", ar.short_src);
         if (ar.currentline > 0)
             LuaPushFString(L, "%d:", ar.currentline);
         if (ar.namewhat != '\0')  /* is there a name? */
             LuaPushFString(L, " in function " + LUA_QS, ar.name);
         else
         {
             if (ar.what == 'm')  /* main? */
                 LuaPushFString(L, " in main chunk");
             else if (ar.what == 'C' || ar.what == 't')
                 LuaPushLiteral(L, " ?");  /* C function or tail call */
             else
                 LuaPushFString(L, " in function <%s:%d>",
                                    ar.short_src, ar.linedefined);
         }
         LuaConcat(L, LuaGetTop(L) - arg);
     }
     LuaConcat(L, LuaGetTop(L) - arg);
     return 1;
 }
Exemple #6
0
        public static bool Init()
        {
            _quit    = false;
            LuaState = new Lua {
                Encoding = Encoding.UTF8
            };

            LuaState.PushString($"Eight {Eight.Version}");
            LuaState.SetGlobal("_HOST");

            LuaState.SetWarningFunction(WarnFunction, IntPtr.Zero);

            DoLibs();

            State = LuaState.NewThread();

            State.SetHook((luaState, ar) => {
                var state = Lua.FromIntPtr(luaState);

                var arg = LuaDebug.FromIntPtr(ar);

                if (arg.Event == LuaHookEvent.Count)
                {
                    if (Event.OutOfSync && !_killed)
                    {
                        _killed = true;
                        if (Eight.Flags["out_of_sync_error"])
                        {
                            State.Error("out of sync");
                        }
                    }
                }
            }, LuaHookMask.Count, 10000);

            if (!File.Exists("Lua/boot.lua"))
            {
                Console.WriteLine("Could not find boot.lua");
                Eight.Crash("Could not find bios.lua!", "Is Eight installed correctly?");
                return(false);
            }

            var biosContent = File.ReadAllText("Lua/boot.lua");

            var status = State.LoadString(biosContent, "@BOOT");

            if (status != LuaStatus.OK)
            {
                var error = State.ToString(-1);
                Console.WriteLine("Lua Load Exception: {0}", error);
                return(false);
            }

            return(true);
        }
Exemple #7
0
    public void PrepareLuaState()
    {
        lua_ = LuaAPI.NewState(IntPtr.Zero);
        lua_.L_OpenLibs();
#if UNITY_EDITOR || LuaDebugger
        LuaAPI.luaopen_RMDB(lua_.GetLuaPtr(), 0);
#endif
        //Register Global Class
        LuaDebug.RegisterToLua(lua_, typeof(LuaDebug));
        RegisterType(typeof(Register));
        LuaDBTable.RegisterToLua(lua_, typeof(LuaDBTable));
    }
        void Debugger_Stoping(object sender, StopingEventArgs e)
        {
            string reason;

            if (e.Breakpoint != null)
            {
                reason = "Breakpoint";
            }
            else
            {
                reason = e.Action.ToString();
            }
            Console.Out.WriteLine(String.Format("{0}:{1}: Stopping because of {2}", e.FileName, e.Line, reason));
            m_LuaDebugAtStop = e.LuaDebug;
        }
Exemple #9
0
		bool ILuaAPI.GetStack( int level, LuaDebug ar )
		{
			if( level < 0 )
				return false;

			int index;
			for( index = CI.Index; level > 0 && index > 0; --index )
				{ level--; }

			bool status = false;
			if( level == 0 && index > 0 ) {
				status = true;
				ar.ActiveCIIndex = index;
			}
			return status;
		}
Exemple #10
0
 /// <summary>
 /// Sets a new value for a local variable.
 /// </summary>
 /// <param name="luaDebug">Current LuaDebug structure.</param>
 /// <param name="varName">Name of the variable.</param>
 /// <param name="newValue">New value. The type don't have to match.</param>
 public bool SetLocalVar(LuaDebug luaDebug, string varName, object newValue)
 {
     if (m_State == LuaDebuggerState.Stoped)
     {
         LuaVar[] vars = GetLocalVars(luaDebug);
         for (int n = 0; n < vars.Length; ++n) // no foreach bc var is used as ref parameter!
         {
             var var = vars[n];
             if (String.Compare(varName, var.Name, StringComparison.OrdinalIgnoreCase) == 0)
             {
                 SetLocalVar(luaDebug, ref var, newValue);
                 return(true);
             }
         }
     }
     return(false);
 }
Exemple #11
0
        bool ILuaAPI.GetStack( int level, LuaDebug ar )
        {
            if( level < 0 )
                return false;

            CallInfo ci;
            for( ci = CI; level > 0 && ci != BaseCI; ci = ci.Previous )
                level--;

            bool status = false;
            if( level == 0 && ci != BaseCI )
            {
                status = true;
                ar.ActiveCI = ci;
            }
            return status;
        }
Exemple #12
0
        static void HookCalbackStruct(IntPtr p, IntPtr ar)
        {
            var state = Lua.FromIntPtr(p);
            var debug = new LuaDebug();

            state.GetStack(0, ref debug);

            if (!state.GetInfo("Snlu", ref debug))
            {
                return;
            }

            string source = debug.Source.Substring(1);

            source = System.IO.Path.GetFileName(source);
            hookLog.AppendLine($"{source}:{debug.CurrentLine} ({debug.What})");
        }
Exemple #13
0
        /// <summary>
        /// Gets the local variables and their values.
        /// </summary>
        /// <param name="luaDebug">Current LuaDebug structure.</param>
        /// <returns>
        /// Returns a list with all local variables and their values.
        /// If the debuggger is not stoped, a empty array is returned.
        /// </returns>
        public LuaVar[] GetLocalVars(LuaDebug luaDebug)
        {
            List <LuaVar> vars = new List <LuaVar>();

            if (m_State == LuaDebuggerState.Stoped)
            {
                int    index = 1;
                string name  = m_Lua.GetLocal(luaDebug, index);
                while (name != null)
                {
                    vars.Add(new LuaVar(index, name, m_Lua.Pop()));

                    ++index;
                    name = m_Lua.GetLocal(luaDebug, index);
                }
            }
            return(vars.ToArray());
        }
        private static int CO_Status(ILuaState lua)
        {
            ILuaState co = lua.ToThread(1);

            lua.L_ArgCheck(co != null, 1, "coroutine expected");
            if ((LuaState)lua == (LuaState)co)
            {
                lua.PushString("running");
            }
            else
            {
                switch (co.Status)
                {
                case ThreadStatus.LUA_YIELD:
                    lua.PushString("suspended");
                    break;

                case ThreadStatus.LUA_OK:
                {
                    LuaDebug ar = new LuaDebug();
                    if (co.GetStack(0, ar))                        // does it have frames?
                    {
                        lua.PushString("normal");
                    }
                    else if (co.GetTop() == 0)
                    {
                        lua.PushString("dead");
                    }
                    else
                    {
                        lua.PushString("suspended");
                    }
                    break;
                }

                default:                 // some error occurred
                    lua.PushString("dead");
                    break;
                }
            }
            return(1);
        }
Exemple #15
0
 /// <summary>
 /// Stops execution.
 /// </summary>
 /// <param name="luaDebug">LuaDebug from debug hook.</param>
 /// <param name="action">Current Debugger Action.</param>
 /// <param name="breakpoint">Brekpoint. Can be null.</param>
 /// <remarks>
 /// The WaitingForAction event is called as long as State == Stoped.
 /// </remarks>
 private void StopExecution(LuaDebug luaDebug, DebuggerActions action, LuaDebugBreakpoint breakpoint)
 {
     m_State = LuaDebuggerState.Stoped;
     try
     {
         OnStopping(new StopingEventArgs(
                        luaDebug, luaDebug.shortsrc,
                        luaDebug.eventCode == EventCodes.LUA_HOOKCALL ? luaDebug.linedefined : luaDebug.currentline,
                        action,
                        breakpoint));
         do
         {
             OnWaitingForAction(new EventArgs());
         }while (m_State == LuaDebuggerState.Stoped);
     }
     finally
     {
         m_State = LuaDebuggerState.Running;
     }
 }
Exemple #16
0
        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);
        }
        void Debugger_FullTraceData(object sender, DebugHookEventArgs e)
        {
            Console.Out.Write(String.Format("FT {0} ", e.LuaDebug.eventCode.ToString()));
            Console.Out.WriteLine(e.LuaDebug.currentline);

            LuaDebug luaDebug = e.LuaDebug;

            if (m_Lua.GetInfo("nS", ref luaDebug) == 0)
            {
                Console.Out.WriteLine("   Lua.GetInfo failed!");
            }
            else
            {
                if (luaDebug.source.Length > 0 && luaDebug.source[0] == '@')
                {
                    Console.Out.WriteLine(String.Format("   n:{0} nw:{1} w:{2} s:{3} ss:{4} ld:{5} lld:{6} cl:{7}",
                                                        luaDebug.name, luaDebug.namewhat,
                                                        luaDebug.what, luaDebug.source, luaDebug.shortsrc,
                                                        luaDebug.linedefined, luaDebug.lastlinedefined, luaDebug.currentline));
                }
            }
        }
Exemple #18
0
        private static int DBG_GetInfo(ILuaState lua)
        {
            LuaDebug ar    = new LuaDebug();
            int      level = lua.L_CheckInteger(1);

            if (lua.GetStack(level, ar))                //
            {
                ((LuaState)lua).GetInfo("Sl", ar);

                lua.NewTable();
                lua.PushString("currentline");
                lua.PushNumber(ar.CurrentLine);
                lua.SetTable(-2);
                lua.PushString("source");
                lua.PushString(ar.Source);
                lua.SetTable(-2);
            }
            else
            {
                lua.PushNil();
            }
            return(1);
        }
        bool ILuaAPI.GetStack(int level, LuaDebug ar)
        {
            if (level < 0)
            {
                return(false);
            }

            int index;

            for (index = CI.Index; level > 0 && index > 0; --index)
            {
                level--;
            }

            bool status = false;

            if (level == 0 && index > 0)
            {
                status           = true;
                ar.ActiveCIIndex = index;
            }
            return(status);
        }
Exemple #20
0
        public int GetInfo( string what, LuaDebug ar )
        {
            CallInfo 	ci;
            StkId		func;

            int	pos = 0;
            if( what[pos] == '>' )
            {
                ci = null;
                func = Top - 1;

                Utl.ApiCheck( func.Value.IsFunction, "function expected" );
                pos++;

                Top -= 1;
            }
            else
            {
                ci = ar.ActiveCI;
                func = ci.Func;
                Utl.Assert( ci.Func.Value.IsFunction );
            }

            // var IsClosure( func.Value ) ? func.Value
            int status = AuxGetInfo( what, ar, func, ci );
            if( what.Contains( "f" ) )
            {
                Top.Value = func.Value;
                IncrTop();
            }
            if( what.Contains( "L" ) )
            {
                CollectValidLines( func );
            }
            return status;
        }
Exemple #21
0
		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;
		}
Exemple #22
0
		public DebugHookEventArgs (LuaDebug luaDebug)
		{
			this.luaDebug = luaDebug;
		}
Exemple #23
0
 /// <summary>
 /// Gets information about the interpreter runtime stack. 
 /// </summary>
 public int GetStack(int level, LuaDebug ar)
 {
     throw new NotImplementedException();
 }
Exemple #24
0
 private static void HookF(LuaState L, LuaDebug ar)
 {
     LuaPushLightUserData(L, KEY_HOOK);
     LuaRawGet(L, LUA_REGISTRYINDEX);
     LuaPushLightUserData(L, L);
     LuaRawGet(L, -2);
     if (LuaIsFunction(L, -1))
     {
         LuaPushString(L, hooknames[(int)ar.event_]);
         if (ar.currentline >= 0)
             LuaPushInteger(L, ar.currentline);
         else LuaPushNil(L);
         LuaAssert(LuaGetInfo(L, "lS", ar));
         LuaCall(L, 2, 0);
     }
 }
Exemple #25
0
        /// <summary>
        /// Lua debug hook event handler.
        /// </summary>
        /// <param name="sender">Sender of the event</param>
        /// <param name="e">Event args</param>
        /// <remarks>
        /// This is the main debug handler.
        /// This event calls the FullTraceData event (if enabled),
        /// Stoping event and the WaitingForAction event (when execution is stoped).
        /// </remarks>
        private void Lua_DebugHook(object sender, DebugHookEventArgs e)
        {
            if (!m_InDebugHook)
            {
                m_InDebugHook = true;
                try
                {
                    if (m_FullTrace)
                    {
                        OnFullTraceData(e);
                    }

                    if (m_State != LuaDebuggerState.Disabled)
                    {
                        if (e.LuaDebug.eventCode == EventCodes.LUA_HOOKCALL)
                        {
                            ++m_StackLevel;
                        }
                        else if (e.LuaDebug.eventCode == EventCodes.LUA_HOOKRET ||
                                 e.LuaDebug.eventCode == EventCodes.LUA_HOOKTAILRET)
                        {
                            --m_StackLevel;
                        }

                        if (e.LuaDebug.eventCode == EventCodes.LUA_HOOKCALL || e.LuaDebug.eventCode == EventCodes.LUA_HOOKLINE)
                        {
                            LuaDebug luaDebug = e.LuaDebug;
                            m_Lua.GetInfo("nS", ref luaDebug);
                            int line = luaDebug.eventCode == EventCodes.LUA_HOOKCALL ? luaDebug.linedefined : luaDebug.currentline;
                            if (luaDebug.source.Length > 0 && luaDebug.source[0] == '@')
                            {
                                LuaDebugBreakpoint breakpoint;
                                switch (m_Action)
                                {
                                case DebuggerActions.Run:
                                    // checked for breakpoints
                                    breakpoint = GetBreakpoint(luaDebug.shortsrc, line);
                                    if (breakpoint != null && breakpoint.Enabled)
                                    {
                                        StopExecution(luaDebug, m_Action, breakpoint);
                                    }
                                    break;

                                case DebuggerActions.Stop:
                                case DebuggerActions.StepInto:
                                    StopExecution(luaDebug, m_Action, null);
                                    break;

                                case DebuggerActions.StepOver:
                                case DebuggerActions.StepOut:
                                    // checked for breakpoints or if stack level is ready for stopping
                                    if (m_StackLevel <= m_StepStackLevel)
                                    {
                                        StopExecution(luaDebug, m_Action, null);
                                    }
                                    else
                                    {
                                        breakpoint = GetBreakpoint(luaDebug.shortsrc, line);
                                        if (breakpoint != null && breakpoint.Enabled)
                                        {
                                            StopExecution(luaDebug, m_Action, breakpoint);
                                        }
                                    }
                                    break;

                                default:
                                    break;
                                }
                            }
                        }
                    }
                }
                finally
                {
                    m_InDebugHook = false;
                }
            }
        }
Exemple #26
0
		public int GetStack (int level, ref LuaDebug ar)
		{
			return LuaCore.LuaGetStack (luaState, level,ref ar);
		}
Exemple #27
0
        public static string SetLocal(ScriptState luaState, LuaDebug ar, int n)
        {
            CharPtr local = ScriptApi.SetLocal(luaState, ar, n);

            return(local.ToString());
        }
Exemple #28
0
 /*
 ** Hook set by signal function to stop the interpreter.
 */
 static void lstop(ILuaState L, LuaDebug ar)
 {
     //(void)ar;  /* unused arg. */
     L.SetHook(null, 0, 0); /* reset hook */
     L.Error("interrupted!");
 }
Exemple #29
0
		private void DebugHookCallbackInternal (LuaState luaState, LuaDebug luaDebug)
		{
			try {
				var temp = DebugHook;

				if (temp != null)
					temp (this, new DebugHookEventArgs (luaDebug));
			} catch (Exception ex) {
				OnHookException (new HookExceptionEventArgs (ex));
			}
		}
Exemple #30
0
 private static int DBGetInfo(LuaState L)
 {
     LuaDebug ar = new LuaDebug();
     int arg;
     LuaState L1 = GetThread(L, out arg);
     CharPtr options = LuaLOptString(L, arg + 2, "flnSu");
     if (LuaIsNumber(L, arg + 1) != 0)
     {
         if (LuaGetStack(L1, (int)LuaToInteger(L, arg + 1), ar) == 0)
         {
             LuaPushNil(L);  /* level out of range */
             return 1;
         }
     }
     else if (LuaIsFunction(L, arg + 1))
     {
         LuaPushFString(L, ">%s", options);
         options = LuaToString(L, -1);
         LuaPushValue(L, arg + 1);
         LuaXMove(L, L1, 1);
     }
     else
         return LuaLArgError(L, arg + 1, "function or level expected");
     if (LuaGetInfo(L1, options, ar) == 0)
         return LuaLArgError(L, arg + 2, "invalid option");
     LuaCreateTable(L, 0, 2);
     if (strchr(options, 'S') != null)
     {
         SetTabsS(L, "source", ar.source);
         SetTabsS(L, "short_src", ar.short_src);
         SetTabSI(L, "linedefined", ar.linedefined);
         SetTabSI(L, "lastlinedefined", ar.lastlinedefined);
         SetTabsS(L, "what", ar.what);
     }
     if (strchr(options, 'l') != null)
         SetTabSI(L, "currentline", ar.currentline);
     if (strchr(options, 'u') != null)
         SetTabSI(L, "nups", ar.nups);
     if (strchr(options, 'n') != null)
     {
         SetTabsS(L, "name", ar.name);
         SetTabsS(L, "namewhat", ar.namewhat);
     }
     if (strchr(options, 'L') != null)
         TreatStackOption(L, L1, "activelines");
     if (strchr(options, 'f') != null)
         TreatStackOption(L, L1, "func");
     return 1;  /* return table */
 }
Exemple #31
0
 private static int DBGetLocal(LuaState L)
 {
     int arg;
     LuaState L1 = GetThread(L, out arg);
     LuaDebug ar = new LuaDebug();
     CharPtr name;
     if (LuaGetStack(L1, LuaLCheckInt(L, arg + 1), ar) == 0)  /* out of range? */
         return LuaLArgError(L, arg + 1, "level out of range");
     name = LuaGetLocal(L1, ar, LuaLCheckInt(L, arg + 2));
     if (name != null)
     {
         LuaXMove(L1, L, 1);
         LuaPushString(L, name);
         LuaPushValue(L, -2);
         return 2;
     }
     else
     {
         LuaPushNil(L);
         return 1;
     }
 }
Exemple #32
0
 static void lstop(LuaState L, LuaDebug ar)
 {
     Lua.LuaSetHook(L, null, 0, 0);
     Lua.LuaLError(L, "interrupted!");
 }
Exemple #33
0
		static void DebugHookCallback (LuaState luaState, LuaDebug debug)
		{
Exemple #34
0
 private static int CO_Status( ILuaState lua )
 {
     ILuaState co = lua.ToThread( 1 );
     lua.L_ArgCheck( co != null, 1, "coroutine expected" );
     if( (LuaState)lua == (LuaState)co )
         lua.PushString( "running" );
     else switch( co.Status )
     {
         case ThreadStatus.LUA_YIELD:
             lua.PushString( "suspended" );
             break;
         case ThreadStatus.LUA_OK:
         {
             LuaDebug ar = new LuaDebug();
             if( co.GetStack( 0, ar ) ) // does it have frames?
                 lua.PushString( "normal" );
             else if( co.GetTop() == 0 )
                 lua.PushString( "dead" );
             else
                 lua.PushString( "suspended" );
             break;
         }
         default: // some error occurred
             lua.PushString( "dead" );
             break;
     }
     return 1;
 }
Exemple #35
0
 public void TestGetStack()
 {
     LuaState L = null;
     using (L = new LuaState())
     {
         L.PushNumber(23);
         L.PushFunction(l => {
             var ar = new LuaDebug();
             Assert.Throws<NotImplementedException>(() => l.GetStack(0, ar));
             //Assert.Equal(0, l.GetStack(0, ar));
             //Assert.Equal(0, ar.currentline);
             return 0;
         });
         L.PCall(0, 0, 0);
     }
 }
Exemple #36
0
		public int GetInfo (string what, ref LuaDebug ar)
		{
			return LuaCore.LuaGetInfo (luaState, what, ref ar);
		}
Exemple #37
0
		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;
		}
 public DebugHookEventArgs(LuaDebug luaDebug)
 {
     this.luaDebug = luaDebug;
 }
Exemple #39
0
 private void FuncInfo( LuaDebug ar, StkId func )
 {
     var ccl = func.Value as LuaCSharpClosure;
     var lcl = func.Value as LuaLClosure;
     if( ccl != null )
     {
         ar.Source = "=[C#]";
         ar.LineDefined = -1;
         ar.LastLineDefined = -1;
         ar.What = "C#";
     }
     else if( lcl != null )
     {
         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";
     }
     if( ar.Source.Length > LuaDef.LUA_IDSIZE )
     {
         ar.ShortSrc = ar.Source.Substring(0, LuaDef.LUA_IDSIZE);
     }
     else ar.ShortSrc = ar.Source;
 }
Exemple #40
0
		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;
		}
Exemple #41
0
 private static int DBSetLocal(LuaState L)
 {
     int arg;
     LuaState L1 = GetThread(L, out arg);
     LuaDebug ar = new LuaDebug();
     if (LuaGetStack(L1, LuaLCheckInt(L, arg + 1), ar) == 0)  /* out of range? */
         return LuaLArgError(L, arg + 1, "level out of range");
     LuaLCheckAny(L, arg + 3);
     LuaSetTop(L, arg + 3);
     LuaXMove(L, L1, 1);
     LuaPushString(L, LuaSetLocal(L1, ar, LuaLCheckInt(L, arg + 2)));
     return 1;
 }
Exemple #42
0
        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);
        }
Exemple #43
0
		static void DebugHookCallback (LuaState luaState, LuaDebug debug)
		{
			ObjectTranslator translator = ObjectTranslatorPool.Instance.Find (luaState);
			Lua lua = translator.Interpreter;
			lua.DebugHookCallbackInternal (luaState, debug);
		}
Exemple #44
0
 /// <summary>
 /// Gets information about a specific function or function invocation. 
 /// </summary>
 public int GetInfo(String what, LuaDebug ar)
 {
     throw new NotImplementedException();
 }
Exemple #45
0
 /// <summary>
 /// Gets information about a local variable of a given activation record or a given function. 
 /// </summary>
 public String GetLocal(LuaDebug ar, int n)
 {
     throw new NotImplementedException();
 }
Exemple #46
0
		private static void DebugHookCallback (LuaState luaState, LuaDebug luaDebug)
		{
			var translator = ObjectTranslatorPool.Instance.Find (luaState);
			var lua = translator.Interpreter;

			lua.DebugHookCallbackInternal (luaState, luaDebug);
		}
Exemple #47
0
 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) ? ci.CurrentLine : -1;
                 break;
             }
             case 'u':
             {
                 var ccl = func.Value as LuaCSharpClosure;
                 var lcl = func.Value as LuaLClosure;
                 if( ccl != null )
                 {
                     ar.NumUps = ccl.Upvals.Count;
                     ar.IsVarArg = true;
                     ar.NumParams = 0;
                 }
                 else if( lcl != null )
                 {
                     ar.NumUps = lcl.Upvals.Count;
                     ar.IsVarArg = lcl.Proto.IsVarArg;
                     ar.NumParams = lcl.Proto.NumParams;
                 }
                 break;
             }
             case 't':
             {
                 ar.IsTailCall = (ci != null)
                     ? ( (ci.CallStatus & CallStatus.CIST_TAIL) != 0 )
                     : false;
                 break;
             }
             case 'n':
             {
                 if( ci != null
                     && ((ci.CallStatus & CallStatus.CIST_TAIL) == 0)
                     && ci.Previous.IsLua )
                 {
                     ar.NameWhat = GetFuncName( ci.Previous, 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;
 }
Exemple #48
0
		/// <summary>
		/// Sets local (see lua docs)
		/// </summary>
		/// <param name = "luaDebug">lua debug structure</param>
		/// <param name = "n">see lua docs</param>
		/// <returns>see lua docs</returns>
		/// <author>Reinhard Ostermeier</author>
		public string SetLocal (LuaDebug luaDebug, int n)
		{
			return LuaCore.LuaSetLocal (luaState, luaDebug, n).ToString ();
		}
Exemple #49
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="luaDebug">LuaDebug structure for the entry.</param>
 internal CallStackEntry(LuaDebug luaDebug)
 {
     m_LuaDebug = luaDebug;
 }