2010-01-29 22:51:51 -05:00
|
|
|
(function(){
|
2010-06-11 18:36:18 -04:00
|
|
|
var CoffeeScript, helpers, readline, repl, run, stdio;
|
2010-03-15 20:39:46 -07:00
|
|
|
CoffeeScript = require('./coffee-script');
|
2010-03-15 22:53:25 -07:00
|
|
|
helpers = require('./helpers').helpers;
|
2010-06-11 18:36:18 -04:00
|
|
|
readline = require('readline');
|
|
|
|
stdio = process.openStdin();
|
2010-03-15 22:53:25 -07: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-04-10 18:05:35 -04:00
|
|
|
val = CoffeeScript.run(buffer.toString(), {
|
2010-06-12 19:05:13 -04:00
|
|
|
noWrap: true,
|
2010-03-07 22:17:45 -05:00
|
|
|
globals: true,
|
|
|
|
source: '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> ');
|
|
|
|
stdio.addListener('data', function(buffer) {
|
|
|
|
return repl.write(buffer);
|
|
|
|
});
|
|
|
|
repl.addListener('close', function() {
|
|
|
|
return stdio.destroy();
|
|
|
|
});
|
|
|
|
repl.addListener('line', run);
|
|
|
|
repl.prompt();
|
2010-02-24 18:56:32 -05:00
|
|
|
})();
|