Skip to content

Instantly share code, notes, and snippets.

@jschementi
Created March 27, 2009 06:39
Show Gist options
  • Save jschementi/86573 to your computer and use it in GitHub Desktop.
Save jschementi/86573 to your computer and use it in GitHub Desktop.
PythonEngine class used in Calculator Scripting blog post
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