Merge pull request #1238 from dsnopek/variant-call-callp
Fix variant call compiler error (alternate)pull/1155/head
commit
4314f91b7d
|
@ -255,25 +255,33 @@ public:
|
||||||
bool operator!=(const Variant &other) const;
|
bool operator!=(const Variant &other) const;
|
||||||
bool operator<(const Variant &other) const;
|
bool operator<(const Variant &other) const;
|
||||||
|
|
||||||
void call(const StringName &method, const Variant **args, int argcount, Variant &r_ret, GDExtensionCallError &r_error);
|
void callp(const StringName &method, const Variant **args, int argcount, Variant &r_ret, GDExtensionCallError &r_error);
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
Variant call(const StringName &method, Args... args) {
|
Variant call(const StringName &method, Args... args) {
|
||||||
|
std::array<Variant, sizeof...(args)> vargs = { args... };
|
||||||
|
std::array<const Variant *, sizeof...(args)> argptrs;
|
||||||
|
for (size_t i = 0; i < vargs.size(); i++) {
|
||||||
|
argptrs[i] = &vargs[i];
|
||||||
|
}
|
||||||
Variant result;
|
Variant result;
|
||||||
GDExtensionCallError error;
|
GDExtensionCallError error;
|
||||||
std::array<GDExtensionConstVariantPtr, sizeof...(Args)> call_args = { Variant(args)... };
|
callp(method, argptrs.data(), argptrs.size(), result, error);
|
||||||
call(method, call_args.data(), call_args.size(), result, error);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void call_static(Variant::Type type, const StringName &method, const Variant **args, int argcount, Variant &r_ret, GDExtensionCallError &r_error);
|
static void callp_static(Variant::Type type, const StringName &method, const Variant **args, int argcount, Variant &r_ret, GDExtensionCallError &r_error);
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
static Variant call_static(Variant::Type type, const StringName &method, Args... args) {
|
static Variant call_static(Variant::Type type, const StringName &method, Args... args) {
|
||||||
|
std::array<Variant, sizeof...(args)> vargs = { args... };
|
||||||
|
std::array<const Variant *, sizeof...(args)> argptrs;
|
||||||
|
for (size_t i = 0; i < vargs.size(); i++) {
|
||||||
|
argptrs[i] = &vargs[i];
|
||||||
|
}
|
||||||
Variant result;
|
Variant result;
|
||||||
GDExtensionCallError error;
|
GDExtensionCallError error;
|
||||||
std::array<GDExtensionConstVariantPtr, sizeof...(Args)> call_args = { Variant(args)... };
|
callp_static(type, method, argptrs.data(), argptrs.size(), sizeof...(args), result, error);
|
||||||
call_static(type, method, call_args.data(), call_args.size(), result, error);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -549,11 +549,11 @@ bool Variant::operator<(const Variant &other) const {
|
||||||
return result.operator bool();
|
return result.operator bool();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Variant::call(const StringName &method, const Variant **args, int argcount, Variant &r_ret, GDExtensionCallError &r_error) {
|
void Variant::callp(const StringName &method, const Variant **args, int argcount, Variant &r_ret, GDExtensionCallError &r_error) {
|
||||||
internal::gdextension_interface_variant_call(_native_ptr(), method._native_ptr(), reinterpret_cast<GDExtensionConstVariantPtr *>(args), argcount, r_ret._native_ptr(), &r_error);
|
internal::gdextension_interface_variant_call(_native_ptr(), method._native_ptr(), reinterpret_cast<GDExtensionConstVariantPtr *>(args), argcount, r_ret._native_ptr(), &r_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Variant::call_static(Variant::Type type, const StringName &method, const Variant **args, int argcount, Variant &r_ret, GDExtensionCallError &r_error) {
|
void Variant::callp_static(Variant::Type type, const StringName &method, const Variant **args, int argcount, Variant &r_ret, GDExtensionCallError &r_error) {
|
||||||
internal::gdextension_interface_variant_call_static(static_cast<GDExtensionVariantType>(type), method._native_ptr(), reinterpret_cast<GDExtensionConstVariantPtr *>(args), argcount, r_ret._native_ptr(), &r_error);
|
internal::gdextension_interface_variant_call_static(static_cast<GDExtensionVariantType>(type), method._native_ptr(), reinterpret_cast<GDExtensionConstVariantPtr *>(args), argcount, r_ret._native_ptr(), &r_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,9 @@ extends "res://test_base.gd"
|
||||||
|
|
||||||
var custom_signal_emitted = null
|
var custom_signal_emitted = null
|
||||||
|
|
||||||
|
class TestClass:
|
||||||
|
func test(p_msg: String) -> String:
|
||||||
|
return p_msg + " world"
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
var example: Example = $Example
|
var example: Example = $Example
|
||||||
|
@ -144,6 +147,10 @@ func _ready():
|
||||||
assert_equal(new_tilemap.tile_set, new_tileset)
|
assert_equal(new_tilemap.tile_set, new_tileset)
|
||||||
new_tilemap.queue_free()
|
new_tilemap.queue_free()
|
||||||
|
|
||||||
|
# Test variant call.
|
||||||
|
var test_obj = TestClass.new()
|
||||||
|
assert_equal(example.test_variant_call(test_obj), "hello world")
|
||||||
|
|
||||||
# Constants.
|
# Constants.
|
||||||
assert_equal(Example.FIRST, 0)
|
assert_equal(Example.FIRST, 0)
|
||||||
assert_equal(Example.ANSWER_TO_EVERYTHING, 42)
|
assert_equal(Example.ANSWER_TO_EVERYTHING, 42)
|
||||||
|
|
|
@ -161,6 +161,8 @@ void Example::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("test_add_child", "node"), &Example::test_add_child);
|
ClassDB::bind_method(D_METHOD("test_add_child", "node"), &Example::test_add_child);
|
||||||
ClassDB::bind_method(D_METHOD("test_set_tileset", "tilemap", "tileset"), &Example::test_set_tileset);
|
ClassDB::bind_method(D_METHOD("test_set_tileset", "tilemap", "tileset"), &Example::test_set_tileset);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("test_variant_call", "variant"), &Example::test_variant_call);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("test_bitfield", "flags"), &Example::test_bitfield);
|
ClassDB::bind_method(D_METHOD("test_bitfield", "flags"), &Example::test_bitfield);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("test_rpc", "value"), &Example::test_rpc);
|
ClassDB::bind_method(D_METHOD("test_rpc", "value"), &Example::test_rpc);
|
||||||
|
@ -410,6 +412,10 @@ void Example::test_set_tileset(TileMap *p_tilemap, const Ref<TileSet> &p_tileset
|
||||||
p_tilemap->set_tileset(p_tileset);
|
p_tilemap->set_tileset(p_tileset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Variant Example::test_variant_call(Variant p_variant) {
|
||||||
|
return p_variant.call("test", "hello");
|
||||||
|
}
|
||||||
|
|
||||||
BitField<Example::Flags> Example::test_bitfield(BitField<Flags> flags) {
|
BitField<Example::Flags> Example::test_bitfield(BitField<Flags> flags) {
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <godot_cpp/classes/tile_map.hpp>
|
#include <godot_cpp/classes/tile_map.hpp>
|
||||||
#include <godot_cpp/classes/tile_set.hpp>
|
#include <godot_cpp/classes/tile_set.hpp>
|
||||||
#include <godot_cpp/classes/viewport.hpp>
|
#include <godot_cpp/classes/viewport.hpp>
|
||||||
|
#include <godot_cpp/variant/variant.hpp>
|
||||||
|
|
||||||
#include <godot_cpp/core/binder_common.hpp>
|
#include <godot_cpp/core/binder_common.hpp>
|
||||||
|
|
||||||
|
@ -135,6 +136,8 @@ public:
|
||||||
void test_add_child(Node *p_node);
|
void test_add_child(Node *p_node);
|
||||||
void test_set_tileset(TileMap *p_tilemap, const Ref<TileSet> &p_tileset) const;
|
void test_set_tileset(TileMap *p_tilemap, const Ref<TileSet> &p_tileset) const;
|
||||||
|
|
||||||
|
Variant test_variant_call(Variant p_variant);
|
||||||
|
|
||||||
BitField<Flags> test_bitfield(BitField<Flags> flags);
|
BitField<Flags> test_bitfield(BitField<Flags> flags);
|
||||||
|
|
||||||
// RPC
|
// RPC
|
||||||
|
|
Loading…
Reference in New Issue