コード例 #1
0
ファイル: AsyncExtensions.cs プロジェクト: xiexin36/moonsharp
 /// <summary>
 /// Asynchronously creates a new dynamic expression.
 ///
 /// This method is supported only on .NET 4.x and .NET 4.x PCL targets.
 /// </summary>
 /// <param name="script">The script.</param>
 /// <param name="code">The code of the expression.</param>
 /// <returns></returns>
 public static Task <DynamicExpression> CreateDynamicExpressionAsync(this Script script, string code)
 {
     return(ExecAsync(() => script.CreateDynamicExpression(code)));
 }
コード例 #2
0
		public static void Generate(string language, string luafile, string destfile, bool allowInternals, string classname, string namespacename)
		{
			var logger = new ConsoleLogger();
			try
			{
				Script s = new Script(CoreModules.None);
				var eee = s.CreateDynamicExpression(File.ReadAllText(luafile));

				Table t = eee.Evaluate(null).Table;

				HardwireGeneratorRegistry.RegisterPredefined();

				HardwireGenerator hcg = new HardwireGenerator(namespacename ?? "HardwiredClasses", classname ?? "HardwireTypes", logger,
					language == "vb" ? HardwireCodeGenerationLanguage.VB : HardwireCodeGenerationLanguage.CSharp)
				{
					AllowInternals = allowInternals
				};

				hcg.BuildCodeModel(t);

				string code = hcg.GenerateSourceCode();

				File.WriteAllText(destfile, code);
			}
			catch (Exception ex)
			{
				Console.WriteLine("Internal error : {0}", ex.Message);
			}

			Console.WriteLine();
			Console.WriteLine("done: {0} errors, {1} warnings.", logger.Errors, logger.Warnings);
		}