Sign in to follow this  
marijnh

Scheme as an embedded scripting language

Recommended Posts

My current project is going to need a scripting language, I was thinking about using Python through boost::python, but recently I've fallen in love with Scheme. The problem is, though, that I can not find any scheme interpreters that are conveniently embeddable in C++. Most of them are written in C, and have quite clunky interfaces. On top of that many use setjmp/longjmp happily and that certainly will not cooperate nicely with C++ stack unwinding. Have any of you ever used scheme as an embedded language in a C++ program? If so, what interpreter did you use, and what was your experience...

Share this post


Link to post
Share on other sites
hello!
ive been tinkering some with using TinyScheme (heard it recomended on this forum a couple of times) for scripting and it has worked rather well. TinyScheme is in c but it was quite easy to make a simple hack for it to support methods on c++ objects. nothing too fancy but it works good for me.. there is a description in the hack.txt file contained in the TinyScheme download which describes how to add a new datatype and it can give you some hints what and where you have to change the source code..

http://tinyscheme.sourceforge.net/download.html

Share this post


Link to post
Share on other sites
Scratch the itch. Boost::Python is, as I understand it, a very simple wrapper on the standard Python objects. Shouldn't be too hard to wrap your favourite embedded C-based scheme interpreter in a nice layer of C++.

Still, I can't imagine using scheme for a game engine... I mean, do you want to actually have other developers use it? I've tried to get into Lisp, but I just can't read that stuff. Then again, my favourite game of the 90's was scripted with Lisp, so I should shut up. Abuse pwns.

Share this post


Link to post
Share on other sites
schlook:
I've been messing around with tinyscheme, it looks nice. The only gripe I had was that the documentation was even tinier than the program itself. I guess I'll just have to start digging through the headers to figure out what functions to call.

Pxtl:
I agree that lisp code *looks* awful, especially at first. But I've found that its consistency (no operator precedence, well, no operators at all actually, only a few special keywords) makes it very easy to learn. The complete specification of the Scheme language is only about 50 pages, most of which is easy to read for anyone with any programming experience. And you can do NEAT stuff with it - Python has already managed to imitiate quite a lot of it but in the end it feels quite bolted on, and Python lambda's are just a joke.

Share this post


Link to post
Share on other sites
Quote:
Original post by marijnh
The only gripe I had was that the documentation was even tinier than the program itself.


yes, i know what you mean.. :/

Quote:
Original post by marijnh
I guess I'll just have to start digging through the headers to figure out what functions to call.


this is how i did it: first i made a simple class with a pure virtual function taking a scheme state and a pointer with the args and returning a pointer. in other words it looks like a foregin function.. then i looked at the code and saw how the foregin function was implemnted and just added code to call the function on the class instead of through the function pointer.

ehh.. i dont know if that is much help to you but maybe a little hint anyways :)

i would tell you exactly what i changed if i knew it myself, but that would require some work since im not quite sure i documented all the changes i made.. it was late and i was just happy to get it working :) but if you need more help i probably could check over my code and maybe give a little more hints.. :)

Share this post


Link to post
Share on other sites
For some crazy I reason I have now decided to try and implement a complete scheme interpreter myself. It should be an interesting learning experience - but it'll take weeks. I always get sidetracked like this, and never finish anything!

Share this post


Link to post
Share on other sites
It is kind of hard to get good performance in a scheme-based-scheme-interpreter, and it is just too tempting to just use the underlying scheme features to do all the hard stuff for you. The scheme48 people did do this though - they used pre-scheme, a subset of scheme that is quite close to C, to build the virtual machine and the memory manager, and built the rest of the system in normal scheme.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this