Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a C++ app scriptable

I have several functions in my program that look like this:

void foo(int x, int y)

Now I want my program to take a string that looks like:

foo(3, 5)

And execute the corresponding function. What's the most straightforward way to implement this?

When I say straightforward, I mean reasonably extensible and elegant, but it shouldn't take too long to code up.

Edit:

While using a real scripting language would of course solve my problem, I'd still like to know if there is a quick way to implement this in pure C++.

like image 613
drby Avatar asked Jan 28 '09 12:01

drby


People also ask

What is scriptable app?

Scriptable is an automation app that allows you to write short programs (also known as scripts) so your iPhone or iPad can perform almost any task you might imagine—from emailing all meeting attendees to checking the current pollen count with a single command.

Where can I write Applescript?

You can find it in the Utilities folder inside the Applications folder. You can also use Spotlight to search for “Script Editor” and open it that way. You can learn more about using the Script Editor here.


1 Answers

You can embed Python fairly simply, and that would give you a really powerful, extensible way to script your program. You can use the following to easily (more or less) expose your C++ code to Python:

  • Boost Python
  • SWIG

I personally use Boost Python and I'm happy with it, but it is slow to compile and can be difficult to debug.

like image 88
Simon Steele Avatar answered Oct 11 '22 23:10

Simon Steele