Last active
March 1, 2020 13:21
-
-
Save borkdude/591e9f2a7453fd0872823c50b3e60130 to your computer and use it in GitHub Desktop.
Google cloud function running sci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = []; | |
}; |
Author
borkdude
commented
Feb 21, 2020
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment