Created
March 27, 2009 06:39
-
-
Save jschementi/86573 to your computer and use it in GitHub Desktop.
PythonEngine class used in Calculator Scripting blog post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PythonEngine { | |
private ScriptEngine _engine; | |
private ScriptScope _scope; | |
public PythonEngine() { | |
var setup = DynamicApplication.CreateRuntimeSetup(); | |
setup.DebugMode = true; | |
var runtime = new ScriptRuntime(setup); | |
_engine = Python.GetEngine(runtime); | |
_scope = null; | |
} | |
public object Execute(string code) { | |
_scope = _engine.CreateScope(); | |
return _engine.Execute(code, _scope); | |
} | |
public ScriptScope Scope { get { return _scope; } } | |
public IList<string> ListOfMethods() { | |
return _engine.Operations.GetMemberNames(_scope); | |
} | |
public object CallMethod(string methodName, object argument) { | |
return _engine.Operations.InvokeMember( | |
_scope, methodName, new object[] { argument } | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment