1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/examples/custom_repl.coffee
David M. Lee 576fe44ef8 Export the CoffeeScript REPL.
This is done by adding a root level wrapper script for
lib/coffee-script/repl, similar to how the register script is wrapped.
This allows user programs to embed a CoffeeScript REPL without digging
into CoffeeScript's internals.
2014-04-18 08:26:51 -05:00

20 lines
542 B
CoffeeScript

###
Example of embedding the CoffeeScript REPL, strikingly similar to the Node REPL.
###
# Require 'coffee-script/repl' to import the repl module
repl = require '../repl'
console.log 'Custom REPL! Type `sayHi()` to see what it does!'
# Start the REPL with your configuration
r = repl.start
prompt: 'my-repl> '
# Fields added to the context object are exposed as variables in the REPL
r.context.sayHi = -> console.log 'Hello'
# An exit event is emitted when the user exits the REPL
r.on 'exit', ->
console.log 'Bye!'
process.exit()