2010-01-29 22:51:51 -05:00
|
|
|
(function(){
|
2010-02-17 01:24:02 -05:00
|
|
|
var coffee, prompt, quit, readline;
|
2010-01-29 22:51:51 -05:00
|
|
|
// A CoffeeScript port/version of the Node.js REPL.
|
|
|
|
// Required modules.
|
2010-02-17 00:50:08 -05:00
|
|
|
coffee = require('coffee-script');
|
2010-01-29 22:51:51 -05:00
|
|
|
// Shortcut variables.
|
|
|
|
prompt = 'coffee> ';
|
|
|
|
quit = function quit() {
|
2010-02-17 01:24:02 -05:00
|
|
|
return process.exit(0);
|
2010-01-29 22:51:51 -05:00
|
|
|
};
|
|
|
|
// The main REPL function. Called everytime a line of code is entered.
|
|
|
|
// Attempt to evaluate the command. If there's an exception, print it.
|
2010-02-17 01:24:02 -05:00
|
|
|
readline = function readline(code) {
|
2010-02-17 23:51:43 -05:00
|
|
|
var val;
|
2010-01-29 22:51:51 -05:00
|
|
|
try {
|
2010-02-17 23:51:43 -05:00
|
|
|
val = eval(coffee.compile(code, {
|
2010-02-17 01:24:02 -05:00
|
|
|
no_wrap: true,
|
|
|
|
globals: true
|
2010-02-17 23:51:43 -05:00
|
|
|
}));
|
2010-01-29 22:51:51 -05:00
|
|
|
if (val !== undefined) {
|
|
|
|
p(val);
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
puts(err.stack || err.toString());
|
|
|
|
}
|
|
|
|
return print(prompt);
|
|
|
|
};
|
|
|
|
// Start up the REPL.
|
|
|
|
process.stdio.addListener('data', readline);
|
2010-02-13 10:27:18 -05:00
|
|
|
process.stdio.open();
|
2010-01-29 22:51:51 -05:00
|
|
|
print(prompt);
|
|
|
|
})();
|