diff --git a/src/LegacyRemoteCall.cpp b/src/LegacyRemoteCall.cpp index 2a60e63..7170725 100644 --- a/src/LegacyRemoteCall.cpp +++ b/src/LegacyRemoteCall.cpp @@ -3,8 +3,8 @@ #include "ll/api/mod/RegisterHelper.h" namespace RemoteCall { -extern void removeAllFunc(); -} +void removeAllFunc(); +} // namespace RemoteCall namespace legacy_remote_call_api { LegacyRemoteCallAPI& LegacyRemoteCallAPI::getInstance() { @@ -12,15 +12,18 @@ LegacyRemoteCallAPI& LegacyRemoteCallAPI::getInstance() { return instance; } -bool LegacyRemoteCallAPI::load() { return true; } +bool LegacyRemoteCallAPI::load() /*NOLINT*/ { return true; } -bool LegacyRemoteCallAPI::enable() { return true; } +bool LegacyRemoteCallAPI::enable() /*NOLINT*/ { return true; } -bool LegacyRemoteCallAPI::disable() { +bool LegacyRemoteCallAPI::disable() /*NOLINT*/ { RemoteCall::removeAllFunc(); return true; } -} // namespace legacy_remotecallapi +} // namespace legacy_remote_call_api -LL_REGISTER_MOD(legacy_remote_call_api::LegacyRemoteCallAPI, legacy_remote_call_api::LegacyRemoteCallAPI::getInstance()); +LL_REGISTER_MOD( + legacy_remote_call_api::LegacyRemoteCallAPI, + legacy_remote_call_api::LegacyRemoteCallAPI::getInstance() +); diff --git a/src/RemoteCallAPI.cpp b/src/RemoteCallAPI.cpp index f5ce196..47de754 100644 --- a/src/RemoteCallAPI.cpp +++ b/src/RemoteCallAPI.cpp @@ -1,14 +1,20 @@ +#include "RemoteCallAPI.h" + #include "LegacyRemoteCall.h" #include "ll/api/io/Logger.h" #include "ll/api/utils/StringUtils.h" -#include "RemoteCallAPI.h" -namespace RemoteCall { -CallbackFn const EMPTY_FUNC{}; -std::unordered_map exportedFuncs; - -ll::io::Logger& getLogger() { return legacy_remote_call_api::LegacyRemoteCallAPI::getInstance().getSelf().getLogger();} +namespace RemoteCall { +ll::io::Logger& getLogger() { return legacy_remote_call_api::LegacyRemoteCallAPI::getInstance().getSelf().getLogger(); } +struct TransparentHasher { + using is_transparent = void; + auto operator()(const std::string& key) const { return std::hash{}(key); } + auto operator()(std::string_view key) const { return std::hash{}(key); } + auto operator()(const char* key) const { return std::hash{}(key); } +}; +CallbackFn const EMPTY_FUNC{}; +std::unordered_map> exportedFuncs; bool exportFunc(std::string const& nameSpace, std::string const& funcName, CallbackFn&& callback, void* handle) { if (nameSpace.find("::") != std::string::npos) { getLogger().error("Namespace can't includes \"::\""); @@ -29,18 +35,18 @@ bool hasFunc(std::string const& nameSpace, std::string const& funcName) { return exportedFuncs.find(nameSpace + "::" + funcName) != exportedFuncs.end(); } -bool removeFunc(std::string&& key) { return exportedFuncs.erase(key); } +bool removeFunc(std::string_view key) { + if (auto iter = exportedFuncs.find(key); iter != exportedFuncs.end()) { + exportedFuncs.erase(iter); + return true; + } + return false; +} bool removeFunc(std::string const& nameSpace, std::string const& funcName) { return removeFunc(nameSpace + "::" + funcName); } -void _onCallError(std::string const& msg, void* handle) { - getLogger().error(msg); - auto plugin = ll::mod::NativeMod::getByHandle(handle); - if (plugin) getLogger().error("In plugin <{}>", plugin->getManifest().name); -} - int removeNameSpace(std::string const& nameSpace) { int count = 0; for (auto iter = exportedFuncs.begin(); iter != exportedFuncs.end();) { @@ -55,13 +61,18 @@ int removeNameSpace(std::string const& nameSpace) { int removeFuncs(std::vector>& funcs) { int count = 0; for (auto& [ns, name] : funcs) { - if (removeFunc(ns + "::" + name)) count++; + if (removeFunc((ns + "::").append(name))) count++; } return count; } void removeAllFunc() { exportedFuncs.clear(); } +void _onCallError(std::string const& msg, void* handle) { + getLogger().error(msg); + auto plugin = ll::mod::NativeMod::getByHandle(handle); + if (plugin) getLogger().error("In plugin <{}>", plugin->getManifest().name); +} } // namespace RemoteCall static_assert(RemoteCall::is_supported_type_v); @@ -78,75 +89,4 @@ static_assert(RemoteCall::is_supported_type_v); static_assert(RemoteCall::is_supported_type_v); static_assert(RemoteCall::is_supported_type_v); // static_assert(RemoteCall::is_supported_type_v); -static_assert(RemoteCall::is_supported_type_v); - -#ifdef DEBUG -#include "llapi/ScheduleAPI.h" -#include "llapi/mc/Player.hpp" -inline bool testExtra = ([]() { - std::vector input{"aa", "abcd", "test"}; - auto output = RemoteCall::extract(RemoteCall::pack(input)); - assert(output == input); - std::unordered_map input2{ - {"aa", "bb" }, - {"ab", "ba" }, - {"abc", "cba"}, - }; - auto output2 = RemoteCall::extract(RemoteCall::pack(input2)); - assert(output2 == input2); - std::vector input3{input2, input2}; - auto output3 = RemoteCall::extract(RemoteCall::pack(input3)); - assert(output3 == input3); - std::unordered_map input4{ - {"aa", input3}, - {"ab", input3}, - {"abc", input3}, - }; - auto output4 = RemoteCall::extract(RemoteCall::pack(input4)); - assert(output4 == input4); - - std::vector input5{input4, input4, input4}; - auto output5 = RemoteCall::extract(RemoteCall::pack(input5)); - assert(output5 == input5); -#if false - __debugbreak(); - output5.erase(output5.begin()); - assert(output5 == input5); - __debugbreak(); -#endif // false - return true; -})(); -int TestExport(std::string a0, int a1, int a2) { return static_cast(a0.size()) + a1; } -std::unique_ptr TestSimulatedPlayerLL(Player* player) { return player->getNbt(); } - -void exportTestSimulatedPlayerLL() { - RemoteCall::exportAs("TestRemoteCall", "TestSimulatedPlayerLL", TestSimulatedPlayerLL); -} -#include "llapi/EventAPI.h" -auto TestRemoteCall = ([]() -> bool { - std::thread([]() { - SetCurrentThreadDescription(L"LL_Test_RemoteCall_Thread"); - Sleep(5000); - Schedule::nextTick([]() { - RemoteCall::exportAs("TestNameSpace", "StrSize", [](std::string arg) -> size_t { return arg.size(); }); - - exportTestSimulatedPlayerLL(); - RemoteCall::exportAs("Test", "test2", TestExport); - if (!RemoteCall::hasFunc("TestRemoteCall", "TestSimulatedPlayerJs")) return; - auto func = RemoteCall::importAs("Test", "test2"); - auto func2 = RemoteCall::importAs>("Test", "test2"); - auto size = func("TestParam", 5, 10); - static auto TestSimulatedPlayerJs = - RemoteCall::importAs("TestRemoteCall", "TestSimulatedPlayerJs"); - Event::PlayerJoinEvent::subscribe_ref([](Event::PlayerJoinEvent& ev) { - logger.warn("TestSimulatedPlayer"); - auto res = TestSimulatedPlayerJs(ev.mPlayer); - logger.warn("Result: {}", res); - return true; - }); - }); - }).detach(); - return true; -})(); - -#endif // DEBUG +static_assert(RemoteCall::is_supported_type_v); \ No newline at end of file diff --git a/src/RemoteCallAPI.h b/src/RemoteCallAPI.h index 77354ac..cdb2bfa 100644 --- a/src/RemoteCallAPI.h +++ b/src/RemoteCallAPI.h @@ -1,16 +1,21 @@ #pragma once #include "fmt/core.h" +#include "ll/api/base/TypeTraits.h" #include "ll/api/utils/SystemUtils.h" +#include "mc/deps/core/math/Vec3.h" #include "mc/nbt/CompoundTag.h" #include "mc/world/Container.h" #include "mc/world/actor/player/Player.h" #include "mc/world/item/ItemStack.h" -#include "mc/deps/core/math/Vec3.h" #include "mc/world/level/BlockPos.h" #include "mc/world/level/block/Block.h" #include "mc/world/level/block/actor/BlockActor.h" -#define TEST_NEW_VALUE_TYPE +#ifdef REMOTE_CALL_EXPORT +#define REMOTE_CALL_API __declspec(dllexport) +#else +#define REMOTE_CALL_API __declspec(dllimport) +#endif /////////////////////////////////////////////////////// // Remote Call API @@ -30,14 +35,49 @@ // logger.info(`Size of str: ${strSize("12345678")}`); // ///////////////////////////////////////////////////// + namespace RemoteCall { -#ifdef TEST_NEW_VALUE_TYPE -// ..... struct NbtType { CompoundTag const* ptr = nullptr; bool own = false; - NbtType(std::unique_ptr tag) : ptr(tag.release()), own(true){}; - NbtType(CompoundTag const* ptr) : ptr(ptr), own(false){}; + NbtType(std::unique_ptr tag) noexcept /*NOLINT*/ : ptr(tag.release()), own(true) {} + NbtType(CompoundTag const* ptr) noexcept /*NOLINT*/ : ptr(ptr), own(false) {} + NbtType(NbtType const& other) { + if (other.own) { + ptr = new CompoundTag(*other.ptr); + own = true; + } else { + ptr = other.ptr; + own = false; + } + } + NbtType(NbtType&& other) noexcept { + std::swap(ptr, other.ptr); + std::swap(own, other.own); + } + NbtType& operator=(NbtType const& other) { + if (this != &other) { + if (own) delete const_cast(ptr); + if (other.own) { + ptr = new CompoundTag(*other.ptr); + own = true; + } else { + ptr = other.ptr; + own = false; + } + } + return *this; + } + NbtType& operator=(NbtType&& other) noexcept { + std::swap(ptr, other.ptr); + std::swap(own, other.own); + return *this; + } + ~NbtType() { + if (own) { + delete const_cast(ptr); + } + } inline std::unique_ptr tryGetUniquePtr() { if (!own) return {}; own = false; @@ -64,8 +104,44 @@ struct NbtType { struct ItemType { ItemStack const* ptr = nullptr; bool own = false; - ItemType(std::unique_ptr tag) : ptr(tag.release()), own(true){}; - ItemType(ItemStack const* ptr) : ptr(ptr), own(false){}; + ItemType(std::unique_ptr tag) noexcept /*NOLINT*/ : ptr(tag.release()), own(true) {} + ItemType(ItemStack const* ptr) noexcept /*NOLINT*/ : ptr(ptr), own(false) {} + ItemType(ItemType const& other) { + if (other.own) { + ptr = new ItemStack(*other.ptr); + own = true; + } else { + ptr = other.ptr; + own = false; + } + } + ItemType(ItemType&& other) noexcept { + std::swap(ptr, other.ptr); + std::swap(own, other.own); + } + ItemType& operator=(ItemType const& other) { + if (this != &other) { + if (own) delete const_cast(ptr); + if (other.own) { + ptr = new ItemStack(*other.ptr); + own = true; + } else { + ptr = other.ptr; + own = false; + } + } + return *this; + } + ItemType& operator=(ItemType&& other) noexcept { + std::swap(ptr, other.ptr); + std::swap(own, other.own); + return *this; + } + ~ItemType() { + if (own) { + delete const_cast(ptr); + } + } inline std::unique_ptr tryGetUniquePtr() { if (!own) return {}; own = false; @@ -93,8 +169,8 @@ struct BlockType { Block const* block; BlockPos blockPos; int dimension; - BlockType(Block* block) : block(block){}; - BlockType(Block const* ptr) : block(ptr) { + BlockType(Block* block) noexcept /*NOLINT*/ : block(block) {}; + BlockType(Block const* ptr) noexcept /*NOLINT*/ : block(ptr) { blockPos = BlockPos::ZERO(); dimension = 0; }; @@ -109,37 +185,34 @@ struct BlockType { struct NumberType { __int64 i = 0; double f = 0; - NumberType(__int64 i, double f) : i(i), f(f){}; - template - std::enable_if_t || std::is_floating_point_v, NumberType&> operator=(T v) { + NumberType(__int64 i, double f) : i(i), f(f) {}; + template || std::is_floating_point_v>> + NumberType& operator=(T&& v) noexcept { i = static_cast<__int64>(v); f = static_cast(v); + return *this; } - NumberType(double v) : i(static_cast<__int64>(v)), f(static_cast(v)){}; - NumberType(float v) : i(static_cast<__int64>(v)), f(static_cast(v)){}; - NumberType(__int64 v) : i(static_cast<__int64>(v)), f(static_cast(v)){}; - NumberType(int v) : i(static_cast<__int64>(v)), f(static_cast(v)){}; - NumberType(short v) : i(static_cast<__int64>(v)), f(static_cast(v)){}; - NumberType(char v) : i(static_cast<__int64>(v)), f(static_cast(v)){}; - NumberType(unsigned __int64 v) : i(static_cast<__int64>(v)), f(static_cast(v)){}; - NumberType(unsigned int v) : i(static_cast<__int64>(v)), f(static_cast(v)){}; - NumberType(unsigned short v) : i(static_cast<__int64>(v)), f(static_cast(v)){}; - NumberType(unsigned char v) : i(static_cast<__int64>(v)), f(static_cast(v)){}; + NumberType(double v) noexcept /*NOLINT*/ : i(static_cast<__int64>(v)), f(static_cast(v)) {}; + NumberType(float v) noexcept /*NOLINT*/ : i(static_cast<__int64>(v)), f(static_cast(v)) {}; + NumberType(__int64 v) noexcept /*NOLINT*/ : i(static_cast<__int64>(v)), f(static_cast(v)) {}; + NumberType(int v) noexcept /*NOLINT*/ : i(static_cast<__int64>(v)), f(static_cast(v)) {}; + NumberType(short v) noexcept /*NOLINT*/ : i(static_cast<__int64>(v)), f(static_cast(v)) {}; + NumberType(char v) noexcept /*NOLINT*/ : i(static_cast<__int64>(v)), f(static_cast(v)) {}; + NumberType(unsigned __int64 v) noexcept /*NOLINT*/ : i(static_cast<__int64>(v)), f(static_cast(v)) {}; + NumberType(unsigned int v) noexcept /*NOLINT*/ : i(static_cast<__int64>(v)), f(static_cast(v)) {}; + NumberType(unsigned short v) noexcept /*NOLINT*/ : i(static_cast<__int64>(v)), f(static_cast(v)) {}; + NumberType(unsigned char v) noexcept /*NOLINT*/ : i(static_cast<__int64>(v)), f(static_cast(v)) {}; template - inline std::enable_if_t, RTN> get() { + inline std::enable_if_t || std::is_floating_point_v, RTN> get() { return static_cast(i); }; - template - inline std::enable_if_t, RTN> get() { - return static_cast(f); - }; }; struct WorldPosType { Vec3 pos = Vec3::ZERO(); int dimId = 3; // VanillaDimensions::Undefined; - WorldPosType(Vec3 const& pos, int dimId = 3) : pos(pos), dimId(dimId){}; - WorldPosType(std::pair const& pos) : pos(pos.first), dimId(pos.second){}; + WorldPosType(Vec3 const& pos, int dimId = 3) noexcept /*NOLINT*/ : pos(pos), dimId(dimId) {}; + WorldPosType(std::pair const& pos) noexcept /*NOLINT*/ : pos(pos.first), dimId(pos.second) {}; template inline RTN get() = delete; template <> @@ -163,8 +236,8 @@ struct WorldPosType { struct BlockPosType { BlockPos pos = BlockPos::ZERO(); int dimId = 0; - BlockPosType(BlockPos const& pos, int dimId = 0) : pos(pos), dimId(dimId){}; - BlockPosType(std::pair const& pos) : pos(pos.first), dimId(pos.second){}; + BlockPosType(BlockPos const& pos, int dimId = 0) noexcept /*NOLINT*/ : pos(pos), dimId(dimId) {}; + BlockPosType(std::pair const& pos) noexcept /*NOLINT*/ : pos(pos.first), dimId(pos.second) {}; template inline RTN get() = delete; template <> @@ -187,89 +260,99 @@ struct BlockPosType { // std::string -> json // std::string* -> bytes -#define ExtraType \ - std::nullptr_t, NumberType, Player*, Actor*, BlockActor*, Container*, WorldPosType, BlockPosType, ItemType, \ - BlockType, NbtType -#define ElementType bool, std::string, ExtraType -template -static constexpr bool is_one_of_v = - std::_Meta_find_unique_index, _Ty>::value < sizeof...(_Types); -template -static constexpr bool is_extra_type_v = std::_Is_any_of_v<_Ty, ExtraType>; - -static_assert(sizeof(std::variant) == sizeof(std::string) + 8); +template +static constexpr bool is_extra_type_v = ll::traits::is_one_of_v< + Ty, + std::nullptr_t, + NumberType, + Player*, + Actor*, + BlockActor*, + Container*, + WorldPosType, + BlockPosType, + ItemType, + BlockType, + NbtType>; + + +static_assert( + sizeof(std::variant< + bool, + std ::string, + std ::nullptr_t, + NumberType, + Player*, + Actor*, + BlockActor*, + Container*, + WorldPosType, + BlockPosType, + ItemType, + BlockType, + NbtType>) + == 40 +); template constexpr bool is_vector_v = false; -template -constexpr bool is_vector_v> = true; +template +constexpr bool is_vector_v> = true; template constexpr bool is_map_v = false; -template -constexpr bool is_map_v> = true; -template -constexpr bool is_map_v> = true; -using Value = std::variant; -// struct Value -//{ -// std::variant value; -// Value(bool v) -// : value(v){}; -// Value(__int64 v) -// : value(v){}; -// Value(double v) -// : value(v){}; -// Value(std::string const& v) -// : value(v){}; -// Value(std::string* v) -// : value(v){}; -// Value(Player* v) -// : value(v){}; -// Value(Actor* v) -// : value(v){}; -// Value(ItemStack* v) -// : value(v){}; -// Value(Block* v) -// : value(v){}; -// Value(BlockActor* v) -// : value(v){}; -// Value(Container* v) -// : value(v){}; -// Value(Vec3* v) -// : value(v){}; -// Value(BlockPos* v) -// : value(v){}; -// Value(CompoundTag* v) -// : value(v){}; -// operator std::variant() -// { -// return value; -// } -// }; +template +constexpr bool is_map_v> = true; +template +constexpr bool is_map_v> = true; +using Value = std::variant< + bool, + std ::string, + std ::nullptr_t, + NumberType, + Player*, + Actor*, + BlockActor*, + Container*, + WorldPosType, + BlockPosType, + ItemType, + BlockType, + NbtType>; + struct ValueType { using ArrayType = std::vector; using ObjectType = std::unordered_map; using Type = std::variant; Type value; - ValueType() : value({}){}; - // ValueType(ValueType const& v) = delete; - // ValueType(Value const& v) = delete; - ValueType(Value&& v) : value(std::move(v)){}; - ValueType(Value v) : value(std::move(v)){}; - // ValueType(ValueType&& v) noexcept - // : value(std::move(v.value)){}; - ValueType(std::vector&& v) : value(std::move(v)){}; - ValueType(std::unordered_map&& v) : value(std::move(v)){}; + ValueType() = default; + ValueType(ValueType const&) = default; + ValueType(ValueType&&) = default; template - ValueType(T const& v) : value(Value(v)){}; + ValueType(T&& v) /*NOLINT*/ : value(std::forward(v)) {} }; -template +template static constexpr bool is_supported_type_v = - std::is_void_v<_Ty> || is_one_of_v<_Ty, ElementType> || std::is_assignable_v - || std::is_assignable_v || std::is_assignable_v || std::is_assignable_v - || std::is_assignable_v || std::is_assignable_v - || std::is_base_of_v> || std::is_base_of_v>; + std::is_void_v + || ll::traits::is_one_of_v< + Ty, + bool, + std ::string, + std ::nullptr_t, + NumberType, + Player*, + Actor*, + BlockActor*, + Container*, + WorldPosType, + BlockPosType, + ItemType, + BlockType, + NbtType> + || std::is_assignable_v || std::is_assignable_v || std::is_assignable_v + || std::is_assignable_v || std::is_assignable_v + || std::is_assignable_v || std::is_base_of_v> + || std::is_base_of_v>; template RTN extract(ValueType&& val); @@ -280,7 +363,22 @@ template RTN extractValue(Value&& value) { using Type = std::remove_const_t>; static_assert(is_supported_type_v, "Unsupported Type:"); - if constexpr (is_one_of_v) return std::get(value); + if constexpr (ll::traits::is_one_of_v< + Type, + bool, + std ::string, + std ::nullptr_t, + NumberType, + Player*, + Actor*, + BlockActor*, + Container*, + WorldPosType, + BlockPosType, + ItemType, + BlockType, + NbtType>) + return std::get(value); else if constexpr (std::is_assignable_v) return std::get(value).get(); else if constexpr (std::is_assignable_v) return std::get(value).get(); else if constexpr (std::is_assignable_v) return std::get(value).get(); @@ -328,7 +426,22 @@ template ValueType packValue(T val) { using RawType = std::remove_reference_t>; static_assert(is_supported_type_v, "Unsupported Type"); - if constexpr (is_one_of_v) return ValueType(std::forward(val)); + if constexpr (ll::traits::is_one_of_v< + RawType, + bool, + std ::string, + std ::nullptr_t, + NumberType, + Player*, + Actor*, + BlockActor*, + Container*, + WorldPosType, + BlockPosType, + ItemType, + BlockType, + NbtType>) + return ValueType(std::forward(val)); else if constexpr (std::is_assignable_v) return ValueType(NumberType{std::forward(val)}); else if constexpr (std::is_assignable_v) return ValueType(NbtType(std::forward(val))); else if constexpr (std::is_assignable_v) return ValueType(ItemType(std::forward(val))); @@ -369,22 +482,6 @@ ValueType pack(T val) { } else return packValue(std::forward(val)); } -#else - -// Use string as value type because it is easy to convert between script types and native types -using ValueType = std::string; // Json string - -template -std::remove_reference_t extract(ValueType const& val) { - return nlohmann::json::parse(val).get>(); -} - -template -ValueType pack(T const& val) { - return nlohmann::json(val).dump(); -} - -#endif // TEST_NEW_VALUE_TYPE using CallbackFn = std::function)>; @@ -392,15 +489,14 @@ struct ExportedFuncData { void* handle; CallbackFn callback; }; - -__declspec(dllexport) extern CallbackFn const EMPTY_FUNC; -__declspec(dllexport) bool exportFunc( - std::string const& nameSpace, - std::string const& funcName, - CallbackFn&& callback, - void* handle = ll::sys_utils::getCurrentModuleHandle() -); -__declspec(dllexport) CallbackFn const& importFunc(std::string const& nameSpace, std::string const& funcName); +REMOTE_CALL_API extern CallbackFn const EMPTY_FUNC; +REMOTE_CALL_API bool exportFunc( + std::string const& nameSpace, + std::string const& funcName, + CallbackFn&& callback, + void* handle = ll::sys_utils::getCurrentModuleHandle() + ); +REMOTE_CALL_API CallbackFn const& importFunc(std::string const& nameSpace, std::string const& funcName); inline ValueType _expandArg(std::vector& args, int& index) { return std::move(args[--index]); } @@ -408,11 +504,11 @@ template inline bool _exportAs(std::string const& nameSpace, std::string const& funcName, std::function&& callback) { CallbackFn cb = [callback = std::move(callback)](std::vector args) -> ValueType { - if (sizeof...(Args) != args.size()) return std::move(ValueType()); + if (sizeof...(Args) != args.size()) return {}; int index = sizeof...(Args); if constexpr (std::is_void_v) { callback(extract(_expandArg(args, index))...); - return std::move(ValueType()); + return {}; } else { return pack(callback(extract(_expandArg(args, index))...)); } @@ -420,11 +516,11 @@ _exportAs(std::string const& nameSpace, std::string const& funcName, std::functi return exportFunc(nameSpace, funcName, std::move(cb), ll::sys_utils::getCurrentModuleHandle()); } -__declspec(dllexport) bool hasFunc(std::string const& nameSpace, std::string const& funcName); -__declspec(dllexport) bool removeFunc(std::string const& nameSpace, std::string const& funcName); -__declspec(dllexport) int removeNameSpace(std::string const& nameSpace); -__declspec(dllexport) int removeFuncs(std::vector>& funcs); -__declspec(dllexport) void _onCallError(std::string const& msg, void* handle = ll::sys_utils::getCurrentModuleHandle()); +REMOTE_CALL_API bool hasFunc(std::string const& nameSpace, std::string const& funcName); +REMOTE_CALL_API bool removeFunc(std::string const& nameSpace, std::string const& funcName); +REMOTE_CALL_API int removeNameSpace(std::string const& nameSpace); +REMOTE_CALL_API int removeFuncs(std::vector>& funcs); +REMOTE_CALL_API void _onCallError(std::string const& msg, void* handle = ll::sys_utils::getCurrentModuleHandle()); template inline bool _importAs(std::string const& nameSpace, std::string const& funcName, std::function& func) { @@ -450,7 +546,7 @@ inline Func importAs(std::string const& nameSpace, std::string const& funcName) template inline bool exportAs(std::string const& nameSpace, std::string const& funcName, CB&& callback) { - return _exportAs(nameSpace, funcName, std::function(std::move(callback))); + return _exportAs(nameSpace, funcName, std::function(std::forward(callback))); } } // namespace RemoteCall diff --git a/xmake.lua b/xmake.lua index 0b734be..1556935 100644 --- a/xmake.lua +++ b/xmake.lua @@ -30,7 +30,7 @@ target("LegacyRemoteCall") add_rules("@levibuildscript/linkrule") add_rules("@levibuildscript/modpacker") add_cxflags( "/EHa", "/utf-8", "/W4", "/w44265", "/w44289", "/w44296", "/w45263", "/w44738", "/w45204") - add_defines("NOMINMAX", "UNICODE") + add_defines("NOMINMAX", "UNICODE", "REMOTE_CALL_EXPORT") add_packages("levilamina") set_exceptions("none") set_kind("shared")