fix an issue that node sockets can be duplicated

This commit is contained in:
falsycat 2022-09-26 12:45:05 +09:00
parent 5ef347fa2e
commit b949383932
3 changed files with 19 additions and 1 deletions

View File

@ -7,14 +7,17 @@
namespace nf7::util {
template <typename T>
inline void Uniq(std::vector<T>& v) noexcept {
inline size_t Uniq(std::vector<T>& v) noexcept {
size_t n = 0;
for (auto itr = v.begin(); itr < v.end();) {
if (v.end() != std::find(itr+1, v.end(), *itr)) {
itr = v.erase(itr);
++n;
} else {
++itr;
}
}
return n;
}
} // namespace nf7::util

View File

@ -267,6 +267,14 @@ try {
auto new_inputs = yaml["inputs"] .as<std::vector<std::string>>();
auto new_outputs = yaml["outputs"].as<std::vector<std::string>>();
auto new_script = yaml["script"].as<std::string>();
if (nf7::util::Uniq(new_inputs) > 0) {
throw nf7::Exception {"duplicated inputs"};
}
if (nf7::util::Uniq(new_outputs) > 0) {
throw nf7::Exception {"duplicated outputs"};
}
inputs = std::move(new_inputs);
outputs = std::move(new_outputs);
script = std::move(new_script);

View File

@ -35,6 +35,7 @@
#include "common/nfile_watcher.hh"
#include "common/node.hh"
#include "common/ptr_selector.hh"
#include "common/util_algorithm.hh"
#include "common/yas_std_filesystem.hh"
@ -232,10 +233,16 @@ nf7::Future<std::shared_ptr<LuaNode::Meta>> LuaNode::Build() noexcept {
lua_getfield(L, 1, "inputs");
nf7::luajit::ToStringList(L, ret->inputs, -1);
if (nf7::util::Uniq(ret->inputs) > 0) {
throw nf7::Exception {"duplicated inputs"};
}
lua_pop(L, 1);
lua_getfield(L, 1, "outputs");
nf7::luajit::ToStringList(L, ret->outputs, -1);
if (nf7::util::Uniq(ret->outputs)) {
throw nf7::Exception {"duplicated outputs"};
}
lua_pop(L, 1);
lua_getfield(L, 1, "lambda");