Skip to main content

Thoughts on scripting

I mentioned script-driven classes, without going into detail what I mean with this. Read on for some thoughts on scripting. Note that nothing of this has been implemented, and it is mostly just ideas that I carry around without having time to implement them properly.

The script side

The scripts would run in some kind of ScriptVM, probably a stack-based machine. Calling script code from C++ would invoke populating the stack with the appropriate parameters, and invoking a script method. The script method names and their parameters would be stored in some global array inside the ScriptVM. When a script is called, the ScriptVM processes each of the compiled opcodes and operates on the script stack only. If another scipt function is invoked from a script, the operation would be the same as if it was called from C++.


The simpler side. Calling scripts would mean: The user knows what variables the script expects and what function. With a script function void func (int, int):

ScriptVM->stack->push<int> (param1);
ScriptVM->stack->push<int> (param2);


This way is more difficult. A possible solution is that when a C++ class is made scriptable, a new wrapper class is generated. For example, assume we have a C++ call void func(int,int);. The wrapper would look like this this:

extern "C" void scr_func (Stack& stack) 
    int p1 = stack->pop();
    int p2 = stack->pop();
    func (p1, p2);

So much for now, maybe I get some prototype working, then you'll get more ideas.