Way back at the start of this year, I wrote about how I’d been working on a new Object Pascal-based script engine built around Delphi’s extended RTTI system. And then it got real quiet, because more immediate concerns took priority for me. But I’ve gotten to the point in my game engine development where I really need to put in the scripting system, so I spent the last couple weeks finishing up the implementation and tuning the performance a little, and now I’ve got an alpha version ready. If anyone would like to try it out, they can find it on Google Code.
Note: This is an alpha version. There are probably plenty of bugs in it. There are still features I haven’t gotten around to implementing. The sight of the code would probably send Barry Kelly fleeing from the room, screaming in horror. So use at your own risk, and I take no responsibility if this causes your system to crash, your data to come out all wrong, or demons to fly out your nose. Specifically, the program keyword is not implemented yet, (only units,) var parameters don’t work yet, and a handful of features aren’t implemented in the script executor.
Having said that, here’s a few cool features I’ve come up with:
- Class creation: Defining a new class inside the script code is not supported yet, but the basic framework is there, and script units implement new classes with their routines as methods, accessible to the script executor through the RTTI system. I’ll add class creation pretty soon.
- Automatic registration: Ever try to register a class with the script engine in PascalScript? It’s a painful process involving generating a registration unit that basically redeclares your entire class, and then has to be kept in sync or things break. (And if you get the dependency order wrong, it fails silently, leading to weird errors further down the line.) I figured that was way too complicated, so for RTTIScript, all you have to do is register a class reference, and it uses the RTTI system to figure out the internal members and dependencies for you.
- Execution environment: You’ll often have a bunch of little standalone routines and global variables that you want to import into a script to have available at all times, to provide an interface between the script and your program. So I introduced the concept of the “environment:” You create a class and register it with the compiler, and it treats all the class’s public methods and properties as globals for the script. (This also means that you can use property getters and setters to have the script’s interaction with its “global variables” invoke side effects.)
- Script saving: I know Eric Grange thinks that a fast compiler is good enough and a bytecode version of a script is not necessary, but I don’t agree. By his own tests, even a very fast script compiler can take 2 seconds to compile a 100,000 line script. I’ve actually got an example of one that big in a project that the author wants to convert over once the TURBU project is ready. Adding a two-second lag into the loading process and making the player wait while a level loads, which should feel instantaneous, is unacceptable. I don’t have script saving implemented yet, but it’s definitely on the to-do list.
Anyway, the alpha version is available for any
guinea pigs curious developers out there who’d like to take a look at it. It requires Delphi XE, it’s pretty fast, and when I get the rest of the features set up it’s going to be awesome! Feel free to check it out, and to submit a bug report if you find some errors. (Which I’m sure plenty of people will.)