Compiling Scripts

Compiling a script is pretty easy:

StreamReader reader = new StreamReader("ScriptFile.txt");
FScript      script = FerrScriptCompiler.Inst.Compile(reader.ReadToEnd());
reader.Close();

The compiler only compiles strings, so you'll have to read it from file yourself, but that's not so hard, now is it?

If there were any errors during the compilation, they will be listed in FerrScriptCompiler.Inst.Errors, and your script will be NULL.

Once the script is loaded, you can call it:
ScriptValue sv = scripts.Run();

Or you can call a specific function from the script:
ScriptValue sv = script.CallFunction("Factorial", new object[] { 6 });

ScriptCore

There's also an idea here called a ScriptCore. The ScriptCore allows you to swap out all the variables in the script, and replace it with a different set. This is great for situations when you use one script to control multiple objects, as you can swap out cores for each object, so each one remembers their own variables.
ScriptCore myCore = script.GetDefaultCore();
...
script.SetCore(myCore);
script.Run();
script.GetCore(ref myCore);

Last edited Apr 10, 2011 at 11:24 PM by koujaku, version 12

Comments

No comments yet.