Как мне связать пользовательские операторы в Godot-cpp (4.4), например тот, который показан в примере Toy MyClass?
Пример настроен так, чтобы имитировать руководство, как показано в официальной документации GDExtension C++, пример
// MyClass.hpp
#pragma once
#include
namespace godot {
class MyClass : public RefCounted
{
GDCLASS(MyClass, RefCounted)
public:
float get_stuff() const;
void set_stuff(float stuff);
bool operator==(float const& other) const;
protected:
static void _bind_methods();
private:
float stuff_;
};
}
// MyClass.cpp
#include
namespace godot {
float MyClass::get_stuff() const {
return stuff_;
}
void MyClass::set_stuff(float const& stuff) {
stuff_ = stuff;
}
bool MyClass::operator==(MyClass const& other) {
return stuff_ == other.stuff_;
}
void MyClass::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_stuff"), &MyClass::get_stuff);
ClassDB::bind_method(D_METHOD("set_stuff", "stuff"), &MyClass::set_stuff);
// Bind operator here.
}
}
Как может выглядеть пример программы GDScript:
func foo(a: MyClass, b: MyClass) -> bool:
return a == b
Подробнее здесь: https://stackoverflow.com/questions/797 ... -operators