ScriptScope
: Every
ScriptRuntime
can contain multiple
ScriptScope
s. A
ScriptScope
can provide variable binding isolation. In addition, you can use a
ScriptScope
to give exe-
cutable code specific permissions.
Now that you have a better idea of how the pieces fit together, it’s important to consider which
pieces you use to embed scripting support within an application. Generally, if you want basic code
(Level 1) support, all you need are the objects shown in green at
http://www.flickr.com/photos/
john_lam/2220796647/
. In fact, if you want to use the default
ScriptScope
settings, all you really
need to do is create the
ScriptRuntime
and then use the default
ScriptScope
.
Considering the Host Application
A host has to meet specific requirements before it can run IronPython as a scripting language.
Chapter 15 discusses more of the details for C# and Visual Basic.NET developers. You’ll find that
C# and Visual Basic.NET provide everything you need. However, it’s interesting to see just what
the requirements are, especially if you’re using an older version of these languages. Section 3 of the
DLR-Spec-Hosting.DOC
file found in the
\Codeplex-DLR-0.92\Docs
folder contains complete
information about the hosting requirements. Section 3.3 (and associated subsections) are especially
important for most developers to read if they plan to use the Hosting APIs for anything special.
Embedding IronPython as a Scripting Language
Imagine that you’ve created a custom editor in your application where users can write IronPython
scripts. They then save the script to disk (or you could read it from memory), and then they assign
the script to a button or menu in your application. When the user selects the button or menu, your
application executes the script. Creating this scenario isn’t as hard as you might imagine. DLR
comes with most of the functionality you need built in.
Of course, you need a test script to start. Listing 14-1 shows the test script for this example. The
example is purposely simple so that the example doesn’t become more focused on the IronPython
code than the code that executes it. However, you could easily use any script you want as long as
it’s a legitimate IronPython script.
548592c14.indd 295
2/24/10 12:49:05 PM
www.finebook.ir
Do'stlaringiz bilan baham: |