TXScript + DotScript Update; Re-named to Managed Scripting
by Johnathon · 07/01/2009 (3:48 pm) · 2 comments
I was working on integrating TXScript with my DotScript scripting engine when I ran into several issues. One was I lacked a solid XNA port of the script engine, which made programming how the engine handled TXScripts difficult, DotScript it self was not finished, so I found myself having a hard time managing the three projects. (.NET support, XNA support & Torque X). The straw that finally broke the camels back was trying to maintain three seperate builds of the engine. The changes made in the .NET version had to be copied over to the XNA and Torque X version. In the end, I decided to perform a major over hual on the entire engine, and re-name it as Managed Scripting, since in essence, that's what it is.
Managed Scripting comes in two flavors at the moment:
Managed Scripting .NET (PC/LINUX)
Managed Scripting XNA (PC/XBOX/ZUNE)
I learned how to use compiler directives with C# and so now I'm just working on one code base, that all 5 platforms share. Changes I make on the PC side, are reflected instantly on the linux, xbox and zune platforms thanks to Visual Studios nifty 'Link-File' feature. With that having been said, the engine was re-wrote and now supports multiple compilers.
Source Code Compiler
This accepts source code and compiles it. Nothing really fancy.
Example
Script Compiler
This accepts actual files wrote in either VB or C# and compiles them into an assembly.
Example
Hybrid Compiler
My pride and joy. Managed Scripting has a ClassGenerator that will simplify the creation of methods, properties and classes during an applications runtime. For something like Torque X this is great, as it allows developers to create an IDE (or myself once I begin work on Managed Scripting Torque) and give 3rd party users or themselves a more visual way of creating methods, properties and classes. Classes created using the ClassGenerator can be added to a ClassLibrary and sent to the Hybrid Compiler. The compiler then merges the properties, methods and class information into a single class for each instance of the generator found in the library, and generates a class. Once all of the classes have been created they are sent to the compiler for compiling into an assembly. There's a lot more that can be done with both the compiler and the class generator but I'll leave that for later.
The example below shows how the script engine could be implemented into your C# applications or Torque X projects using a MethodSetup class to setup some information about a method we want to make. It then creates an instance of the ClassGenerator class and gives it the method. At this point we create the class, instance a script engine and compile it.
Example
If you wanted you could use the following line of code
and it will create the class code for you and let you do what you want with it. You can at any time make adjustments to the class by adjusting it's properties (such as newClass.Modifier = public) and re-create the class and re-send it to the compiler. The code we used above created the following class when the newClass.Create() method was used.
As you can see, you can customize how your application will handle a script. It can be a very easy setup, or a much more customized implementation. Hopefully this will speed up development of some Torque X games once it is available, and easily add 3rd party support for modifications. The engine is pretty flexible as it will compile single methods by themselves, by wrapping it in a temporary class during compilation, and can also support visual basic or C#.
My next post will demonstrate accessing these scripts once they've been compiled into an assembly (either in memory or locally on the hard-drive) and how to instance them and invoke their methods.
The .NET and XNA versions are almost ready for beta release, and the Torque X will come soon afterwards. I will be looking for private beta testers for the torque version when it is ready and hopefully some of the garage games community will be able to use it and find it useful.
Till the next update~
Managed Scripting comes in two flavors at the moment:
Managed Scripting .NET (PC/LINUX)
Managed Scripting XNA (PC/XBOX/ZUNE)
I learned how to use compiler directives with C# and so now I'm just working on one code base, that all 5 platforms share. Changes I make on the PC side, are reflected instantly on the linux, xbox and zune platforms thanks to Visual Studios nifty 'Link-File' feature. With that having been said, the engine was re-wrote and now supports multiple compilers.
Source Code Compiler
This accepts source code and compiles it. Nothing really fancy.
Example
ScriptingEngine engine = new ScriptingEngine(); string code = TextBox1.Text; engine.Compiler = ScriptingEngine.CompilerSelections.SourceCompiler; string results = engine.Compile(code);
Script Compiler
This accepts actual files wrote in either VB or C# and compiles them into an assembly.
Example
ScriptingEngine engine = new ScriptingEngine(); string[] scripts = System.IO.Directory.GetFiles(@"C:MyProjectScripts", "*.vb"); engine.Compiler = ScriptingEngine.CompilerSelections.ScriptCompiler; engine.Language = BaseCompiler.ScriptLanguages.VB; engine.FrameworkVersion = BaseCompiler.CompilerVersion.V35; engine.Compile(scripts);
Hybrid Compiler
My pride and joy. Managed Scripting has a ClassGenerator that will simplify the creation of methods, properties and classes during an applications runtime. For something like Torque X this is great, as it allows developers to create an IDE (or myself once I begin work on Managed Scripting Torque) and give 3rd party users or themselves a more visual way of creating methods, properties and classes. Classes created using the ClassGenerator can be added to a ClassLibrary and sent to the Hybrid Compiler. The compiler then merges the properties, methods and class information into a single class for each instance of the generator found in the library, and generates a class. Once all of the classes have been created they are sent to the compiler for compiling into an assembly. There's a lot more that can be done with both the compiler and the class generator but I'll leave that for later.
The example below shows how the script engine could be implemented into your C# applications or Torque X projects using a MethodSetup class to setup some information about a method we want to make. It then creates an instance of the ClassGenerator class and gives it the method. At this point we create the class, instance a script engine and compile it.
Example
//Instance a new MethodSetup & Class Generator and then a library to hold the final class in.
ClassGenerator.MethodSetup method = new ClassGenerator.MethodSetup();
ClassGenerator newClass = new ClassGenerator();
ScriptLibrary library = new ScriptLibrary();
//Setup the method.
method.Name = "MyFunction"; //Name of the method
method.ReturnType = "string"; //The type that the method will return.
method.Code = new string[] { "return "Hello World!";" }; //The body of the method
//Setup the class.
newClass.ClassName = "MyClass";
newClass.Namespace = "MyNamespace";
newClass.AddMethod(method); //Add the method to the class.
//Add the class to the library.
library.AddScript(newClass);
//Instance a new compiler.
ScriptingEngine engine = new ScriptingEngine();
//Tell the engine we want to use the Hybrid Compiler
engine.Compiler = ScriptingEngine.CompilerSelections.HybridCompiler;
//Compile
string results = engine.Compile(library);
//Print out the results of the compilation.
Console.WriteLine(results);If you wanted you could use the following line of code
string code = newClass.Create();
and it will create the class code for you and let you do what you want with it. You can at any time make adjustments to the class by adjusting it's properties (such as newClass.Modifier = public) and re-create the class and re-send it to the compiler. The code we used above created the following class when the newClass.Create() method was used.
namespace MyNamespace
{
public class MyClass
{
public string MyFunction()
{
return "Hello World!";
}
}
}As you can see, you can customize how your application will handle a script. It can be a very easy setup, or a much more customized implementation. Hopefully this will speed up development of some Torque X games once it is available, and easily add 3rd party support for modifications. The engine is pretty flexible as it will compile single methods by themselves, by wrapping it in a temporary class during compilation, and can also support visual basic or C#.
My next post will demonstrate accessing these scripts once they've been compiled into an assembly (either in memory or locally on the hard-drive) and how to instance them and invoke their methods.
The .NET and XNA versions are almost ready for beta release, and the Torque X will come soon afterwards. I will be looking for private beta testers for the torque version when it is ready and hopefully some of the garage games community will be able to use it and find it useful.
Till the next update~
About the author
#2
As for not understanding my project, it has the same goal and features as DotScript. If you are interested in reading into it a little more, you can visit the website at www.managedscripting.com and review the features page. If you are planning on using DotScript I would recommend waiting a couple weeks till Managed Scripting is released. I'm no longer working on DotScript, as Managed Scripting will be replacing it.
07/02/2009 (5:51 pm)
Hey Diego, you are correct in the fact that DotScript is able to run along side XNA with out any modifications really. However, when I wrote DotScript, I didnt add any XNA support for things such as the GameComponent or the DrawableGameComponent. Also I'm not sure how stable the engine is. As far as whats the difference? I basically took my original source for DotScript and re-worked every aspect of it to increase stability, performance and make it easier to use. Managed Script is just a new version of my DotScript engine, renamed with additional features. The XNA version of the engine allows classes to inherit from GameComponent and DrawableGameComponent, and a Torque X version of it will allow scripts to 'plug-in' as additional components that can be added to objects within the game, instead of acting like normal C# scripts, they'll act and work like an internal Torque X C# component.As for not understanding my project, it has the same goal and features as DotScript. If you are interested in reading into it a little more, you can visit the website at www.managedscripting.com and review the features page. If you are planning on using DotScript I would recommend waiting a couple weeks till Managed Scripting is released. I'm no longer working on DotScript, as Managed Scripting will be replacing it.

Torque Owner Diego Santos Leao - GameBlox Studio
What is the advantage of using your software instead of DotScript? In fact, I'm not sure I understood your project...
What you described above is not available in standard DotScript? I thought that DotScript generated C# assembly at runtime, so it should just run fine with XNA. What modifications were necessary?