Since we can run JavaScript using various interpreters, like V8 or Rhino, I thought there should be a way to run CoffeeScript code inside a terminal as well.
Technically, I can do that by using Node.js while running javascript, but I'm curious if there is a standalone interpreter specifically designed for CoffeeScript.
Since we can run JavaScript using various interpreters, like V8 or Rhino, I thought there should be a way to run CoffeeScript code inside a terminal as well.
Technically, I can do that by using Node.js while running javascript, but I'm curious if there is a standalone interpreter specifically designed for CoffeeScript.
Share Improve this question asked Nov 24, 2011 at 17:07 NoobDev4iPhoneNoobDev4iPhone 5,72910 gold badges35 silver badges33 bronze badges6 Answers
Reset to default 9What's wrong with simply installing and running the interpreter that comes with CoffeeScript itself?
Read the installation part of the guide here: http://jashkenas.github.com/coffee-script/#installation
And then use it like this:
Or am I missing some dimension of your question?
No. You can launch a coffeescript file with coffee filename
, but this will just compile the coffeescript file in-RAM and run it as javascript. Well, actually someone did write an interpreter for coffeescript, but that interpreter is written in javascript or coffeescript or so and therefore has to run inside of a JS engine, too. Also, it's slow as hell because it's an interpreter and not a JIT compiler.
As I said, just use the coffee
command.
There is, to my knowledge, only one CoffeeScript interpreter that does not compile it to JavaScript: Poetics.
It's written in pure Ruby and runs CoffeeScript code directly on the Rubinius VM. However, it hasn't been updated since May, and it's far from identical to the official CoffeeScript implementation.
If you don't want to run your script with the coffee
command, you can always add a hashbang to the top of the script:
#!/usr/local/bin/coffee
As long as the file is set to be executable (chmod +x foo.coffee
), now you can run it without specifying the coffee
command in your terminal:
$ ./foo.coffee
You can't use coffee
as a script interpreter directly, because it's already a script. But you can fix that by writing a simple C wrapper:
#include <unistd.h>
int main(int argc, char *argv[]) {
execvp("coffee", argv);
}
Compile that and put it in your PATH somewhere (I called it klatsh
) and then put #!/usr/bin/env klatsh
(or whatever you called it) at the top of your scripts, and you're good to go.
Yes, just use:
$ coffee test.coffee
Output from coffee!