Developing a scripting system ON TOP OF C#

It’s a darn shame that it may come to that. I’m looking into the possibility of writing a script language API on top of Unity’s C#. The biggest, and possibly the only driver, is coroutine state persistence. I need a system that resumes all coroutines where they left off when the game level was saved.

I don’t see that its possible in Unity to set up a game save and load system that accounts for coroutine states. Maybe that’s the price to pay for the efficiency you get with JIT. I don’t need such blazing efficiency for the relatively few coroutines I’ll have running.

I’m curious if anyone has ever come across a light, open-source script language/system in C++ or C# (likely will need some conversion), that might lend itself well to what I need to do.

The plan would be to have a compiler of some sort crank out a C# file containing arrays for the byte code etc. I don’t need any help with the specifics of that though.

Can you give an example of exactly what you’re trying to do with the resumable co-routines? I’m just wondering if you could go about it in a much simpler way by tracking some state variables and resuming execution based off those variables rather than implementing an entirely new scripting language on top of C#.

Yeah I thought of a state variable approach, which would become ugly as sin. As far as what we’re trying to do: pretty much everything that coroutines are good for. It’s not just an isolated design hurdle.

A few examples (among billions):

yield WaitForSeconds(3);
yield myGui.MultipleChoice(Question, AnswerArray);
if (myGui.GetResult() == 2)
{
   while (!FunctionThatChecksSomeCondition())
   {
      yield;
   }
}

But we’ll have many, many pages of such code. A “naked” state machine is not really the answer, but rather, our interpreted byte code and data (in arrays) would be processed by a hidden state machine, i.e. a virtual machine.

We really want the full power of coroutines for a variety of reasons, but with the ability to persist (or pickle) the coroutine’s state and start in a different session, where it left off. This can be done with Lua and Stackless Python, but those are different animals.