Home > Programming > rScript 1.2 released

rScript 1.2 released

It’s been less than a week and I’ve already released a 2nd update to the rScript Engine. Version 1.2 includes a couple nice features that required quiet a bit of re-coding in order to get them built in, but it went together smoothly and I think the changes make the engine a much better solution than it was in version 1.1.

So what changed? For starters, the ScriptRepository property was removed and the Compile() method gained three variations to itself. You can now compile a directory full of scripts, a single file or raw source code.

Here is an example of compiling a complete directory.

static void CompileScriptRepository()
        {
            //The directory that contains a collection of scripts.
            String scriptRepository = "Scripts";

            //Compile all scripts within that directory.
            Boolean isCompiled = _CompileEngine.Compile(scriptRepository);

            //Check for any compiler errors.
            if (!isCompiled)
            {
                Console.WriteLine(_CompileEngine.Errors);
            }
        }

And another example, this time showing how to compile a single file.

static void CompileScriptFile()
       {
           //The script file that we will compile
           System.IO.FileInfo file = new System.IO.FileInfo(@"Scripts\Wheel.cs");

           //Compile our source script file. Script engine will perform file existance checking prior to compiling.
           Boolean isCompiled = _CompileEngine.Compile(file);

           //Check for any compiler errors.
           if (!isCompiled)
           {
               Console.WriteLine(_CompileEngine.Errors);
           }
       }

Lastly, how to compile raw source code.

static void CompileSource()
        {
            //Construct an array of strings with raw source code.
            String[] sourceCode = new String[] {"namespace SampleSource {\n" + 
                "public class SampleClass {" +
                "public int Size = 20; " +
                "public Double Width" +
                "{" +
                    "get" +
                    "{" +
                      "return 8.5;" +
                    "}" +
                "}" + 
                "public void GetTireBrand() {" + 
                    "System.Windows.Forms.MessageBox.Show(\"Super Tire Co.\");" +
                 "}" + 
                 "}" + 
                 "}"
            };

            //Compile the source code
            Boolean isCompiled = _CompileEngine.Compile(sourceCode);

            //Check for any compiler errors.
            if (!isCompiled)
            {
                Console.WriteLine(_CompileEngine.Errors);
            }
        }

What’s next? I’ve already started work on implementing a IronPython Compiler Wrapper. I’m sure developers would like being able to supply a Python script engine with their application wrote in C# or VB. I’m also working on getting a Windows Phone 7 version of the engine compiled. Be nice to write your Python scripts once, include the scripts in your PC app and then ship pre-compiled scripts with your WP7 app and still have access to dynamic method invoking and property accessing.

Advertisements
Categories: Programming
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: