2023-01-10 15:14:30 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* engine_ptrcall.hpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/**************************************************************************/
|
2021-08-18 14:03:52 +00:00
|
|
|
|
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
|
|
|
|
2022-12-13 23:40:17 +00:00
|
|
|
#include <gdextension_interface.h>
|
2021-08-18 14:03:52 +00:00
|
|
|
|
|
|
|
#include <godot_cpp/core/binder_common.hpp>
|
|
|
|
#include <godot_cpp/core/object.hpp>
|
|
|
|
#include <godot_cpp/godot.hpp>
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
|
|
|
namespace godot {
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename O, typename... Args>
|
2022-12-07 13:11:44 +00:00
|
|
|
O *_call_native_mb_ret_obj(const GDExtensionMethodBindPtr mb, void *instance, const Args &...args) {
|
2021-08-18 14:03:52 +00:00
|
|
|
GodotObject *ret = nullptr;
|
2022-12-07 13:11:44 +00:00
|
|
|
std::array<GDExtensionConstTypePtr, sizeof...(Args)> mb_args = { { (GDExtensionConstTypePtr)args... } };
|
2023-04-24 16:45:45 +00:00
|
|
|
internal::gdextension_interface_object_method_bind_ptrcall(mb, instance, mb_args.data(), &ret);
|
2022-02-01 01:12:45 +00:00
|
|
|
if (ret == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2023-02-17 16:49:09 +00:00
|
|
|
return reinterpret_cast<O *>(internal::get_object_instance_binding(ret));
|
2021-08-18 14:03:52 +00:00
|
|
|
}
|
|
|
|
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename R, typename... Args>
|
2022-12-07 13:11:44 +00:00
|
|
|
R _call_native_mb_ret(const GDExtensionMethodBindPtr mb, void *instance, const Args &...args) {
|
2021-08-18 14:03:52 +00:00
|
|
|
R ret;
|
2022-12-07 13:11:44 +00:00
|
|
|
std::array<GDExtensionConstTypePtr, sizeof...(Args)> mb_args = { { (GDExtensionConstTypePtr)args... } };
|
2023-04-24 16:45:45 +00:00
|
|
|
internal::gdextension_interface_object_method_bind_ptrcall(mb, instance, mb_args.data(), &ret);
|
2021-08-18 14:03:52 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename... Args>
|
2022-12-07 13:11:44 +00:00
|
|
|
void _call_native_mb_no_ret(const GDExtensionMethodBindPtr mb, void *instance, const Args &...args) {
|
|
|
|
std::array<GDExtensionConstTypePtr, sizeof...(Args)> mb_args = { { (GDExtensionConstTypePtr)args... } };
|
2023-04-24 16:45:45 +00:00
|
|
|
internal::gdextension_interface_object_method_bind_ptrcall(mb, instance, mb_args.data(), nullptr);
|
2021-08-18 14:03:52 +00:00
|
|
|
}
|
|
|
|
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename R, typename... Args>
|
2022-12-07 13:11:44 +00:00
|
|
|
R _call_utility_ret(GDExtensionPtrUtilityFunction func, const Args &...args) {
|
2021-08-18 14:03:52 +00:00
|
|
|
R ret;
|
2022-12-07 13:11:44 +00:00
|
|
|
std::array<GDExtensionConstTypePtr, sizeof...(Args)> mb_args = { { (GDExtensionConstTypePtr)args... } };
|
2021-08-18 14:03:52 +00:00
|
|
|
func(&ret, mb_args.data(), mb_args.size());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename... Args>
|
2024-03-27 12:19:54 +00:00
|
|
|
Object *_call_utility_ret_obj(const GDExtensionPtrUtilityFunction func, const Args &...args) {
|
2021-08-18 14:03:52 +00:00
|
|
|
GodotObject *ret = nullptr;
|
2022-12-07 13:11:44 +00:00
|
|
|
std::array<GDExtensionConstTypePtr, sizeof...(Args)> mb_args = { { (GDExtensionConstTypePtr)args... } };
|
2021-08-18 14:03:52 +00:00
|
|
|
func(&ret, mb_args.data(), mb_args.size());
|
2023-02-17 16:49:09 +00:00
|
|
|
return (Object *)internal::get_object_instance_binding(ret);
|
2021-08-18 14:03:52 +00:00
|
|
|
}
|
|
|
|
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename... Args>
|
2022-12-07 13:11:44 +00:00
|
|
|
void _call_utility_no_ret(const GDExtensionPtrUtilityFunction func, const Args &...args) {
|
|
|
|
std::array<GDExtensionConstTypePtr, sizeof...(Args)> mb_args = { { (GDExtensionConstTypePtr)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
|