Game Development Reference
In-Depth Information
private string StubWrapper(string innerCode)
{
Note
The full source code for this method is available on the Companion Web site.
}
The next method is the meat of our scripting engine; it is in charge of building
complete source code, including the stub code, setting up the CodeDom compiler
instance, and building the in-memory assembly for execution. A notable area is the
list of references where you specify the dependencies to include. Keep this refer-
ence list as small as possible for security. The user should only have access to the
functionality you provide.
Caution
Do not add every class library in the .NET framework for the heck of it. Many problems will arise
from this, including a number of security vulnerabilities, even with code access security configured.
The rule of thumb is to list only the references you need after carefully considering what your users
need access to.
The next important area is where compilation errors are handed. Do not worry
about the code lines that reference ObjectHost ; we will cover that shortly. You can,
however, notice the information that is available for each error. We can use this
information to display compilation errors to the user when we build the user
interface for our command window.
Finally, the most important area is near the end, where reflection is used to find
the Run() method within our in-memory assembly after compilation. This method
is then executed to run the script logic sent to this class.
The following method describes the compilation logic for the script engine.
public bool Execute(string innerCode)
{
Note
The full source code for this method is available on the Companion Web site.
}
}
}
 
Search Nedrilad ::




Custom Search