2010-07-24 15:31:43 +00:00
|
|
|
(function() {
|
2010-06-11 22:36:18 +00:00
|
|
|
var CoffeeScript, helpers, readline, repl, run, stdio;
|
2010-03-16 03:39:46 +00:00
|
|
|
CoffeeScript = require('./coffee-script');
|
2010-09-25 00:29:44 +00:00
|
|
|
helpers = require('./helpers');
|
2010-06-11 22:36:18 +00:00
|
|
|
readline = require('readline');
|
|
|
|
stdio = process.openStdin();
|
2010-03-16 05:53:25 +00:00
|
|
|
helpers.extend(global, {
|
2010-05-15 03:40:04 +00:00
|
|
|
quit: function() {
|
2010-03-08 02:49:08 +00:00
|
|
|
return process.exit(0);
|
|
|
|
}
|
|
|
|
});
|
2010-05-15 03:40:04 +00:00
|
|
|
run = function(buffer) {
|
2010-02-18 04:51:43 +00:00
|
|
|
var val;
|
2010-01-30 03:51:51 +00:00
|
|
|
try {
|
2010-09-21 05:36:23 +00:00
|
|
|
val = CoffeeScript.eval(buffer.toString(), {
|
2010-10-13 19:09:56 +00:00
|
|
|
bare: true,
|
2010-03-08 03:17:45 +00:00
|
|
|
globals: true,
|
2010-07-31 00:37:12 +00:00
|
|
|
fileName: 'repl'
|
2010-03-08 02:49:08 +00:00
|
|
|
});
|
2010-10-28 02:50:20 +00:00
|
|
|
if (val !== void 0) {
|
2010-10-25 01:15:20 +00:00
|
|
|
console.log(val);
|
2010-01-30 03:51:51 +00:00
|
|
|
}
|
|
|
|
} catch (err) {
|
2010-10-24 18:11:09 +00:00
|
|
|
console.error(err.stack || err.toString());
|
2010-01-30 03:51:51 +00:00
|
|
|
}
|
2010-06-11 22:36:18 +00:00
|
|
|
return repl.prompt();
|
2010-01-30 03:51:51 +00:00
|
|
|
};
|
2010-06-11 22:36:18 +00:00
|
|
|
repl = readline.createInterface(stdio);
|
|
|
|
repl.setPrompt('coffee> ');
|
2010-07-18 11:54:44 +00:00
|
|
|
stdio.on('data', function(buffer) {
|
2010-06-11 22:36:18 +00:00
|
|
|
return repl.write(buffer);
|
|
|
|
});
|
2010-07-18 11:54:44 +00:00
|
|
|
repl.on('close', function() {
|
2010-06-11 22:36:18 +00:00
|
|
|
return stdio.destroy();
|
|
|
|
});
|
2010-07-18 11:54:44 +00:00
|
|
|
repl.on('line', run);
|
2010-06-11 22:36:18 +00:00
|
|
|
repl.prompt();
|
2010-09-21 07:53:58 +00:00
|
|
|
}).call(this);
|