6 #ifdef SPH_USE_CHAISCRIPT
22 , callbacks(callbacks) {
27 void setParam(
const std::string& key,
const T value) {
29 if (!current.
has<T>()) {
30 throw InvalidSetup(
"Type mismatch when setting parameter '" + key +
"'");
32 settings.
set(key, value);
37 node->
run(global, callbacks);
45 void Node::setParam(
const std::string& key,
const std::string value) {
47 if (current.
has<std::string>()) {
48 settings.
set(key, value);
49 }
else if (current.
has<
Path>()) {
55 throw InvalidSetup(
"Unknown value of parameter '" + key +
"': " + value);
57 ew.
value = enumValue.value();
58 settings.
set(key, ew);
60 throw InvalidSetup(
"Type mismatch when setting parameter '" + key +
"'");
67 chaiscript::ChaiScript chai;
68 Chai::registerBindings(chai);
70 chai.add(chaiscript::user_type<Chai::Node>(),
"Node");
71 chai.add(chaiscript::fun(&Chai::Node::setParam<Float>),
"setParam");
72 chai.add(chaiscript::fun(&Chai::Node::setParam<int>),
"setParam");
73 chai.add(chaiscript::fun(&Chai::Node::setParam<std::string>),
"setParam");
74 chai.add(chaiscript::fun(&Chai::Node::run),
"run");
76 chai.add(chaiscript::fun<std::function<Chai::Node(std::string)>>([&](std::string name) {
77 for (
const auto& node : nodes) {
79 return Chai::Node(node, global, callbacks);
86 chai.eval_file(file.native());
#define NAMESPACE_SPH_END
Utility functions and classes exposed to the embedded scripting language.
static Optional< TEnum > fromString(const std::string &value)
Interface used during job evaluation.
virtual bool shouldAbortRun() const =0
Returns whether current run should be aborted or not.
Thrown when components of the run are mutually incompatible.
virtual void run(const RunSettings &global, IJobCallbacks &callbacks) override
Evaluates the node and all its providers.
std::string instanceName() const
Returns the instance name of the job.
VirtualSettings getSettings() const
Returns settings object allowing to access and modify the state of the job.
Object representing a path on a filesystem.
Variant, an implementation of type-safe union, similar to std::variant or boost::variant.
INLINE bool has() const
Checks if the variant currently hold value of given type.
INLINE T & get()
Returns the stored value.
Holds a map of virtual entries, associated with a unique name.
IVirtualEntry::Value get(const std::string &key) const
Returns a value of an entry.
void set(const std::string &key, const IVirtualEntry::Value &value)
Modifies an existing entry in the settings.