Advertisement

Which scripting language to use?

Started by January 13, 2013 04:06 AM
9 comments, last by SiCrane 11 years, 10 months ago

I've discovered that my game needs a scripting language. This scripting language will be used to automate game events and each script will be associated with a level. I'm specifically looking for a scripting language that:

1. Is fast to run and to write

2. Has a C/C++ like syntax

3. Is portable (doesn't depend on system specific stuff)

4. Is easy to integrate (I can call a C++ function from my main application in the script and I can easily share data)

I'm thinking about JavaScript because It's widely supported and I'm familiar with it from web development and it looks alot like C or C++.

Can anyone suggest a javascript api to use which runs on Win/Linux/Mac?

Does anyone have any alternative ideas on which scripting language to use or have any thoughts on using javascript to extend games?

AngelScript is fairly close to C++ syntax; I haven't yet used it, but I have it on my TODO to migrate to it within the next few weeks.

It also is extremely portable, and executes very fast. I'm not sure what you mean by 'fast to write'.

As far as I've found, zero scripting languages have #4. Every single one requires you to explicitly make a function or class visible to the scripting language in some way.

Advertisement
As far as I've found, zero scripting languages have #4. Every single one requires you to explicitly make a function or class visible to the scripting language in some way.

Yeah I don't really care that I have to explicitly make each function/class visible to my script just so long as I can easily access it afterwards. As for "fast to write" I mean that I can quickly write the script because the language for example includes alot of useful predefined functions that make coding easier or something like that.

A quick search on github revealed Killa. It appears to be a fork of Lua that was modified to use a Javascript style syntax. With this you could use the wealth of Lua embedding references for guidance. Also, being based on Lua, it's going to be meet all your requirements.

A quick search on github revealed Killa. It appears to be a fork of Lua that was modified to use a Javascript style syntax. With this you could use the wealth of Lua embedding references for guidance. Also, being based on Lua, it's going to be meet all your requirements.

Why modify Lua to use a Javascript-like syntax? Why not just use Javascript itself, with a C++ lib like Google's V8?

Also, Lua doesn't satisfy #4 either - you have to write a Lua wrapper function around each of your C++ functions that you want to use (though templates and macroes and pre-processing libraries can make it easier).

Why modify Lua to use a Javascript-like syntax? Why not just use Javascript itself, with a C++ lib like Google's V8?

You might choose Lua over V8 because its more lightweight and there's lots of information on it. I've also heard tell that V8 is a pain to embed, but I suppose experiences may very. If there exists a lightweight Javascript implementation or if you don't mind V8's heavier footprint, then by all means use it. I'd be interested in a lightweight JS implementation if you know of any.

Also, Lua doesn't satisfy #4 either - you have to write a Lua wrapper function around each of your C++ functions that you want to use (though templates and macroes and pre-processing libraries can make it easier).

Nobody mentioned anything about wrapping. #4 says it must be "easy to integrate" I didn't interpret that as meaning "no wrappers". Plus SWIG is available for wrapping, if you want it.

Advertisement

I guess I'm interpreting "I can call a C++ function from my main application in the script..." too stringently. mellow.png

If wrapping is permitted, then almost any scripting language fulfills that requirement. If wrapping isn't permitted, than almost none do.

AngelScript is fairly close to C++ syntax; I haven't yet used it, but I have it on my TODO to migrate to it within the next few weeks.

I'll second AngelScript. It's more C++ than Javascript, but hey, maybe it's acceptable anyway.

Also, a search on github brought up the following projects: flathead and ChaiScript. Their not as famous as V8, but they might be of interest. Wikipedia also has a list of JS engines.

You could also look at using Runtime Compiled C++, if all you want is C++-syntax that you can tweak at runtime wink.png

I guess I'm interpreting "I can call a C++ function from my main application in the script..." too stringently. mellow.png
If wrapping is permitted, then almost any scripting language fulfills that requirement. If wrapping isn't permitted, than almost none do.

Most scripting language I've used require ~1 line of C++ code to 'register' a C++ function with the scripting environment, and IMO this is to be expected.

I've also used languages that parse your C++ headers and automatically build their own bindings, but these generally put restrictions on the way you write your headers, and make me feel dirty with their fragility and over-reaching nature.


The main difference with Lua's method of binding to C++ compared to other scripting libraries, like AngelScript, is that Lua doesn't supply an advanced registration system out of the box -- instead they give you the tools to write your own registration system, so you can either spend half a dozen lines of C++ to register each function yourself manually, or you can use a 3rd party Lua-binding library to reduce this to 1-line.
This is getting off-topic, but the Bitsquid engine chose not to use one of these Lua-binding systems at all, and instead use the manual method of writing their Lua bindings (half a dozen lines per function). Their rationale is that if you're writing the bindings yourself, then you're aware of any inefficiencies or quirks at the language boundary and you'll produce a better, and more Lua-styled, Lua-side engine API as a result, which I found to be an interesting bit of food-for-thought.

Personally I'd recommend Lua, even though it fails requirement #2 (and possibly #4 depending on how you personally feel about the manual binding API, and/or how you feel about 3rd-party binding systems). It's easy to write, is extremely fast (especially if you use LuaJIT instead of standard Lua) and the Tilde debugger is pretty cool.

</offtopic>

I think I'm going to use AngelScript. I'm usually concerned about the documentation of projects like this but AngelScript seems to have pretty good docs. As a plus Amnesia uses it and their enigine seems to have a few similarities with mine (OpenGL/OpenAL/SDL).

This topic is closed to new replies.

Advertisement