/* * Tencent is pleased to support the open source community by making ScriptX available. * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include "Engine.h" #include "Exception.h" #include "Reference.h" #include SCRIPTX_BACKEND(Engine.h) #include SCRIPTX_BACKEND(Includes.h) namespace script { template void ScriptEngine::registerNativeClass(const ClassDefine& classDefine) { if ((std::is_same_v && staticClassDefineRegistry_.find(&classDefine) != staticClassDefineRegistry_.end()) || classDefineRegistry_.find(internal::typeIndexOf()) != classDefineRegistry_.end()) { throw Exception(std::string("already registered for " + classDefine.getClassName())); } using RealEngine = typename internal::ImplType::type; internal::scriptDynamicCast(this)->registerNativeClassImpl(&classDefine); if (std::is_same_v) { staticClassDefineRegistry_.emplace(&classDefine); } else { classDefineRegistry_.emplace(internal::typeIndexOf(), &classDefine); } } template const ClassDefine& ScriptEngine::getClassDefine() const { static_assert(!std::is_same_v); auto it = classDefineRegistry_.find(internal::typeIndexOf()); if (it == classDefineRegistry_.end()) { throw Exception(std::string("ClassDefine is not registered")); } return *static_cast*>(it->second); } template Local ScriptEngine::newNativeClassImpl(const ClassDefine& classDefine, size_t size, const Local* args) { static_assert(!std::is_same_v); using RealEngine = typename internal::ImplType::type; return internal::scriptDynamicCast(this)->newNativeClassImpl(&classDefine, size, args); } template bool ScriptEngine::isInstanceOfImpl(const Local& value, const ClassDefine& classDefine) { static_assert(!std::is_same_v); using RealEngine = typename internal::ImplType::type; return internal::scriptDynamicCast(this)->isInstanceOfImpl(value, &classDefine); } template T* ScriptEngine::getNativeInstanceImpl(const Local& value, const ClassDefine& classDefine) { static_assert(!std::is_same_v); using RealEngine = typename internal::ImplType::type; return internal::scriptDynamicCast(this)->getNativeInstanceImpl(value, &classDefine); } template inline std::shared_ptr ScriptEngine::getData() { return std::static_pointer_cast(userData_); } } // namespace script