Jump to content
  • Advertisement
Sign in to follow this  
Radan

Multiple scripting languages in a game?

This topic is 2975 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Have any of you tried embedding more than one scripting language into the game to use them simultaneously?

The benefit would be that for each script used you could select the appropriate language to write it in (always have the right tool for the job). Could be beneficial to productivity even though you'd introduce runtime overhead with more than one script interpreter running at the same time.

Obviously it would be pretty difficult to come up with an elegant architecture to support it. Most libraries for binding C++ functions to script make heavy use of templates so you couldn't use polymorphism to make the use of multiple scripting languages transparent to the rest of the code. By that I mean you could not add another scripting language without modifying the code where the function is being exposed.

An alternative is to use SWIG and just regenerate binding code for each new language. Any experience with that?


P.S. Yes, this is just me thinking out loud hoping someone will contribute to it. :)

Share this post


Link to post
Share on other sites
Advertisement
I have templates/macros that allow reflection/marshaling (see visitor pattern) of the functions inside a class, and use this to generate the script-bindings. This does allow a class to be bound to many languages without editing it ;)

To allow different languages to operate on the same objects (or the same language running on different VMs - e.g. two instances of Lua on two different threads), I provide an API for the scripts to add variables to objects (instead of using variables native to the language).
Something like:
object.add("integer", "foo")
object.set("foo", 42)
var fourtyTwo = object.get("foo")

Share this post


Link to post
Share on other sites
Quote:
Original post by Hodgman
I have templates/macros that allow reflection/marshaling (see visitor pattern) of the functions inside a class, and use this to generate the script-bindings. This does allow a class to be bound to many languages without editing it ;)


Interesting. Do you mind me asking how intrusive is your solution? What I mean by that is how many more declarations have to be added to the class for it receive reflection/marshalling?

Could you provide and example of a simple class declared with your templates/macros?

Share this post


Link to post
Share on other sites
In theory that is what Parrot does ..

http://parrot.org/

It allows the user to write in their favorite dynamic language and then runs all of them on a common VM. Perhaps it can auto-create bindings from C++ to all the target languages as well so you don't have to mess around with 20 different binding solutions for each language.

-ddn

Share this post


Link to post
Share on other sites
Quote:
Original post by Radan
Interesting. Do you mind me asking how intrusive is your solution? What I mean by that is how many more declarations have to be added to the class for it receive reflection/marshalling?

Could you provide and example of a simple class declared with your templates/macros?
It's pretty intrusive, but consistently so ;)
The member functions all have to be declared with the Message# macro (where # is the number of arguments).
class CGridCell : public CComponent
{
public:
seComponent( CGridCell, CComponent, CSandSystem )

seConstructors
seConstructor1( CGrid&, grid )
seEndConstructors

seNoInterfaces

seMessages
seMessage1( void, AddSand, uint, amt )
seMessage1( void, RemoveSand, uint, amt )
seMessage2( void, Erode, int, self_x, int, self_y )
seMessagesEnd

seProperties
seProperty( m_height, "height", Shared, None, None );
sePropertiesEnd
protected:
CGridCell(CSandSystem&, CEntity&, CGrid&);
private:
CGrid& m_Grid;
uint m_height;
};

Share this post


Link to post
Share on other sites
Just for the record the unreal engine uses both unreal script (a text scripting language) as well as kismet (a graphical node scripting language).

So yeah, there is precedence for it (:

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!