Пример #1
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)
        {
            IntPtr ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug));

            System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false);
            try
            {
                return(LuaDLL.lua_setlocal(luaState, ld, n));
            }
            finally
            {
                System.Runtime.InteropServices.Marshal.FreeHGlobal(ld);
            }
        }
Пример #2
0
        /// <summary>
        /// Gets info (see lua docs)
        /// </summary>
        /// <param name="what">what (see lua docs)</param>
        /// <param name="luaDebug">lua debug structure</param>
        /// <returns>see lua docs</returns>
        /// <author>Reinhard Ostermeier</author>
        public int GetInfo(String what, ref LuaDebug luaDebug)
        {
            IntPtr ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug));

            System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false);
            try
            {
                return(LuaDLL.lua_getinfo(luaState, what, ld));
            }
            finally
            {
                luaDebug = (LuaDebug)System.Runtime.InteropServices.Marshal.PtrToStructure(ld, typeof(LuaDebug));
                System.Runtime.InteropServices.Marshal.FreeHGlobal(ld);
            }
        }
Пример #3
0
        /// <summary>
        /// Gets the stack entry on a given level
        /// </summary>
        /// <param name="level">level</param>
        /// <param name="luaDebug">lua debug structure</param>
        /// <returns>Returns true if level was allowed, false if level was invalid.</returns>
        /// <author>Reinhard Ostermeier</author>
        public bool GetStack(int level, out LuaDebug luaDebug)
        {
            luaDebug = new LuaDebug();
            IntPtr ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug));

            System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false);
            try
            {
                return(LuaDLL.lua_getstack(luaState, level, ld) != 0);
            }
            finally
            {
                luaDebug = (LuaDebug)System.Runtime.InteropServices.Marshal.PtrToStructure(ld, typeof(LuaDebug));
                System.Runtime.InteropServices.Marshal.FreeHGlobal(ld);
            }
        }
Пример #4
0
 /// <summary>
 /// Delegate that is called on lua hook callback
 /// </summary>
 /// <param name="luaState">lua state</param>
 /// <param name="luaDebug">Pointer to LuaDebug (lua_debug) structure</param>
 /// <author>Reinhard Ostermeier</author>
 private void DebugHookCallback(IntPtr luaState, IntPtr luaDebug)
 {
     try
     {
         LuaDebug ld = (LuaDebug)System.Runtime.InteropServices.Marshal.PtrToStructure(luaDebug, typeof(LuaDebug));
         EventHandler <DebugHookEventArgs> temp = DebugHook;
         if (temp != null)
         {
             temp(this, new DebugHookEventArgs(ld));
         }
     }
     catch (Exception ex)
     {
         OnHookException(new HookExceptionEventArgs(ex));
     }
 }
Пример #5
0
 public int GetInfo(string what, ref LuaDebug luaDebug)
 {
     int num;
     IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf((LuaDebug) luaDebug));
     Marshal.StructureToPtr((LuaDebug) luaDebug, ptr, false);
     try
     {
         num = LuaJIT.lua_getinfo(this.luaState, what, ptr);
     }
     finally
     {
         luaDebug = (LuaDebug) Marshal.PtrToStructure(ptr, typeof(LuaDebug));
         Marshal.FreeHGlobal(ptr);
     }
     return num;
 }
Пример #6
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)
 {
    IntPtr ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug));
    System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false);
    try
    {
       return LuaDLL.lua_setlocal(luaState, ld, n);
    }
    finally
    {
       System.Runtime.InteropServices.Marshal.FreeHGlobal(ld);
    }
 }
Пример #7
0
 /// <summary>
 /// Gets info (see lua docs)
 /// </summary>
 /// <param name="what">what (see lua docs)</param>
 /// <param name="luaDebug">lua debug structure</param>
 /// <returns>see lua docs</returns>
 /// <author>Reinhard Ostermeier</author>
 public int GetInfo(String what, ref LuaDebug luaDebug)
 {
    IntPtr ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug));
    System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false);
    try
    {
       return LuaDLL.lua_getinfo(luaState, what, ld);
    }
    finally
    {
       luaDebug = (LuaDebug)System.Runtime.InteropServices.Marshal.PtrToStructure(ld, typeof(LuaDebug));
       System.Runtime.InteropServices.Marshal.FreeHGlobal(ld);
    }
 }
Пример #8
0
 /// <summary>
 /// Gets the stack entry on a given level
 /// </summary>
 /// <param name="level">level</param>
 /// <param name="luaDebug">lua debug structure</param>
 /// <returns>Returns true if level was allowed, false if level was invalid.</returns>
 /// <author>Reinhard Ostermeier</author>
 public bool GetStack(int level, out LuaDebug luaDebug)
 {
    luaDebug = new LuaDebug();
    IntPtr ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug));
    System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false);
    try
    {
       return LuaDLL.lua_getstack(luaState, level, ld) != 0;
    }
    finally
    {
       luaDebug = (LuaDebug)System.Runtime.InteropServices.Marshal.PtrToStructure(ld, typeof(LuaDebug));
       System.Runtime.InteropServices.Marshal.FreeHGlobal(ld);
    }
 }
Пример #9
0
 public DebugHookEventArgs(LuaDebug luaDebug)
 {
    this.luaDebug = luaDebug;
 }
Пример #10
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);
      }
 }
Пример #11
0
 public bool GetStack(int level, out LuaDebug luaDebug)
 {
     bool flag;
     luaDebug = new LuaDebug();
     IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf((LuaDebug) luaDebug));
     Marshal.StructureToPtr((LuaDebug) luaDebug, ptr, false);
     try
     {
         flag = LuaJIT.lua_getstack(this.luaState, level, ptr) != 0;
     }
     finally
     {
         luaDebug = (LuaDebug) Marshal.PtrToStructure(ptr, typeof(LuaDebug));
         Marshal.FreeHGlobal(ptr);
     }
     return flag;
 }
Пример #12
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();
        }
Пример #13
0
 public DebugHookEventArgs(LuaDebug luaDebug)
 {
     this.luaDebug = luaDebug;
 }
Пример #14
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;
 }
Пример #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;
      }
 }
Пример #16
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="luaDebug">LuaDebug structure for the entry.</param>
 internal CallStackEntry(LuaDebug luaDebug)
 {
     m_LuaDebug = luaDebug;
 }
Пример #17
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;
 }
Пример #18
0
 public string SetLocal(LuaDebug luaDebug, int n)
 {
     string str;
     IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(luaDebug));
     Marshal.StructureToPtr(luaDebug, ptr, false);
     try
     {
         str = LuaJIT.lua_setlocal(this.luaState, ptr, n);
     }
     finally
     {
         Marshal.FreeHGlobal(ptr);
     }
     return str;
 }
Пример #19
0
 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;
 }