Scripting Engine with C#

Started by
2 comments, last by Rob Loach 18 years, 5 months ago
I'm designing a scripting system for my engine. The engine is writing in managed c++ and I need to write a scripting system that works with c# or VB. My plans are to make an interface object called IScript. The actual object will be behind the interface so we can update it while the engine is running. I also need to display these objects in a property grid so when they select an object they can change the properties. First question: When loading a script it loads into an assembly. As most people already know is that you can unload these assemblies. People talk about creating an app-domain for each script so you can unload these but calling across app domain bounds can be slow and I need to assign this object to a property grid. I believe the property grid needs the type information for that to work so I don't think that this will work. So I though of loading the scripts and putting them in to a list of active scripts, then if one script gets changed I’ll put the old assembly into an inactive list. I don't think the small amount of memory would be that big of a problem. This will only happen while in editor mode. I just want to know if this sounds right? Second question: I have to assign these objects to a property grid. So the property grid needs the actual object. Should I let it access the object behind the IScript or create a clone of that object and then if they change any properties serialize it over to the object behind the IScript? Again I just want to know if this sounds right? Anything will help so I pre thank everyone for posting!
Advertisement
Alternatively you could use my GakScript engine. It wraps .NET's CodeDom namespace into a managable interface. You tell it what language you want to script in (C#, VB.NET, Boo, etc), give it the code and the assembly references and then compile it. From the compiled assembly you can invoke methods, create instances of scripted objects, etc. </selfplug>
Rob Loach [Website] [Projects] [Contact]
Quote:Original post by Rob Loach
Alternatively you could use my GakScript engine. It wraps .NET's CodeDom namespace into a managable interface. You tell it what language you want to script in (C#, VB.NET, Boo, etc), give it the code and the assembly references and then compile it. From the compiled assembly you can invoke methods, create instances of scripted objects, etc. </selfplug>


I don't think this is what he was looking for at all. It sounds like much of what your wrapper does he's already got. I'm running into the same roadblock as cforlife. That is, how to interface a scripted object to the user so they can alter it at runtime and serialize the data over to the new object. I can't seem to find any related articles on the net.
Quote:Original post by segt
That is, how to interface a scripted object to the user so they can alter it at runtime....
Well, if you use GakScript, you could make a scripted function called something like MakePersonOlder that you pass in a Person object written in C#:
// Person.csusing System;namespace ScriptingTest{    public class Person    {        public string FirstName = "Unknown";        public string LastName = "Unknown";        public int Age = 0;        public Person(string first, string last){            FirstName = first;            LastName = last;        }    }}


// Script file (script.boo)import ScriptingTestdef MakePersonOlder( Person p ):    p.Age = p.Age + 1


And then to use it with GakScript, you'd do something like this:
namespace ScriptingTest{public static Person segt = new Person("KickAss", "Guy");// in mainGakScripter script = new GakScripter(new GakScript.Languages.Boo());script.AddCodeFromFile("script.boo");script.AddReference();script.Compile();Console.WriteLine("segt's Age: " + segt.Age);script.Invoke("SourceModule", "MakePersonOlder", ScriptingTest.segt);Console.WriteLine("segt's Age: " + segt.Age); // now one older}
Rob Loach [Website] [Projects] [Contact]

This topic is closed to new replies.

Advertisement