I'm writing a small, simple tile based RPG using C++ to hopefully expand my knowledge, and I'd like to know how I can use Common Lisp as a scripting language from within the C++ engine. Yes, I know it would be much slower than scheme, guile, or TCL, but I want to do it anyway just for the experience and the fun of it. I'm on a Unix machine (FreeBSD 4.3 to be exact) and i use the CMU Common lisp compiler. If it's possisble to use it as a scripting language, could I have a few links to show how I would go about doing this, as i have no idea where to even start. Thanks!
dan_...@Hotmail.com (dan b) writes: > I'm writing a small, simple tile based RPG using C++ to hopefully > expand my knowledge, and I'd like to know how I can use Common Lisp as > a scripting language from within the C++ engine. Yes, I know it would > be much slower than scheme, guile, or TCL,
Since when a language for which native compilers exist, is slower than "scheme, guile, or TCL,"? (And you forgot the innominable one).
Are you trolling?
Cheers
-- Marco Antoniotti ======================================================== NYU Courant Bioinformatics Group tel. +1 - 212 - 998 3488 719 Broadway 12th Floor fax +1 - 212 - 995 4122 New York, NY 10003, USA http://bioinformatics.cat.nyu.edu "Hello New York! We'll do what we can!" Bill Murray in `Ghostbusters'.
> > I'm writing a small, simple tile based RPG using C++ to hopefully > > expand my knowledge, and I'd like to know how I can use Common Lisp as > > a scripting language from within the C++ engine. Yes, I know it would > > be much slower than scheme, guile, or TCL,
> Since when a language for which native compilers exist, is slower than > "scheme, guile, or TCL,"? (And you forgot the innominable one).
> Are you trolling?
> Cheers
Woah, chill out, i didn't mean to offend you. I meant as a SCRIPTING LANGUAGE, i've HEARD, scheme, guile, and TCL are better suited. Back to my original question, do you know how I could use Common Lisp for that purpose?
> I'm writing a small, simple tile based RPG using C++ to hopefully > expand my knowledge, and I'd like to know how I can use Common Lisp as > a scripting language from within the C++ engine. Yes, I know it would > be much slower than scheme, guile, or TCL, but I want to do it anyway > just for the experience and the fun of it. I'm on a Unix machine > (FreeBSD 4.3 to be exact) and i use the CMU Common lisp compiler. If > it's possisble to use it as a scripting language, could I have a few > links to show how I would go about doing this, as i have no idea where > to even start. Thanks!
Search for "Abuse" by crack-dot-com. 2D side scrolling shooter. They posted the complete code for the game when they went out of business. The main graphic engine is in C++ with a mini-lisp interpreter, possibly compiler, built into it. The entire game logic is written in Lisp. It's also annoyingly fast. Their web page was still up a year ago, it seems to have finally disappeared. There were numerous ports to Linux around the web at one time, check some ftp sites, it's probably still around.
dan_...@Hotmail.com (dan b) writes: > I'm writing a small, simple tile based RPG using C++ to hopefully > expand my knowledge, and I'd like to know how I can use Common Lisp as > a scripting language from within the C++ engine. Yes, I know it would > be much slower than scheme, guile, or TCL, but I want to do it anyway > just for the experience and the fun of it. I'm on a Unix machine > (FreeBSD 4.3 to be exact) and i use the CMU Common lisp compiler. If > it's possisble to use it as a scripting language, could I have a few > links to show how I would go about doing this, as i have no idea where > to even start. Thanks!
Actually, it's almost certain to be much faster than Guile Scheme or TCL. CMUCL makes it very easy for the Lisp program to call out to C, but it's not so easy for C to call into Lisp. It's possible, but I would not recommend it as a way of adding scripting to your program. Think about it and see if you can come up with a way for it to make sense for the Lisp to call up into C, and if you can, use CMUCL.
If you can't, try ECLS <http://ecls.sourceforge.net/>, which is designed to be embedded in C apps. It's not ANSI compliant, but it's moving in that direction. And the limbo between CLtL1 and ANSI CL is a much nicer place to be than Scheme or, god forbid, TCL.
> I meant as a SCRIPTING LANGUAGE, i've HEARD, scheme, guile, and TCL > are better suited.
Even if they are, Common Lisp in general is *not* slower than Scheme, and CMU CL is defenitely faster than Guile (a particular Scheme dialect) and TCL.
> Back to my original question, do you know how I could use Common Lisp > for that purpose?
Take a look at http://langband.sf.net - a rougelike RPG using Common Lisp both as a scripting and the main implementation language. It's author usually can be found on IRC channel #lisp at irc.openprojects.net. -- Eugene.
> I'm writing a small, simple tile based RPG using C++ to hopefully > expand my knowledge, and I'd like to know how I can use Common Lisp as > a scripting language from within the C++ engine. Yes, I know it would > be much slower than scheme, guile, or TCL, but I want to do it anyway > just for the experience and the fun of it.
Are you referring to the startup time of the interpreter, or to the execution time of the code once the interpreter is executing? Do you expect to be able to pre-compile most of the code that will be run, or do you intend to ship tons of source code into your system?
So it's hard for C to call lisp eh? Hmmm... I was worried about that. I'm not good enough at lisp to write it in lisp, plus it's graphical and thats even more advanced if i was to write it in lisp. Well i'll check out the links you guys gave me. Thanks for answering my questions.
dan_...@hotmail.com (dan b) writes: > So it's hard for C to call lisp eh? Hmmm... I was worried about that. > I'm not good enough at lisp to write it in lisp, plus it's graphical > and thats even more advanced if i was to write it in lisp. Well i'll > check out the links you guys gave me. Thanks for answering my > questions.
Calling between Lisp and other languages is outside of the scope of the spec, so statements like "it's hard for C to call Lisp" aren't very useful. It is hard for C to call CMUCL. It's not so hard for C to call into ECLS. Try to remember that CL isn't a one-implementation language, unlike most things people try to use for scripting.
> Are you referring to the startup time of the interpreter, or to the > execution time of the code once the interpreter is executing? Do you > expect to be able to pre-compile most of the code that will be run, or do > you intend to ship tons of source code into your system?
Again-- I am just a newbie, and i'm not sure what the best way to do it would be, so I'm not sure myself. I was just wondering if it's even possible-- if so i was looking for links to show how it could be done, if anyone has more...
dan b wrote: > > Are you referring to the startup time of the interpreter, or to the > > execution time of the code once the interpreter is executing? Do you > > expect to be able to pre-compile most of the code that will be run, or do > > you intend to ship tons of source code into your system?
> Again-- I am just a newbie, and i'm not sure what the best way to do > it would be, so I'm not sure myself. I was just wondering if it's even > possible-- if so i was looking for links to show how it could be done, > if anyone has more...
I've called Lisp from C using the following techniques:
The server: * create a socket server which forks off the following process for each client trying to connect - * create a pseudoterminal (see W.Richard Stevens, Advanced Unix Programming) * start up CMUCL Lisp in the pseudo terminal * I have created C functions callable from Lisp which enable it to transmit lisp data or code back to the client over a socket in a self-describing XDR format
The client: * A GUI GTK program connects to the lisp server. * The GUI program executes commands on the lisp server, as if it were on the same machine or in the same process space * If a result is desired, the server is instructed to relay data or code in an XDR format back to the client.
Using these techniques, I have been able to send code to a lisp server, which then returns code ..which can in turn be resent back to the server (etc etc) until finally data is sent back to the C program. Thread(s) are spawned in the client which receives the data, decodes it, and processes it.
(I actually embed a terminal (gnome ZVT_TERM widget) in my client, and I even employ readline, to make CMUCL code entry easier if I desire to hand to hand enter it instead of having widget clicks generate it). Also, my C program uses the lispreader library (www.complang.tuwien.ac.at/~schani/lispreader/), and all data returned from CMUCL, gets decoded in C into a lisp_object_t* object, so I can car , cdr and cons (manipulate) it in C in a lispy way.
There is heavy use of threading, forking, as well as placing graphics events into the gtk event stack. The code is currently proprietary, but this should give you a start.
I'm not sure this is the *best* way of doing it, but it works, and it is **very** fast.
Interesting. It's a shame they don't have to much there at the moment although it looks like they've put the entire original source in the CVS tree. I was thinking about tackling a rewrite of the code myself and making it Win32-DX friendly. Since they are aiming for a Win-Linux mix I hope they dump the assembly code and rely on the compilers instead of consigning it to x86 machines.
> I've called Lisp from C using the following techniques:
> The server: > * create a socket server which forks off the following process for each client > trying to connect - > * create a pseudoterminal (see W.Richard Stevens, Advanced Unix Programming) > * start up CMUCL Lisp in the pseudo terminal > * I have created C functions callable from Lisp which enable it to transmit lisp > data or code back to the client over a socket in a self-describing XDR format
> The client: > * A GUI GTK program connects to the lisp server. > * The GUI program executes commands on the lisp server, as if it were on the > same machine or in > the same process space > * If a result is desired, the server is instructed to relay data or code in an > XDR format back to the client.
> Using these techniques, I have been able to send code to a lisp server, which > then returns code ..which can > in turn be resent back to the server (etc etc) until finally data is sent back > to the C program. Thread(s) are spawned in the client which receives the data, > decodes it, and processes it.
> (I actually embed a terminal (gnome ZVT_TERM widget) in my client, and I even > employ readline, to make CMUCL code entry easier if I desire to hand to hand > enter it instead of having widget clicks generate it). Also, my C program uses > the lispreader library (www.complang.tuwien.ac.at/~schani/lispreader/), and all > data returned from CMUCL, gets decoded in C into a lisp_object_t* object, so I > can car , cdr and cons (manipulate) it in C in a lispy way.
> There is heavy use of threading, forking, as well as placing graphics events > into the gtk event stack. The code is currently proprietary, but this should > give you a start.
> I'm not sure this is the *best* way of doing it, but it works, and it is > **very** fast.
> Dave Linenberg
Wow! That's a little advanced for me but it might be doable, i've done linux sockets a little. Thanks alot for that!
You might want to take a look at "librep." It lives on Sourceforge http://librep.sourceforge.net/ and seems like it might be what you need. It is a Lisp system that is meant to be embedded into an application to provide scripting functionality in that app.
"Dennis Dunn" <ansof...@bellsouth.net> writes: > Hey Dan,
> You might want to take a look at "librep." It lives on Sourceforge
Anyone care to characterise where librep lives in the family-trees of Lisp and Scheme dialects? I seem to remember reading that it started out as a clone of emacs lisp, and then drifted towards standard lisp. (Which standard lisp might that be, i.e. when did this drift happen).
Somewhere else I encountered some talk about Scheme in librep. I believe it encapsulates some kind of embedded Scheme dialect, but how this works is kind of hazy to me.
The reason I'm asking is because most of sawfish ( default WM for GNOME) is written in this lispish language. Much of that in a seemingly Scheemish subset of that lispish language. This language makes me a bit --- unnhh --- uncomfortable, and as a newbie I need some guru to tell me exactly why. The more details the better. A good place to start would be talking about how SETF does not work in librep.
> > You might want to take a look at "librep." It lives on Sourceforge
> Anyone care to characterise where librep lives in the family-trees of > Lisp and Scheme dialects? I seem to remember reading that it started > out as a clone of emacs lisp, and then drifted towards standard lisp. > (Which standard lisp might that be, i.e. when did this drift happen).
librep is a dialect of Lisp, designed to be used both as an extension language for applications, and for use as a general programming language. It was originally written to be mostly-compatible with Emacs Lisp, but has subsequently diverged markedly. Its aim is to combine the best features of Scheme and Common Lisp and provide an environment that is comfortable for implementing both small and large scale systems. It tries to be a "pragmatic" programming language.
> A good place to start would be talking about how SETF does not work in > librep.
If librep is emacs-like, perhaps one could lift all the setf macros out of Dave Gillespie's emacs 'cl package (or better, integrate it with the librep distro)?
Philip -- Real programs don't eat cache (Malay) --------------------------------------------------------------------------- -- Philip Lijnzaad, lijnz...@ebi.ac.uk \ European Bioinformatics Institute,rm A2-08 +44 (0)1223 49 4639 / Wellcome Trust Genome Campus, Hinxton +44 (0)1223 49 4468 (fax) \ Cambridgeshire CB10 1SD, GREAT BRITAIN