Added more methods to StringName's glue. Also removed operator == and != from StringName. It seems like c# does not like when an operator like that calls into native code.

This commit is contained in:
Relintai 2023-06-02 01:13:15 +02:00
parent 55b3cebac3
commit 1a9a5d522c
3 changed files with 21 additions and 15 deletions

View File

@ -70,6 +70,11 @@ namespace Godot
ptr = godot_icall_StringName_String_Ctor(path);
}
public StringName(StringName other)
{
ptr = godot_icall_StringName_StringName_Ctor(StringName.GetPtr(other));
}
public static implicit operator StringName(string from)
{
return new StringName(from);
@ -86,17 +91,7 @@ namespace Godot
/// <returns>A string representation of this <see cref="StringName"/>.</returns>
public override string ToString()
{
return (string)this;
}
public static bool operator ==(StringName left, StringName right)
{
return godot_icall_StringName_operator_Equals(StringName.GetPtr(left), StringName.GetPtr(right));
}
public static bool operator !=(StringName left, StringName right)
{
return !left.Equals(right);
return godot_icall_StringName_operator_String(StringName.GetPtr(this));
}
public override bool Equals(object obj)
@ -125,6 +120,9 @@ namespace Godot
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern IntPtr godot_icall_StringName_String_Ctor(string path);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern IntPtr godot_icall_StringName_StringName_Ctor(IntPtr ptr);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void godot_icall_StringName_Dtor(IntPtr ptr);

View File

@ -42,22 +42,28 @@ StringName *godot_icall_StringName_String_Ctor(MonoString *p_path) {
return memnew(StringName(GDMonoMarshal::mono_string_to_godot(p_path)));
}
StringName *godot_icall_StringName_StringName_Ctor(StringName *p_path) {
return memnew(StringName(*p_path));
}
void godot_icall_StringName_Dtor(StringName *p_ptr) {
ERR_FAIL_NULL(p_ptr);
memdelete(p_ptr);
}
MonoString *godot_icall_StringName_operator_String(StringName *p_np) {
return GDMonoMarshal::mono_string_from_godot(p_np->operator String());
String s = p_np->operator String();
return GDMonoMarshal::mono_string_from_godot(s);
}
bool godot_icall_StringName_operator_Equals(StringName *p_sn1, StringName *p_sn2) {
return p_sn1->operator==(*p_sn2);
MonoBoolean godot_icall_StringName_operator_Equals(StringName *p_sn1, StringName *p_sn2) {
return (MonoBoolean)p_sn1->operator==(*p_sn2);
}
void godot_register_stringname_icalls() {
GDMonoUtils::add_internal_call("Godot.StringName::godot_icall_StringName_Ctor", godot_icall_StringName_Ctor);
GDMonoUtils::add_internal_call("Godot.StringName::godot_icall_StringName_String_Ctor", godot_icall_StringName_String_Ctor);
GDMonoUtils::add_internal_call("Godot.StringName::godot_icall_StringName_StringName_Ctor", godot_icall_StringName_StringName_Ctor);
GDMonoUtils::add_internal_call("Godot.StringName::godot_icall_StringName_Dtor", godot_icall_StringName_Dtor);
GDMonoUtils::add_internal_call("Godot.StringName::godot_icall_StringName_operator_String", godot_icall_StringName_operator_String);
GDMonoUtils::add_internal_call("Godot.StringName::godot_icall_StringName_operator_Equals", godot_icall_StringName_operator_Equals);

View File

@ -41,11 +41,13 @@ StringName *godot_icall_StringName_Ctor();
StringName *godot_icall_StringName_String_Ctor(MonoString *p_path);
StringName *godot_icall_StringName_StringName_Ctor(StringName *p_path);
void godot_icall_StringName_Dtor(StringName *p_ptr);
MonoString *godot_icall_StringName_operator_String(StringName *p_np);
bool godot_icall_StringName_operator_Equals(StringName *p_sn1, StringName *p_sn2);
MonoBoolean godot_icall_StringName_operator_Equals(StringName *p_sn1, StringName *p_sn2);
// Register internal calls