<p>I'm looking at adding scripting functionality to an existing codebase and am weighing up the pros/cons of various packages. Lua is probably the most obvious choice, but I was wondering if people have any other suggestions based on their experience.</p>

<p>Scripts will be triggered upon certain events and may stay resident for a period of time. For example upon startup a script may define several options which the program presents to the user as a number of buttons. Upon selecting one of these buttons the program will notify the script where further events may occur.</p>

<p>These are the only real requirements;</p>

<ol>
<li>Must be a cross-platform library that is compilable from source</li>
<li>Scripts must be able to call registered code-side functions</li>
<li>Code must be able to call script-side functions</li>
<li>Be used within a C/C++ codebase.</li>
</ol>

[{'answer_id': 15358, 'author': 'mk.', 'author_id': 1797, 'author_profile': 'https://Stackoverflow.com/users/1797', 'pm_score': 1, 'selected': False, 'text': '<p>I have played around a little bit with <a href="http://www.mozilla.org/js/spidermonkey/" rel="nofollow noreferrer">Spidermonkey</a>. It seems like it would at least be worth a look at in your situation. I have heard good things about Lua as well. The big argument for using a javascript scripting language is that a lot of developers know it already and would probably be more comfortable from the get go, whereas Lua most likely would have a bit of a learning curve. </p>\n\n<p>I\'m not completely positive but I think that spidermonkey your 4 requirements. </p>\n'}, {'answer_id': 15364, 'author': 'Curt Hagenlocher', 'author_id': 533, 'author_profile': 'https://Stackoverflow.com/users/533', 'pm_score': 1, 'selected': False, 'text': "<p>I've used Python extensively for this purpose and have never regretted it.</p>\n"}, {'answer_id': 15450, 'author': 'Mark Harrison', 'author_id': 116, 'author_profile': 'https://Stackoverflow.com/users/116', 'pm_score': 3, 'selected': True, 'text': "<p>Based on my own experience:</p>\n\n<ul>\n<li>Python.  IMHO this is a good choice.  We have a pretty big code base with a lot of users and they like it a lot.</li>\n<li>Ruby.  There are some really nice apps such as Google Sketchup that use this.  I wrote a Sketchup plugin and thought it was pretty nice.</li>\n<li>Tcl.  This is the old-school embeddable scripting language of choice, but it doesn't have a lot of momentum these days.  It's high quality though, they use it on the Hubble Space Telescope!</li>\n<li>Lua. I've only done baby stuff with it but IIRC it only has a floating point numeric type, so make sure that's not a problem for the data you will be working with.</li>\n</ul>\n\n<p>We're lucky to be living in the golden age of scripting, so it's hard to make a bad choice if you choose from any of the popular ones.</p>\n"}, {'answer_id': 15455, 'author': 'Judge Maygarden', 'author_id': 1491, 'author_profile': 'https://Stackoverflow.com/users/1491', 'pm_score': 1, 'selected': False, 'text': '<p>Lua is has the most straight-forward C API for binding into a code base that I\'ve ever used. In fact, I usually quickly roll bindings for it by hand. Whereas, you often wouldn\'t consider doing so without a generator like <a href="http://www.swig.org/" rel="nofollow noreferrer">swig</a> for others. Also, it\'s typically faster and more light weight than the alternatives, and <a href="http://lua-users.org/wiki/CoroutinesTutorial" rel="nofollow noreferrer">coroutines</a> are a very useful feature that few other languages provide.</p>\n'}, {'answer_id': 15703, 'author': 'grom', 'author_id': 486, 'author_profile': 'https://Stackoverflow.com/users/486', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://www.angelcode.com/angelscript/" rel="nofollow noreferrer">AngelScript</a></p>\n<blockquote>\n<p>lets you call standard C functions and C++ methods with no need for proxy functions. The application simply registers the functions, objects, and methods that the scripts should be able to work with and nothing more has to be done with your code. The same functions used by the application internally can also be used by the scripting engine, which eliminates the need to duplicate functionality.</p>\n<p>For the script writer the scripting language follows the widely known syntax of C/C++ (with minor changes), but without the need to worry about pointers and memory leaks.</p>\n</blockquote>\n'}, {'answer_id': 15712, 'author': 'Grey Panther', 'author_id': 1265, 'author_profile': 'https://Stackoverflow.com/users/1265', 'pm_score': 0, 'selected': False, 'text': '<p>There were some excellent suggestions already, but I just wanted to mention that Perl can also be called / can call to C/C++.</p>\n'}, {'answer_id': 21375, 'author': 'Brad Gilbert', 'author_id': 1337, 'author_profile': 'https://Stackoverflow.com/users/1337', 'pm_score': 0, 'selected': False, 'text': '<p>You probably could use any modern scripting / bytecode language.</p>\n\n<p>If you\'re willing to put up with the growing pains of a new product, you could use the <a href="http://www.parrotcode.org" rel="nofollow noreferrer">Parrot</a> VM. Which has support for many, if not all of the languages listed on this page. Unfortunately it\'s not done yet, but that hasn\'t stopped some people from using it in a production environment.</p>\n'}, {'answer_id': 92929, 'author': 'Bryan Oakley', 'author_id': 7432, 'author_profile': 'https://Stackoverflow.com/users/7432', 'pm_score': 1, 'selected': False, 'text': '<p>The original question described Tcl to a "T". </p>\n\n<p>Tcl was designed from the beginning  to be an embedded scripting language. It has evolved to be a first class dynamic language in its own right but still is used all over the world as an embeded language. It is available under the BSD license so it is just about as free as it gets. It also compiles on pretty much any moden platform, and many not-so-modern. And not only does it work on desktop systems, there are variations available for mobile platforms. </p>\n\n<p>Tcl excels as a "glue" language, where you can write performance-intensive functions in C while still benefiting from the advantages of a scripting language for less performance critical parts of the application.</p>\n\n<p>Tcl also comes with a first class GUI toolkit (Tk) that is arguably one of the easiest cross platform GUI toolkits available. It also interfaces very nicely with SQLite and other databases, and has had built-in support for unicode for quite some time.</p>\n\n<p>If the scripting interface will be made available to your customers (as opposed to simply enabling your own engineers to work at the scripting level), Tcl is extremely easy to learn as there are a total of only 12 rules that govern the entire language (as of tcl 8.6). In fact, Tcl shines as a  way to invent domain specific languages which is often how it is used as an end-user scripting solution.</p>\n'}, {'answer_id': 129353, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>I think most people are probably mentioning the scripting language that they are most familiar with.  From my perspective, Tcl was designed specifically to interface with C, so your problem domain is tailor-made for the language.  However, I'm sure Python, Perl, or Lua would be fine.  You should probably choose the language that is most familiar to your current team, since that will reduce the learning time.</p>\n"}]
['https://Stackoverflow.com/questions/15349', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1043/']