Exemple #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);
            }
        }
Exemple #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);
            }
        }
Exemple #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);
            }
        }
Exemple #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));
     }
 }
Exemple #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;
 }
Exemple #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);
    }
 }
Exemple #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);
    }
 }
Exemple #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);
    }
 }
Exemple #9
0
 public DebugHookEventArgs(LuaDebug luaDebug)
 {
    this.luaDebug = luaDebug;
 }
 /// <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 #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;
 }
        /// <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();
        }
Exemple #13
0
 public DebugHookEventArgs(LuaDebug luaDebug)
 {
     this.luaDebug = luaDebug;
 }
 /// <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;
 }
 /// <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;
      }
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="luaDebug">LuaDebug structure for the entry.</param>
 internal CallStackEntry(LuaDebug luaDebug)
 {
     m_LuaDebug = luaDebug;
 }
 /// <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 #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;
 }
 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;
 }