} // func GetDebugInfo /// <summary>Executes the Chunk on the given Environment</summary> /// <param name="env"></param> /// <param name="callArgs"></param> /// <returns></returns> public LuaResult Run(LuaTable env, params object[] callArgs) { if (!IsCompiled) { throw new ArgumentException(Properties.Resources.rsChunkNotCompiled, "chunk"); } object[] args = new object[callArgs == null ? 0 : callArgs.Length + 1]; args[0] = env; if (callArgs != null) { Array.Copy(callArgs, 0, args, 1, callArgs.Length); } try { object r = chunk.DynamicInvoke(args); return(r is LuaResult ? (LuaResult)r : new LuaResult(r)); } catch (TargetInvocationException e) { LuaExceptionData.GetData(e.InnerException); // secure the stacktrace throw e.InnerException; // rethrow with new stackstrace } } // proc Run
} // proc WriteError private static void WriteException(Exception e) { WriteText(ConsoleColor.DarkRed, e.GetType().Name + ": "); WriteText(ConsoleColor.Red, e.Message); Console.WriteLine(); LuaExceptionData eData = LuaExceptionData.GetData(e); WriteText(ConsoleColor.DarkGray, eData.FormatStackTrace(0, true)); Console.WriteLine(); if (e.InnerException != null) { WriteText(ConsoleColor.Gray, ">>> INNER EXCEPTION <<<"); WriteException(e.InnerException); } } // proc WriteException