Sign in to follow this  
sirSolarius

Confused about scripting

Recommended Posts

I want to put a scripting system into my next project, which is an engine for adventure games (like Grim Fandango). I want to allow scripts to access C++ functions in my engine and to add characters, set triggers, etc. using those files. I've looked through lua's website and it seems a bit ghetto, for the lack of a better word. It looks like it was created in the C style, and the tutorials have externs and stuff on them. I'm a bit confused all around, but if it works well and integrates into C++ code without a hitch, then I guess that's fine. Can anyone start to point me in the right direction? Everything is pretty confusing right now and things seem right, but they turn out to be tutorials for totally different things. Thanks a ton! [Edited by - sirSolarius on May 27, 2005 4:04:26 PM]

Share this post


Link to post
Share on other sites
Take a look at the Lua book: http://www.lua.org/pil/

Next, mess around with the Lua interpretor to get an idea of how the language is designed. After you get the hang of that, read the "C API" part in the Lua book and go through the examples. Once you get the hang of interfacing between Lua and C/C++, you start to understand what type of setup is appropriate for your game.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I've recently started using Mozilla's javascript engine, which I found fairly easy to integrate. See http://www.mozilla.org/js/spidermonkey/tutorial.html. There's a little more to it than shown there (namely how to convert the jsvals you get as arguments to C++ types like int, string etc and how to convert back to set a return value), but overall it's pretty straightforward and there seem to be no hidden catches.

Share this post


Link to post
Share on other sites
Ok, this looks to be exactly what I need, with only one caveat. You're right... converting stuff is a huge issue =)

If I have a function defined with an *rval pointer in there, and I want to return a boolean or a double or something, how do I do that? How can I take a c++ data type and convert it into a jsvalue? I only see the methods for jsvalue --> c++ type.

Edit: Ok, I see http://www.mozilla.org/js/spidermonkey/apidoc/gen/api-JS_NewDoubleValue.html for making a new double, but I can't find equivilent methods for integers and booleans...

Thanks again, this is really perfect!

[Edited by - sirSolarius on May 30, 2005 10:29:07 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Extrarius
For a scripting language that supposedly (I've heard but haven't looked into it myself) works well with C++, try python with boost::python.


I'm going to warn you that boost::python is not for the faint of heart. I'm using it in my engine at the moment (with pyste to generate the glue code), but it's a hassle to set it up and get it right. I used ages! Partly because the documentation needs a lot of improvement. Also, game engines tend to use certain design patterns which don't work well when using glue code between languages in that way. The singleton is a notable example.
However, like I said, boost::python is powerful and it works nicely once you've gotten it to work.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Depending on the complexity of the tasks that you ultimately hope to achieve by using a scripting language, you should also check out the various alternatives to lua, while lua itself is very neat and can be great for complex uses, it may be overkill for simple purposes.

For example, a friend of mine required a simple C based scripting language with low overhead, after checking out various interpreters he ultimately ended up using "Nasal", an open source language that's used by a number of smaller open source projects:

www.plausible.org/nasal

If Nasal doesn't fit your needs, I would recommend to go to freshmeat and check all scripting language projects over there:

http://freshmeat.net/browse/817/


good luck

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by _the_phantom_
For Lua and C++ intergration there is also Luabind.

Infact, there are plans in motion to bring Lua into Boost based on the same core as Boost::python.


Make sure to also look into "SWIG" in order to create bindings for arbitrary scripting languages.



Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
but overall it's pretty straightforward and there seem to be no hidden catches.


Yeah, I like Mozilla's SpiderMonkey - except I always fall foul of the garbage collector in it, even if I root things :/

Share this post


Link to post
Share on other sites
Quote:
Original post by sirSolarius
Edit: Ok, I see http://www.mozilla.org/js/spidermonkey/apidoc/gen/api-JS_NewDoubleValue.html for making a new double, but I can't find equivilent methods for integers and booleans...

Thanks again, this is really perfect!


jsval ival = INT_TO_JSVAL( 12345 );
jsval bval = BOOL_TO_JSVAL( true );

// etc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this