1

I have following code:

m_pyScope = pyRuntime.UseFile(filename);

To load script file within IronPython runtime in C#.

The problem is that i need to register my custom functions, variables, etc to that scope, BEFORE executing this script. Code which i use now executes script body after compile.

Is there a way to make loading IronPython script like this:

  1. Compile from file or text variable
  2. Create empty scope (from Engine's createScope())
  3. Do something with that scope, for example add some function
  4. Execute script body, e.g. code which is outside any function or class
0

1 Answer 1

4

I found the solution. The best way to load script is in answer to this question:

IronPython integration in C#: a specific problem/question

Create engine from runtime, then scope, then compile source. After that you can call source.Execute(scope) to execute script in scope created before

Sign up to request clarification or add additional context in comments.

1 Comment

+1 for following up on your own question, that's useful for others. If your problem was solved, you should also accept your own answer, see stackoverflow.com/faq#howtoask. You might have to wait some time before you can accept your own answer (48h or so). It will get you a badge too :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.