Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ embedded scripting language for game development - can't find anything I like [closed]

I'm desperately looking for a fast, C-like syntax, easy to embed, easy to wrap scripting language to embed in my C++ games.

So far I've tried:

  • Lua: it works, but wrapping global C++ functions around it is painful, and wrapping objects is even more difficult. Also, I really dislike Lua's syntax.
  • AngelScript: couldn't get it to work. Beginner documentation is absymal, as the first examples do not compile, and you have to build a lot of add-ons first. Wrapping C++ objects and functions looks easier than Lua but it still could be cleaner. Syntax looks fine.
  • ChaiScript: couldn't get it to work. I got a lot of errors both with the non-git and git C++11 versions. I don't want to use the boost version, as I don't want to introduce boost as a dependency in my project. Wrapping looks easy, and syntax is ok.

I've also investigated:

  • Pike: syntax looks good, but I found no documentation about embedding.
  • Squirrel: I don't like the syntax, and embedding/wrapping is as annoying as Lua, having to deal with the stack.

So:

  • Is there a good fast, C-like syntax, easy to embed, easy to wrap alternative?
  • If there isn't - what are the best learning resources on the creation of a scripting language? I like reinventing the wheel, and this could be an interesting learning experience.
like image 663
Vittorio Romeo Avatar asked Jul 16 '13 08:07

Vittorio Romeo


6 Answers

For C-like syntax, checkout

  • Ch a commercial, embeddable C interpreter
  • CINT an open source C/C++ interpreter
  • Pawn - a "simple, typeless, 32-bit extension language with a C-like syntax"

Probably not for you, but as this question might turn up a list of alternatives others would find interesting, I offer you QtScript which gives you a Javascript-like syntax. Wrapping can be straightforward, but you need to adopt the Qt framework to do it, particularly concept of signals and slots.

There's also SpiderMonkey, the JS engine from Firefox.

like image 88
Paul Dixon Avatar answered Sep 29 '22 02:09

Paul Dixon


You might look at using JavaScript. The V8 scripting engine can be embedded in your program and there is documentation on how to expose your types.

like image 45
Graznarak Avatar answered Sep 29 '22 02:09

Graznarak


You might be interested in Dao (http://daoscript.org/, https://github.com/daokoder/dao).

Dao is implemented in standard C with minimum dependency (if you exclude the optional modules and tools). It is lightweight and efficient with good support for embedding and extending. Its interface for calling C functions is not based on stack. Here is a simple example:

#include "stdio.h"
#include "daoValue.h"
static void Square( DaoProcess *proc, DaoValue *param[], int nparam )
{
    daoint num = param[0]->xInteger.value;
    DaoProcess_PutInteger( proc, num*num );
}
int DaoOnLoad( DaoVmSpace *vmspace, DaoNamespace *nspace )
{
    DaoNamespace_WrapFunction( nspace, Square, "Square( num : int ) => int" );
    return 0;
}

You may noticed that there is NO boilerplate code for checking the parameter types in the wrapped function. This is because this function is registered as Square(num:int)=>int, which means this function can only accept an integer as parameter, and is guaranteed by the Dao runtime.

You may also be interested to know that it also has a tool based on Clang for automatic/semiautomatic generation of C/C++ bindings.

Disclaimer: I am the author of this language.

like image 42
user2593309 Avatar answered Sep 29 '22 04:09

user2593309


You could just use C++, via something like Cling.

You get familiar syntax and easy integration with your static C++ program.

Qt + Cling, the LLVM based C++ interpreter (2:05)

like image 33
bames53 Avatar answered Sep 29 '22 03:09

bames53


I seconded using python as scripting language, I used boost python before in my program (not a game) and quite satisfied with it. If you want to try creating you own script, you may want to try boost spirit

like image 35
Kamil Zubair Avatar answered Sep 29 '22 03:09

Kamil Zubair


Aside from what others have suggested, there's also Cling which is deemed experimental. Writing a scripting language is not easy, but nowadays you can resort to LLVM, at least for the back-end. Programming language design is discussed briefly in the old "Algorithms+Data Structure=Programs" by N. Wirth (but do check the content topic, in the latest edition that chapter was removed) and if you search for the author on Google, you'll end up surely with some other publication about the topic.

like image 35
Fulvio Esposito Avatar answered Sep 29 '22 02:09

Fulvio Esposito