1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/lib/repl.js

32 lines
847 B
JavaScript
Raw Normal View History

2010-01-29 22:51:51 -05:00
(function(){
var coffee, prompt, quit, readline;
2010-01-29 22:51:51 -05:00
// A CoffeeScript port/version of the Node.js REPL.
// Required modules.
coffee = require('coffee-script');
2010-01-29 22:51:51 -05:00
// Shortcut variables.
prompt = 'coffee> ';
quit = function quit() {
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.
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, {
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);
process.stdio.open();
2010-01-29 22:51:51 -05:00
print(prompt);
})();