Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


Which scripting language to use?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 ic0de   Members   -  Reputation: 894

Like
0Likes
Like

Posted 12 January 2013 - 10:06 PM

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?


Edited by ic0de, 12 January 2013 - 10:08 PM.

you know you program too much when you start ending sentences with semicolons;


Sponsor:

#2 Servant of the Lord   Crossbones+   -  Reputation: 20348

Like
2Likes
Like

Posted 12 January 2013 - 10:11 PM

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.


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#3 ic0de   Members   -  Reputation: 894

Like
0Likes
Like

Posted 12 January 2013 - 10:51 PM

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.


you know you program too much when you start ending sentences with semicolons;


#4 scarypajamas   Members   -  Reputation: 317

Like
1Likes
Like

Posted 12 January 2013 - 11:25 PM

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.



#5 Servant of the Lord   Crossbones+   -  Reputation: 20348

Like
1Likes
Like

Posted 12 January 2013 - 11:48 PM

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).


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#6 scarypajamas   Members   -  Reputation: 317

Like
1Likes
Like

Posted 13 January 2013 - 12:18 AM

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.


Edited by scarypajamas, 13 January 2013 - 12:19 AM.


#7 Servant of the Lord   Crossbones+   -  Reputation: 20348

Like
2Likes
Like

Posted 13 January 2013 - 12:24 AM

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.


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#8 scarypajamas   Members   -  Reputation: 317

Like
1Likes
Like

Posted 13 January 2013 - 12:36 AM

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.

 

Edited by scarypajamas, 13 January 2013 - 12:39 AM.


#9 Hodgman   Moderators   -  Reputation: 31084

Like
3Likes
Like

Posted 13 January 2013 - 12:59 AM

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>


Edited by Hodgman, 13 January 2013 - 01:02 AM.


#10 ic0de   Members   -  Reputation: 894

Like
0Likes
Like

Posted 13 January 2013 - 09:06 AM

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).


Edited by ic0de, 13 January 2013 - 07:01 PM.

you know you program too much when you start ending sentences with semicolons;


#11 SiCrane   Moderators   -  Reputation: 9628

Like
2Likes
Like

Posted 13 January 2013 - 10:04 AM

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.
One of the nice things about AngelScript is that wrapping isn't required for many of the platforms that AngelScript runs on. AngelScript will generate the assembly necessary to call a native C++ function without wrappers for an absurd number of platforms. Reading the AngelCode forum threads when Andreas is going through the process of adding native calling support for a new platform supplies much of my knowledge of differently normal C++ ABIs.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS