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