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-03-16 05:53:25 +00:00
|
|
|
helpers = require('./helpers').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-04-10 22:05:35 +00:00
|
|
|
val = CoffeeScript.run(buffer.toString(), {
|
2010-06-12 23:05:13 +00:00
|
|
|
noWrap: true,
|
2010-03-08 03:17:45 +00:00
|
|
|
globals: true,
|
|
|
|
source: 'repl'
|
2010-03-08 02:49:08 +00:00
|
|
|
});
|
2010-01-30 03:51:51 +00:00
|
|
|
if (val !== undefined) {
|
2010-06-01 23:24:48 +00:00
|
|
|
puts(inspect(val));
|
2010-01-30 03:51:51 +00:00
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
puts(err.stack || err.toString());
|
|
|
|
}
|
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-02-24 23:56:32 +00:00
|
|
|
})();
|