Path: blob/master/modules/mono/mono_gd/gd_mono_cache.cpp
10278 views
/**************************************************************************/1/* gd_mono_cache.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "gd_mono_cache.h"3132#include "core/error/error_macros.h"3334namespace GDMonoCache {3536ManagedCallbacks managed_callbacks;37bool godot_api_cache_updated = false;3839void update_godot_api_cache(const ManagedCallbacks &p_managed_callbacks) {40int checked_count = 0;4142#define CHECK_CALLBACK_NOT_NULL_IMPL(m_var, m_class, m_method) \43{ \44ERR_FAIL_NULL_MSG(m_var, \45"Mono Cache: Managed callback for '" #m_class "_" #m_method "' is null."); \46checked_count += 1; \47}4849#define CHECK_CALLBACK_NOT_NULL(m_class, m_method) CHECK_CALLBACK_NOT_NULL_IMPL(p_managed_callbacks.m_class##_##m_method, m_class, m_method)5051CHECK_CALLBACK_NOT_NULL(SignalAwaiter, SignalCallback);52CHECK_CALLBACK_NOT_NULL(DelegateUtils, InvokeWithVariantArgs);53CHECK_CALLBACK_NOT_NULL(DelegateUtils, DelegateEquals);54CHECK_CALLBACK_NOT_NULL(DelegateUtils, DelegateHash);55CHECK_CALLBACK_NOT_NULL(DelegateUtils, GetArgumentCount);56CHECK_CALLBACK_NOT_NULL(DelegateUtils, TrySerializeDelegateWithGCHandle);57CHECK_CALLBACK_NOT_NULL(DelegateUtils, TryDeserializeDelegateWithGCHandle);58CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, FrameCallback);59CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, CreateManagedForGodotObjectBinding);60CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, CreateManagedForGodotObjectScriptInstance);61CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, GetScriptNativeName);62CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, GetGlobalClassName);63CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, SetGodotObjectPtr);64CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, RaiseEventSignal);65CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, ScriptIsOrInherits);66CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, AddScriptBridge);67CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, GetOrCreateScriptBridgeForPath);68CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, RemoveScriptBridge);69CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, TryReloadRegisteredScriptWithClass);70CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, UpdateScriptClassInfo);71CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, SwapGCHandleForType);72CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, GetPropertyInfoList);73CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, GetPropertyDefaultValues);74CHECK_CALLBACK_NOT_NULL(ScriptManagerBridge, CallStatic);75CHECK_CALLBACK_NOT_NULL(CSharpInstanceBridge, Call);76CHECK_CALLBACK_NOT_NULL(CSharpInstanceBridge, Set);77CHECK_CALLBACK_NOT_NULL(CSharpInstanceBridge, Get);78CHECK_CALLBACK_NOT_NULL(CSharpInstanceBridge, CallDispose);79CHECK_CALLBACK_NOT_NULL(CSharpInstanceBridge, CallToString);80CHECK_CALLBACK_NOT_NULL(CSharpInstanceBridge, HasMethodUnknownParams);81CHECK_CALLBACK_NOT_NULL(CSharpInstanceBridge, SerializeState);82CHECK_CALLBACK_NOT_NULL(CSharpInstanceBridge, DeserializeState);83CHECK_CALLBACK_NOT_NULL(GCHandleBridge, FreeGCHandle);84CHECK_CALLBACK_NOT_NULL(GCHandleBridge, GCHandleIsTargetCollectible);85CHECK_CALLBACK_NOT_NULL(DebuggingUtils, GetCurrentStackInfo);86CHECK_CALLBACK_NOT_NULL(DisposablesTracker, OnGodotShuttingDown);87CHECK_CALLBACK_NOT_NULL(GD, OnCoreApiAssemblyLoaded);8889managed_callbacks = p_managed_callbacks;9091// It's easy to forget to add new callbacks here, so this should help92if (checked_count * sizeof(void *) != sizeof(ManagedCallbacks)) {93int missing_count = (sizeof(ManagedCallbacks) / sizeof(void *)) - checked_count;94WARN_PRINT("The presence of " + itos(missing_count) + " callback(s) was not validated");95}9697godot_api_cache_updated = true;98}99} // namespace GDMonoCache100101102