Skip to content

Instantly share code, notes, and snippets.

@borkdude
Last active March 1, 2020 13:21
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save borkdude/591e9f2a7453fd0872823c50b3e60130 to your computer and use it in GitHub Desktop.
Save borkdude/591e9f2a7453fd0872823c50b3e60130 to your computer and use it in GitHub Desktop.
Google cloud function running sci
const { evalString } = require("@borkdude/sci");
let printlnArgs = [];
function println(...args) {
printlnArgs.push(args.map(arg => arg.toString()).join(" "));
}
exports.evalClojureExpr = (req, res) => {
const { text } = req.body;
try {
const result = evalString(text, {namespaces: {"clojure.core": {println: println}}});
let value = [];
if (printlnArgs.length !== 0) {
value.push(...printlnArgs);
}
if (result !== undefined) {
value.push(result.toString());
}
res.json({
response_type: "in_channel",
text: `\`\`\`${value.join("\n")}\`\`\``,
type: "mrkdwn"
});
} catch (error) {
res.json({
response_type: "in_channel",
text: `\`${error.message}\``,
type: "mrkdwn"
});
}
printlnArgs = [];
};
@borkdude
Copy link
Author

borkdude commented Feb 21, 2020

sci-slackbot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment