Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Experiments / IronPythonViewEngine / WindowsApplication1 / Form1.cs
blobbae6a346863af4e11ec58e35f9612a19e1147b18
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace WindowsApplication1
17 using System;
18 using System.Collections.Generic;
19 using System.IO;
20 using System.Text;
21 using System.Windows.Forms;
22 using IronPython.Hosting;
24 public partial class Form1 : Form
26 private PythonEngine eng;
27 private EngineModule mod1;
28 private CompiledCode scriptCompiledCode;
30 public Form1()
32 EngineOptions options = new EngineOptions();
33 eng = new PythonEngine(options);
34 eng.Import("site");
35 System.IO.FileStream fs = new System.IO.FileStream("scripting-log.txt", System.IO.FileMode.Create);
36 eng.SetStandardOutput(fs);
37 eng.SetStandardError(fs);
39 mod1 = eng.CreateModule("mr", false);
41 InitializeComponent();
44 private void button2_Click(object sender, EventArgs e)
46 output.Text = String.Empty;
49 private void button1_Click(object sender, EventArgs e)
51 StringWriter writer = new StringWriter();
52 Dictionary<string,object> locals = new Dictionary<string, object>();
53 locals.Add("output", writer);
55 try
57 CompiledCode functionsCode = eng.Compile(functions.Text);
58 scriptCompiledCode = eng.Compile(script.Text);
60 functionsCode.Execute(mod1);
61 scriptCompiledCode.Execute(mod1, locals);
63 catch(Exception ex)
65 output.Text += Environment.NewLine + ex.Message +
66 Environment.NewLine + Environment.NewLine +
67 ex.Message +
68 Environment.NewLine + Environment.NewLine;
71 output.Text += writer.GetStringBuilder().ToString();
72 output.Text += Environment.NewLine;
73 output.Text += Environment.NewLine;
75 eng.Shutdown();
78 private void button3_Click(object sender, EventArgs e)
80 StringWriter writer = new StringWriter();
81 Dictionary<string, object> locals = new Dictionary<string, object>();
82 locals.Add("output", writer);
84 try
86 CompiledCode functionsCode = eng.Compile(functions.Text);
87 functionsCode.Execute(mod1);
89 scriptCompiledCode.Execute(mod1, locals);
91 catch (Exception ex)
93 output.Text += Environment.NewLine + ex.Message +
94 Environment.NewLine + Environment.NewLine +
95 ex.Message +
96 Environment.NewLine + Environment.NewLine;
99 output.Text += writer.GetStringBuilder().ToString();
100 output.Text += Environment.NewLine;
101 output.Text += Environment.NewLine;