fix issues of LuaJIT/Node

This commit is contained in:
2022-08-28 01:03:33 +09:00
parent 3539181650
commit d41fd1c47b
4 changed files with 20 additions and 26 deletions

View File

@@ -84,15 +84,18 @@ Thread::Handler Thread::CreateNodeLambdaHandler(
case 0:
th.ExecResume(L);
return;
case 2: {
auto k = luaL_checkstring(L, 1);
auto v = nf7::luajit::CheckValue(L, 2);
caller->env().ExecSub(
caller, [caller, callee, k = std::string {k}, v = std::move(v)]() {
caller->Handle(k, v, callee);
});
th.ExecResume(L);
} return;
case 2:
if (auto v = nf7::luajit::ToValue(L, 2)) {
auto k = luaL_checkstring(L, 1);
caller->env().ExecSub(
caller, [caller, callee, k = std::string {k}, v = std::move(v)]() {
caller->Handle(k, *v, callee);
});
th.ExecResume(L);
return;
} else {
}
/* FALLTHROUGH */
default:
if (auto log = th.logger()) {
log->Warn("invalid use of yield, nf7:yield() or nf7:yield(name, value)");

View File

@@ -24,19 +24,16 @@ class NodeRootLambda final : public nf7::Node::Lambda,
NodeRootLambda(NodeRootLambda&&) = delete;
NodeRootLambda& operator=(const NodeRootLambda&) = delete;
NodeRootLambda& operator=(NodeRootLambda&&) = delete;
bool KeepAlive() noexcept {
if (target_.expired() && pro_.size()) {
for (auto& pro : pro_) {
pro.second.Throw(std::make_exception_ptr(
nf7::Exception {"output was never satisified"}));
}
~NodeRootLambda() noexcept {
target_ = nullptr;
for (auto& pro : pro_) {
pro.second.Throw(std::make_exception_ptr(
nf7::Exception {"output was never satisified"}));
}
return !target_.expired();
}
private:
std::weak_ptr<nf7::Node::Lambda> target_;
std::shared_ptr<nf7::Node::Lambda> target_;
std::unordered_map<std::string, nf7::Future<nf7::Value>::Promise> pro_;
std::unordered_map<std::string, std::function<void(const nf7::Value&)>> handler_;