diff --git a/FSharpScriptEngine.fs b/FSharpScriptEngine.fs index cfad1ef..96820dc 100644 --- a/FSharpScriptEngine.fs +++ b/FSharpScriptEngine.fs @@ -29,6 +29,13 @@ type FSharpEngine(host: IScriptHost) = let commonOptions = [| "c:\\fsi.exe"; "--nologo"; "--readline-"; "--noninteractive"|] let session = FsiEvaluationSession.Create(fsiConfig, commonOptions, stdin, stdout, stderr) + do + session.EvalInteraction("let env = new System.Collections.Generic.Dictionary()") + let result = session.EvalExpression("System.Action(fun k v -> env.Add(k, v))") + match result with + | Some value -> let func : Action = unbox value.ReflectionValue in func.Invoke("Host", box host) + | None -> failwith "The system is down" + let (>>=) (d1:#IDisposable) (d2:#IDisposable) = { new IDisposable with member x.Dispose() = diff --git a/scripts/test.fsx b/scripts/test.fsx new file mode 100644 index 0000000..c9ab7f8 --- /dev/null +++ b/scripts/test.fsx @@ -0,0 +1,25 @@ +(* +let x = 1 +let y = 2 +x + y +|> printfn "%i" + +let fizzbuzz n = + let rec loop acc n = + if n <= 0 then acc else + let result = + match n % 3, n % 5 with + | 0, 0 -> "FizzBuzz" + | 0, _ -> "Fizz" + | _, 0 -> "Buzz" + | _, _ -> string n + loop (result::acc) (n - 1) + loop [] n + +fizzbuzz 10 +|> List.iter (printfn "%s") +*) + +let host : ScriptCs.Contracts.IScriptHost = unbox env.["Host"] +let adder = host.Require() +adder.Add(3, 4) |> printfn "%i"