Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scripting language for C++ [closed]

I'm getting a little rusty in scripting languages, provided they're popping like mushrooms lately :)

Today I thought that it would be nice to have a scripting language that talks seamlessly to C++, that is, could use C++ classes, and, the most important for me, could be compiled into C++ or some DLL/.SO (plus its .h) so that I could link it into my C++ program and make use of the classes the script defines or implements.

I know I could embed any popular scripting language such as lua, ruby, python... but the interface usually includes some kind of "eval" function that evaluates the provided scripting code. Depending on the tool used to couple C++ and the scripting language, the integration for callbacks of the script into C++ could be more or less easy to write, but I haven't seen any scripting language that actually allows me to write independent modules that are exposed as a .h and .so/dll to my program (maybe along the lines of a scripting language that generates C++ code).

Do you know any such tool/scripting language?

Thanks in advance.

PD. I've been thinking along the lines of Vala or Haskell's GHC. They generate C, but not C++...

like image 603
Diego Sevilla Avatar asked Jun 30 '10 14:06

Diego Sevilla


People also ask

What language is close to C?

These languages are C++ (also known as C with classes), C#, Python, Java, JavaScript, Perl, PHP, Verilog, D, Limbo and C shell of Unix etc. Every language uses C language in variable capacity.

Is there closure in C?

Although C was created two decades after Lisp, it nonetheless lacks support for closures.

Is C close to Java?

C is a middle-level language as it binds the bridges between machine-level and high-level languages. Java is a high-level language as the translation of Java code takes place into machine language, using a compiler or interpreter. C is only compiled and not interpreted. Java is both compiled and interpreted.

Can you use C for scripting?

C/C++ can be used for maximal performance and complicated systems programming tasks. Scripting languages can be used for rapid prototyping, interactive debugging, scripting, and access to high-level data structures such associative arrays.


1 Answers

UPDATE 2020: Today I would probably go with Lua + Sol2/3 except if I really want to avoid Lua as a language. Chaiscript becomes a good candidate in this case though it is not optimal performance-wise compared to Lua+Sol2/3 (though it was greatly improved through years so it is still good enough in many cases). Falcon have been dead for some years, RIP.


The following ones are more C++ integration oriented than language bindings :

  • ChaiScript - trying at the moment in a little project, interesting, this one is MADE with C++ in mind and works by just including a header! Not sure if it's good for a big project yet but will see, try it to have some taste!
  • (not maintained anymore) Falcon - trying on a big project, excellent; it's not a "one include embed" as ChaiScript but it's because it's really flexible, and totally thought to be used in C++ (only C++ code in libs) - I've decided to stick with it for my biggest project that require a lot of scripting flexibility (comparable to ruby/python )
  • AngelScript - didn't try yet
  • GameMonkey - didn't try yet
  • Io - didn't try yet

For you, if you really want to write your scripting module in C++ and easily expose it to the scripting language, I would recommand going with Falcon. It's totally MADE in C++, all the modules/libraries are written that way.

like image 80
Klaim Avatar answered Sep 20 '22 14:09

Klaim