Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding a Programming Language Into a Program [closed]

Tags:

c

I'd like to add some degree of "scriptability" to a application I'm writing. Roughly speaking, I'd like a way to embed a programming language API into my program. I've looked at TinyPy, but I'm worried that - given it's small size - it might be deceptively limiting (i.e. it looks and feels like Python, but is lacking many of the features of full-fledged Python).

I'm not looking to write my own programming language; I'd like to simply take a relatively well-known language that users can write functions in, and then be able to call those functions/pass those functions parameters from my application, which will be written in C.

I'd also like to be access any data types those functions return back to me, also from within C.

Does anyone have any suggestions as to an API/Library to use, which would be both lightweight, relatively full-featured, and with a relatively easy to use or easy to understand C library?

Thanks!

like image 219
FreeMemory Avatar asked Aug 18 '10 14:08

FreeMemory


4 Answers

Lua is a popular choice.

like image 179
Ignacio Vazquez-Abrams Avatar answered Oct 09 '22 20:10

Ignacio Vazquez-Abrams


You might want to look at SpiderMonkey, which will allow you to embed a Javascript engine in your C program.

like image 45
Jacob Mattison Avatar answered Oct 09 '22 19:10

Jacob Mattison


Most scripting languages have good interfaces with C. The ones I've actually glanced at are Perl, Python, and Lua. If your users aren't serious programmers, I'd advise giving Perl a miss. If they're serious World of Warcraft players, they might already be familiar with Lua, and writing Lua code to interface with a compiled program, so that may be a good choice.

like image 27
David Thornley Avatar answered Oct 09 '22 19:10

David Thornley


YOu can always use 'c' with the ch toolkit.
As you said python is good especially if you can use the boost::python wrapper.
Another popular choice is Javascript, it's used by Qt's scripting system

like image 32
Martin Beckett Avatar answered Oct 09 '22 20:10

Martin Beckett