Parsing a script takes a bit of time and when that happens compiling your script might be a better option. Compiling a script can have huge performance advantages.


Create a script with some triggers.

Load the script into a Page by parsing it using a MonkeyspeakEngine instance.
using (Stream stream = new FileStream("test.msx", FileMode.Open))
    Page page = msEngine.LoadFromStream(stream);

Now that we have a Page we need to compile it we do that by calling one of the many Compile methods in Page. Page contains the CompileToStream and CompileToFile methods.
Now in your file system should be a "test.msx" file.


From the tutorial above you should have a "test.msx" file in your file system.
Loading a compiled script is much faster then loading a non-compiled script. This is because Monkeyspeak has to parse that non-compiled script again even if it did before. Parsing takes a lot of time. So it makes sense to edit your non-compiled script in an editor, compile it and then load the compiled script into your program.

MonkeyspeakEngine comes with a LoadCompiledFile method for loading compiled scripts. Easy as pie.
Important: Compiling does not compile your TriggerHandlers into the compiled script you must add your libraries to the Page again after you load a compiled script.
Page page = msEngine.LoadCompiledScript("test.msx");
Now you are good to go and you can use it as you would any other Page.

Last edited Jun 20, 2012 at 10:43 PM by Squizzle, version 1


No comments yet.