2021-08-18 14:03:52 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* engine_ptrcall.hpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2022-03-15 09:17:53 +00:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2021-08-18 14:03:52 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2022-10-09 06:47:07 +00:00
|
|
|
#ifndef GODOT_ENGINE_PTRCALL_HPP
|
|
|
|
#define GODOT_ENGINE_PTRCALL_HPP
|
2021-08-18 14:03:52 +00:00
|
|
|
|
|
|
|
#include <godot/gdnative_interface.h>
|
|
|
|
|
|
|
|
#include <godot_cpp/core/binder_common.hpp>
|
|
|
|
#include <godot_cpp/core/object.hpp>
|
|
|
|
#include <godot_cpp/godot.hpp>
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
|
|
|
namespace godot {
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
template <class O, class... Args>
|
2021-09-08 18:07:23 +00:00
|
|
|
O *_call_native_mb_ret_obj(const GDNativeMethodBindPtr mb, void *instance, const Args &...args) {
|
2021-08-18 14:03:52 +00:00
|
|
|
GodotObject *ret = nullptr;
|
2022-11-12 23:37:55 +00:00
|
|
|
std::array<GDNativeConstTypePtr, sizeof...(Args)> mb_args = { { (GDNativeConstTypePtr)args... } };
|
2021-10-28 08:20:56 +00:00
|
|
|
internal::gdn_interface->object_method_bind_ptrcall(mb, instance, mb_args.data(), &ret);
|
2022-02-01 01:12:45 +00:00
|
|
|
if (ret == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2021-10-28 08:20:56 +00:00
|
|
|
return reinterpret_cast<O *>(internal::gdn_interface->object_get_instance_binding(ret, internal::token, &O::___binding_callbacks));
|
2021-08-18 14:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class R, class... Args>
|
|
|
|
R _call_native_mb_ret(const GDNativeMethodBindPtr mb, void *instance, const Args &...args) {
|
|
|
|
R ret;
|
2022-11-12 23:37:55 +00:00
|
|
|
std::array<GDNativeConstTypePtr, sizeof...(Args)> mb_args = { { (GDNativeConstTypePtr)args... } };
|
2021-10-28 08:20:56 +00:00
|
|
|
internal::gdn_interface->object_method_bind_ptrcall(mb, instance, mb_args.data(), &ret);
|
2021-08-18 14:03:52 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Args>
|
|
|
|
void _call_native_mb_no_ret(const GDNativeMethodBindPtr mb, void *instance, const Args &...args) {
|
2022-11-12 23:37:55 +00:00
|
|
|
std::array<GDNativeConstTypePtr, sizeof...(Args)> mb_args = { { (GDNativeConstTypePtr)args... } };
|
2021-10-28 08:20:56 +00:00
|
|
|
internal::gdn_interface->object_method_bind_ptrcall(mb, instance, mb_args.data(), nullptr);
|
2021-08-18 14:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class R, class... Args>
|
|
|
|
R _call_utility_ret(GDNativePtrUtilityFunction func, const Args &...args) {
|
|
|
|
R ret;
|
2022-11-12 23:37:55 +00:00
|
|
|
std::array<GDNativeConstTypePtr, sizeof...(Args)> mb_args = { { (GDNativeConstTypePtr)args... } };
|
2021-08-18 14:03:52 +00:00
|
|
|
func(&ret, mb_args.data(), mb_args.size());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Args>
|
|
|
|
Object *_call_utility_ret_obj(const GDNativePtrUtilityFunction func, void *instance, const Args &...args) {
|
|
|
|
GodotObject *ret = nullptr;
|
2022-11-12 23:37:55 +00:00
|
|
|
std::array<GDNativeConstTypePtr, sizeof...(Args)> mb_args = { { (GDNativeConstTypePtr)args... } };
|
2021-08-18 14:03:52 +00:00
|
|
|
func(&ret, mb_args.data(), mb_args.size());
|
2021-10-28 08:20:56 +00:00
|
|
|
return (Object *)internal::gdn_interface->object_get_instance_binding(ret, internal::token, &Object::___binding_callbacks);
|
2021-08-18 14:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Args>
|
|
|
|
void _call_utility_no_ret(const GDNativePtrUtilityFunction func, const Args &...args) {
|
2022-11-12 23:37:55 +00:00
|
|
|
std::array<GDNativeConstTypePtr, sizeof...(Args)> mb_args = { { (GDNativeConstTypePtr)args... } };
|
2021-08-18 14:03:52 +00:00
|
|
|
func(nullptr, mb_args.data(), mb_args.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
} // namespace godot
|
|
|
|
|
2022-10-09 06:47:07 +00:00
|
|
|
#endif // GODOT_ENGINE_PTRCALL_HPP
|