2018-05-23 15:16:56 +00:00
|
|
|
// still needs to be run on a separate file due to the global context
|
|
|
|
var RunCode = require('./runCode.js');
|
2018-05-21 21:22:19 +00:00
|
|
|
|
|
|
|
class CodeRunner {
|
|
|
|
constructor(options) {
|
|
|
|
this.plugins = options.plugins;
|
|
|
|
this.logger = options.logger;
|
|
|
|
this.events = options.events;
|
|
|
|
|
2018-05-23 15:16:56 +00:00
|
|
|
// necessary to init the context
|
|
|
|
RunCode.initContext();
|
|
|
|
|
|
|
|
this.events.on("runcode:register", (varName, code) => {
|
|
|
|
RunCode.registerVar(varName, code);
|
|
|
|
});
|
2018-05-21 21:22:19 +00:00
|
|
|
|
2018-05-23 15:16:56 +00:00
|
|
|
this.events.setCommandHandler('runcode:eval', (code, cb) => {
|
|
|
|
let result = RunCode.doEval(code);
|
|
|
|
if (cb) {
|
|
|
|
cb(null, result);
|
|
|
|
}
|
|
|
|
});
|
2018-05-21 21:22:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = CodeRunner;
|