如何从CoffeeScript脚本中启动CoffeeScript复制? [英] How do I start a CoffeeScript repl from within a CoffeeScript script?

查看:99
本文介绍了如何从CoffeeScript脚本中启动CoffeeScript复制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我这样做

repl = require 'repl'

repl.start {useGlobal: true}

它启动一个Node repl。

It starts a Node repl. How do I start a CoffeeScript repl instead?

感谢

推荐答案

Nesh是一个尝试,使其更容易和可扩展的项目:

Nesh is a project to try and make this a bit easier and extensible:

http://danielgtaylor.github.com/nesh/

它提供了嵌入REPL并支持多种语言(如CoffeeScript)的方法以及提供异步插件架构,支持在启动时在REPL的上下文中执行代码等。例如:

It provides a way to embed a REPL with support for multiple languages like CoffeeScript as well as providing an asyncronous plugin architecture, support to execute code in the context of the REPL on startup, etc. For example:

nesh = require 'nesh'

nesh.loadLanguage 'coffee'

nesh.start (err, repl) ->
    nesh.log.error err if err

它还支持一系列选项默认插件,并公开一些内置的方便功能:

It also supports a bunch of options with the default plugins and exposes some built-in convenience functions as well:

opts =
    welcome: 'Welcome to my interpreter!'
    prompt: '> '
    evalData: CoffeeScript.compile 'hello = (name="world") -> "Hello, #{world}!"', {bare: true}

nesh.start opts, (err, repl) ->
    nesh.log.error err if err

这篇关于如何从CoffeeScript脚本中启动CoffeeScript复制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆