Scripting Alternative

Started by
13 comments, last by DrewGreen 18 years, 7 months ago
Is there anyone on this planet who has ever created their OWN scripting language? I've spent over six months now - off and on - creating a core library of functions I can reuse for practically any project. What I want to do now is add scripting compatibility. From what I've read in this forum, the main scripting languages - Python, Lua, Squirrel - all have their own problems and quirks. So I've decided it would be easiest - in terms of integration - to create my own interpreted "language" specific for my game "engine" (quotes because it's at a pretty early stage right now). I've already set up the basic structure of the language, and it looks like I could really develop this into something usable. What I want to know is, has anyone done anything like this before, or am I really, REALLY using the wrong approach here? If you have done something similar, do you have any advice? Thanks in advance.
-------------Some hate God for putting thorns on roses, others praise God for putting roses on thorns.
Advertisement
Lots of game engines have their own scripting languages and this is not new. Sometimes though its worth putting up with the quirks than writing your own. I've done both... probably won't do it again, but only because its not worth it to me.
I've tried both ways, creating my own language and integrating existing languages, and integration quirks aside, it's much easier to integrate an existing language. Pretty much because if a script screws up, you know it's either the script or your bindings to the scripting system. If you roll your own and a script screws up, it can be one of those or a bug in the scripting system too. And bugs in scripting languages are annoying to track down. (Is it a parsing bug? No? Is it a problem in virtual machine? Maybe it's a problem in the byte code generator?)
I think it's the wrong approach to write your own. You didn't mention Angelscript, which is "sponsored" more or less by gamedev.net. It has its own forum on gdnet.
1. Python: biggest, most powerful, most overhead and most difficult to integrate (and oldest, most mature).
2. Lua: well sorted out at version 5.x, relatively small, easy to integrate, more complicated when garbage collection and C++ class support is desired.
3. LuaPlus: garbage collection issues should be resolved via the built-in reference counting system, powerful but complicated template metaprogramming (porting issues). C/C++ class support reasonbly clean but not as good as Squirrel.
4. Squirrel: smallest and simplest, inspired by Python, &#106avascript, Lua, and is partially derived from Lua (table code). Does not have a large feature library as with Python and LuaPlus (if you write your own language, you'll have to write your own feature library). However, for game scripting with C/C++ and classes, it is comparatively trivial to integrate and use compared to the other languages in this list (see the sqplus example).

Lunatic Python allows Lua to be called from Python and vice versa. Some companies use both languages (for example, Python for tools/utilities, Lua for game scripting).

Also see Ruby, GameMonkey, Small, etc.

If you have the time/desire to create a custom scripting language, perhaps modify+improve one of the existing languages. Otherwise, you may end up spending most of your time working on the scripting language and not on your game.
I created my own scripting system once, but it started off as a simple list of commands, and only later did I add variables and the ability to pause and resume scripts, and later I will add some sort of array object and the ability to call one script from another... but I could have used a pre-made language for that.

I think making your own language is one of those things that requires a fair amount of skill and time to do properly. And often that skill and time can be more fruitfully applied elsewhere. Integrating Lua and other languages like it is usually very easy, and probably wouldn't take more than a week, in contrast to spending up to 6 months developing and integrating your own language. You have to decide if it is worth it.
Thanks for the input.

I guess maybe I didn't clarify the type of "language" I was creating. I'm not about to create a COMPILED language - nothing that complex. All I'm going after is an INTERPRETED language. I know it's a little slower, but since I'm parsing the entire script (or group of linked scripts) right at the beginning, the scripts should run pretty fast.

"I created my own scripting system once, but it started off as a simple list of commands, and only later did I add variables and the ability to pause and resume scripts, and later I will add some sort of array object and the ability to call one script from another... but I could have used a pre-made language for that."

Kylotan, that's pretty much exactly what I'm doing. The reason I'm hesitant about using a pre-made language like Python is that the "hooks" everyone keeps referring to - from what I know they basically translate the C/C++ code into the language I'm using. But that's going to cause problems, right? Unreliable conversions? Correct me if I'm wrong, but that could create a lot more hard-to-find bugs than writing my own language.
-------------Some hate God for putting thorns on roses, others praise God for putting roses on thorns.
Not really, at least with boost::python as long as you have RTTI enabled, there don't seem to be any problems with types getting mixed up when transfering data between Python and C++.
Quote:Original post by Lord Caius
Kylotan, that's pretty much exactly what I'm doing. The reason I'm hesitant about using a pre-made language like Python is that the "hooks" everyone keeps referring to - from what I know they basically translate the C/C++ code into the language I'm using. But that's going to cause problems, right? Unreliable conversions? Correct me if I'm wrong, but that could create a lot more hard-to-find bugs than writing my own language.


As SiCrane noted with boost::python, there will be no major issues with types as template-based methods will tend to show errors at compile time (as the template code is compiled into specialized instantiations). This will also be true for LuaPlus, Luabind, Squadd (for Squirrel), etc. If your are doing really basic scripting, it will be hard to beat Lua or Squirrel in terms of time and effort (relative to creating a custom solution). At which point you want more complicated features, they'll already be there if one of these existing languages is used. All of these languages are interpreted, and all are parsed and converted to (interpreted) byte code before execution (this is what occurs when you see "Compile" syntax in the API: not the same as a C/C++ compile to machine code bytes).

Perhaps try the sqplus example (minutes to download, compile, and test with MSVC7.1 (trace through with the debugger to see how it works)). Next try Vanilla Lua (examples from the etc directory, such as min.c and trace.c), then LuaPlus (trace through the tests/examples), then Python (I have not yet tested Python; perhaps a Python user can recommend a good starting example).

It's also relatively easy to integrate and test multiple languages at the same time, in the same program (I'm currently testing LuaPlus and Squirrel in my game app).
It's a useful thing to study. Language design and implentation is sort of the foundation of Computer science in some ways.

It depends on your game really and what you want to do.


"It's such a useful tool for living in the city!"

This topic is closed to new replies.

Advertisement