Hi,
I'm afraid the SJS repl module was built mainly for our needs with the
`sjs` commandline REPL, so it doesn't have the same flexibility as
the nodejs version. It's not under-documented, there just isn't anything
configurable to document ;).
However, it should be straightforward enough to wrap the nodejs
repl module with a custom `eval` that runs SJS code.
It looks like you're close, but you're trying to call into an SJS
function from plain JS, which is why you'd see the continuation object
rather than the result.
While it's possible to call into SJS from plain JS with some additional
effort, the easiest thing to do is to just write the wrapper
code in an .sjs module, and then waiting for a suspended function
should just work.
I had a go, and this seems to work:
var sjsCompiler = require('sjs:compile/sjs');
var { extend } = require('sjs:object');
var repl = require('nodejs:repl');
var vm = require('nodejs:vm');
var overrides = {
require:require,
}
var eval = function(cmd, context, filename, callback) {
// NOTE: this function is called from plain JS, so the
// caller can't wait for a return value. But that's OK,
// we provide the result to `callback` rather than
// returning anything.
try {
// remove leading '(' and trailing ')' that
// nodejs inserts for some reason
cmd = cmd.slice(1, cmd.length-1);
//console.log("COMPILING: " + cmd);
var js = sjsCompiler.compile(cmd);
//console.log("RUNNING: " + js);
extend(context, overrides);
var result = vm.runInContext(js, context, '(repl)');
callback(null, result);
} catch(e) {
callback(e);
}
};
repl.start({eval:eval});
I don't know if your code needs access to sjs' `require` function.
If not, you can leave out the `overrides` stuff. I also don't
know why the nodejs repl wraps the code in parens, but that threw
off the SJS compiler so I had to strip them.
The above module should be named with an .sjs extension, and
run using the `sjs` command rather than `node`. You can still
use whatever nodejs modules you need (prefixed with 'nodejs:'),
but you also get access to SJS' modules and functionality (including
waiting for the completion of any suspended result).
BTW, if you're running this as a HTTP server or using nodejs streams,
we've got a few modules that make things a little easier to work with
in SJS than the raw nodejs APIs:
https://conductance.io/reference#sjs:nodejs/streamhttps://conductance.io/reference#sjs:nodejs/http::withServerAnd if your server is anything bigger than this, you may want to use conductance, which provides a bunch of useful web functionality on top of SJS (e.g routes, generated pages, rich UI, client-server RPC, etc):
https://conductance.io/Hope that helps, let us know how it goes :)
Cheers,
- Tim.