Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using IronPython.Hosting;
- using IronPython.Modules;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- var x = typeof(PythonMath);
- if (x == null)
- throw new Exception("Do not remove - Used to force local copy.");
- var engine = IronPython.Hosting.Python.CreateEngine();
- var script = @"def foo(y):
- return y + 1
- def bar(x):
- return foo(x)
- bar(-5)
- ";
- var ast = @"import ast
- tree = ast.parse(script)
- callback(ast.dump(tree))";
- var callback = new Action<object>(o =>
- {
- Console.WriteLine(o);
- });
- engine.SetSearchPaths(new[] { "pylib" });
- var scope = engine.CreateScope();
- scope.SetVariable("script", script);
- scope.SetVariable("callback", callback);
- engine.Execute(ast, scope);
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement