Skip to content

Instantly share code, notes, and snippets.

@jeroenvandijk
Forked from borkdude/sci_google_cloud.js
Created February 22, 2020 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeroenvandijk/ff744466007c52ab0c30ca8e43cbd0df to your computer and use it in GitHub Desktop.
Save jeroenvandijk/ff744466007c52ab0c30ca8e43cbd0df to your computer and use it in GitHub Desktop.
Google cloud function running sci
const { evalString } = require("@borkdude/sci");
let printlnArgs = null;
function println(...args) {
printlnArgs = 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 !== null) {
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 = null;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment