Advertisement
Guest User

F# compiler provider for unity(unfinished and forgotten)

a guest
Sep 4th, 2012
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 2.52 KB | None | 0 0
  1. // Learn more about F# at http://fsharp.net
  2. //type public FSCom () =
  3. //        inherit UnityEngine.MonoBehaviour()
  4. //        member public b.mx x = x
  5. //        member public x.Start () = Debug.Log("lala")
  6.  
  7. namespace FSGCOM
  8. module _Gatherer =
  9.     open System
  10.     open System.IO
  11.     open System.CodeDom.Compiler
  12.     open Microsoft.FSharp.Compiler.CodeDom
  13.     open UnityEngine
  14.     //let FindAllInCurrentDir (filetype:String) : string array =
  15.     //    System.IO.Directory.GetFiles("Assets/",filetype,SearchOption.AllDirectories)
  16.     //let DumpAllFiles (files : string array) = for file in files do Console.WriteLine(file)
  17.     let CompileFiles (files :string array) =
  18.         if(File.Exists(@"Assets/Assembly/scripts.dll")) then File.Delete(@"Assets/Assembly/scripts.dll")
  19.         let mutable compiler = new  Microsoft.FSharp.Compiler.CodeDom.FSharpCodeProvider()
  20.         let mutable _params = new CompilerParameters([|"System";"System.Core";"Assets/Assembly/UnityEngine.dll";|])
  21.         _params.IncludeDebugInformation <- true
  22.         _params.OutputAssembly <- @"Assets/Assembly/scripts.dll"
  23.         let mutable res:System.Object =  compiler.CompileAssemblyFromFile(_params, files) :> System.Object
  24.         let mutable Output = res.GetType().GetProperty("Output")
  25.         let mutable Erros  = res.GetType().GetProperty("Errors")
  26.         let mutable assembly:Reflection.Assembly = res.GetType().GetProperty("CompiledAssembly").GetValue(res,Array.empty<System.Object>) :?> Reflection.Assembly
  27.         for logmessage in (Output.GetValue(res,Array.empty<System.Object>) :?> System.Collections.Specialized.StringCollection)  do Debug.Log(logmessage)
  28.         for error in (Erros.GetValue(res,Array.empty<System.Object> ) :?> System.Collections.CollectionBase) do Debug.LogError(error)
  29.         //Debug.Log(assembly)
  30.         //assembly.GetModule("scripts.dll").GetTypes().[0].GetMethod("Start").Invoke(null,Array.empty<System.Object>)|>ignore
  31.         //for _method:Reflection.MethodInfo in assembly.GetModule("scripts.dll").GetTypes().[2].GetMethods() do Debug.Log(_method.Name)
  32.         //Debug.Log(res.PathToAssembly)
  33.         //Debug.Log(res.CompiledAssembly.FullName)
  34.         //Console.WriteLine(res.PathToAssembly)
  35.         //Console.WriteLine(res.CompiledAssembly.FullName)
  36.         //for t:System.Type in assembly.GetModule("scripts.dll").GetTypes() do for mi:Reflection.MethodInfo in t.GetMethods() do Debug.Log(t.ToString()+"|"+mi.ToString())
  37.         //t.gameObject.AddComponent(assembly.GetModule("scripts.dll").GetTypes().[2])|>ignore
  38.         res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement