I am trying to use the scripting capabilities, but since my topics are rather large (but structured) I would like to be able to put something like a publish() function in a script file where I only need to fill in one part that changes and require that script in all my other script to reduce boilerplate.
So it would look something like this:
common.js
function publish(topic, payload) {
mqtt.publish("device1/cmd/${topic}/fmt/json", JSON.stringify(payload), 2, false);
}
I am trying to use the scripting capabilities, but since my topics are rather large (but structured) I would like to be able to put something like a publish() function in a script file where I only need to fill in one part that changes and require that script in all my other script to reduce boilerplate. So it would look something like this: common.js
foo.js
bar.js
sadly, nashorn's load() function doesn't seem to work. Whenever that one is in the code, it fails. Or am I doing something wrong?