/* * Tencent is pleased to support the open source community by making Puerts available. * Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. * Puerts is licensed under the BSD 3-Clause License, except for the third-party components listed in the file 'LICENSE' which may * be subject to their corresponding license terms. This file is subject to the terms and conditions defined in file 'LICENSE', * which is part of this source code package. */ #pragma once #if defined(BUILDING_PES_EXTENSION) #include "PesapiBackend.hpp" #endif #if !defined(BUILDING_PES_EXTENSION) || defined(PES_EXTENSION_WITH_V8_API) #include "V8Backend.hpp" #endif #include "Object.hpp" #ifndef PUERTS_BINDING_IMPL #if defined(BUILDING_PES_EXTENSION) && !defined(PES_EXTENSION_WITH_V8_API) #define PUERTS_BINDING_IMPL pesapi_impl #else #define PUERTS_BINDING_IMPL v8_impl #endif #endif #define MakeConstructor(T, ...) \ ::PUERTS_NAMESPACE::template ConstructorWrapper #define MakeGetter(M) &(::PUERTS_NAMESPACE::PropertyWrapper::getter) #define MakeSetter(M) &(::PUERTS_NAMESPACE::PropertyWrapper::setter) #define MakeProperty(M) \ &(::PUERTS_NAMESPACE::PropertyWrapper::getter), \ &(::PUERTS_NAMESPACE::PropertyWrapper::setter), \ ::PUERTS_NAMESPACE::PropertyWrapper::info() #define MakeReadonlyProperty(M) \ &(::PUERTS_NAMESPACE::PropertyWrapper::getter), nullptr, \ ::PUERTS_NAMESPACE::PropertyWrapper::info() #define MakeVariable(M) MakeProperty(M) #define MakeReadonlyVariable(M) MakeReadonlyProperty(M) #define MakeFunction(M, ...) \ [](::PUERTS_NAMESPACE::PUERTS_BINDING_IMPL::API::CallbackInfoType info) \ { \ ::PUERTS_NAMESPACE::FuncCallWrapper::callWithDefaultValues( \ info, ##__VA_ARGS__); \ }, \ ::PUERTS_NAMESPACE::FuncCallWrapper::info( \ PUERTS_NAMESPACE::Count(__VA_ARGS__)) #define MakeExtension(M, ...) \ [](::PUERTS_NAMESPACE::PUERTS_BINDING_IMPL::API::CallbackInfoType info) \ { \ ::PUERTS_NAMESPACE::FuncCallWrapper::callExtensionWithDefaultValues(info, ##__VA_ARGS__); \ }, \ ::PUERTS_NAMESPACE::FuncCallWrapper::extensionInfo( \ PUERTS_NAMESPACE::Count(__VA_ARGS__)) #define SelectFunction(SIGNATURE, M, ...) \ [](::PUERTS_NAMESPACE::PUERTS_BINDING_IMPL::API::CallbackInfoType info) \ { \ ::PUERTS_NAMESPACE::FuncCallWrapper::callWithDefaultValues( \ info, ##__VA_ARGS__); \ }, \ ::PUERTS_NAMESPACE::FuncCallWrapper::info( \ PUERTS_NAMESPACE::Count(__VA_ARGS__)) #define SelectFunction_PtrRet(SIGNATURE, M, ...) \ [](::PUERTS_NAMESPACE::PUERTS_BINDING_IMPL::API::CallbackInfoType info) \ { \ ::PUERTS_NAMESPACE::FuncCallWrapper::callWithDefaultValues(info, ##__VA_ARGS__); \ }, \ ::PUERTS_NAMESPACE::FuncCallWrapper::info( \ PUERTS_NAMESPACE::Count(__VA_ARGS__)) #define MakeCheckFunction(M) \ &(::PUERTS_NAMESPACE::FuncCallWrapper::checkedCall), \ ::PUERTS_NAMESPACE::FuncCallWrapper::info() #define MakeOverload(SIGNATURE, M) PUERTS_NAMESPACE::FuncCallWrapper #define CombineOverloads(...) \ &::PUERTS_NAMESPACE::OverloadsCombiner::call, \ ::PUERTS_NAMESPACE::OverloadsCombiner::length, \ ::PUERTS_NAMESPACE::OverloadsCombiner::infos() #define CombineConstructors(...) \ &::PUERTS_NAMESPACE::ConstructorsCombiner::call, \ ::PUERTS_NAMESPACE::ConstructorsCombiner::length, \ ::PUERTS_NAMESPACE::ConstructorsCombiner::infos() #define DeclOverloads(Name) \ template \ struct Name##PuertsOverloads \ { \ }; #define DeclOverload(Name, SIGNATURE, M, ...) \ template <> \ struct Name##PuertsOverloads \ { \ static bool overloadCall(::PUERTS_NAMESPACE::PUERTS_BINDING_IMPL::API::CallbackInfoType info) \ { \ return ::PUERTS_NAMESPACE::FuncCallWrapper::overloadCallWithDefaultValues(info, ##__VA_ARGS__); \ } \ static const ::PUERTS_NAMESPACE::CFunctionInfo* info() \ { \ return ::PUERTS_NAMESPACE::FuncCallWrapper::info( \ PUERTS_NAMESPACE::Count(__VA_ARGS__)); \ } \ }; #define SelectOverload(Name, SIGNATURE) Name##PuertsOverloads #define __DefObjectType_HELPER1(CLS, Suffix) __DefObjectType_##Suffix(CLS) #define __DefObjectType_HELPER2(CLS, Suffix) __DefObjectType_HELPER1(CLS, Suffix) #define __DefCDataPointerConverter_HELPER1(CLS, Suffix) __DefCDataPointerConverter_##Suffix(CLS) #define __DefCDataPointerConverter_HELPER2(CLS, Suffix) __DefCDataPointerConverter_HELPER1(CLS, Suffix) #define __DefObjectType(CLS) __DefObjectType_HELPER2(CLS, PUERTS_BINDING_IMPL) #define __DefCDataPointerConverter(CLS) __DefCDataPointerConverter_HELPER2(CLS, PUERTS_BINDING_IMPL) #define UsingNamedCppType(CLS, NAME) __DefScriptTTypeName(NAME, CLS) __DefObjectType(CLS) __DefCDataPointerConverter(CLS) #define UsingCppType(CLS) UsingNamedCppType(CLS, CLS) #if defined(BUILDING_PES_EXTENSION) && !defined(PES_EXTENSION_WITH_V8_API) #define UsingOtherModuleCppType(MODULE, CLS) \ namespace PUERTS_NAMESPACE \ { \ template <> \ struct StaticTypeId \ { \ static const void* get() \ { \ static void* cache_type_id = nullptr; \ if (!cache_type_id) \ { \ cache_type_id = (void*) pesapi_find_type_id(#MODULE, #CLS); \ } \ return cache_type_id; \ } \ }; \ } \ UsingNamedCppType(CLS, CLS) #endif namespace PUERTS_NAMESPACE { template class ClassDefineBuilder; #if defined(BUILDING_PES_EXTENSION) template ClassDefineBuilder DefineClass() { static auto NameLiteral = ScriptTypeName::value(); return ClassDefineBuilder(NameLiteral.Data()); } #else template ClassDefineBuilder DefineClass() { static auto NameLiteral = ScriptTypeName::value(); return ClassDefineBuilder(NameLiteral.Data()); } #endif using Object = PUERTS_BINDING_IMPL::Object; using Function = PUERTS_BINDING_IMPL::Function; inline void ThrowException(const char* msg) { internal::ExceptionHandle::Throw(msg); } } // namespace PUERTS_NAMESPACE