Skip to content

Commit

Permalink
Merge pull request #75 from NuiCpp/devel
Browse files Browse the repository at this point in the history
Bug Fixes and More Tests
  • Loading branch information
5cript authored Sep 20, 2023
2 parents 1e1ee1a + 81b96ac commit 35209fe
Show file tree
Hide file tree
Showing 14 changed files with 1,011 additions and 64 deletions.
17 changes: 17 additions & 0 deletions nui/include/nui/backend/rpc_hub.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <nui/data_structures/selectables_registry.hpp>
#include <nui/utility/meta/function_traits.hpp>
#include <nui/utility/meta/pick_first.hpp>
#include <nui/shared/on_destroy.hpp>
#include <nlohmann/json.hpp>
#include <fmt/format.h>

Expand Down Expand Up @@ -96,6 +97,22 @@ namespace Nui
}})();
)";

struct AutoUnregister : public OnDestroy
{
AutoUnregister(RpcHub const* hub, std::string name)
: OnDestroy{[hub, name = std::move(name)]() {
hub->unregisterFunction(name);
}}
{}
};

template <typename T>
AutoUnregister autoRegisterFunction(std::string const& name, T&& func) const
{
registerFunction(name, std::forward<T>(func));
return AutoUnregister{this, name};
}

template <typename T>
void registerFunction(std::string const& name, T&& func) const
{
Expand Down
Loading

0 comments on commit 35209fe

Please sign in to comment.