Skip to content

Default method names #35

@anderslanglands

Description

@anderslanglands

Reopening this discussion. We should provide default name transformations for cons/destructors, operators and polymorpic functions so that the generated code will at least compile, even if the names are ugly, and then someone writing a binding can go back and fix it afterwards.

Overloads

This is easy, just enumerate the overloads as they're found:

void fun(float);
void fun(int);
void fun(short);

// becomes...
void fun(float);
void fun2(int);
void fun3(short);

Constructors & destructors

I think new and delete are probably the most sensible, or construct and destruct. In the previous discussion, new and delete felt overloaded because I was anticipating using opaqueptr for everything and mallocing in the API layer, but I feel like we're now leaning towards opaquebytes for most things and leave opaqueptr for things that can't be constructed by the user, in which case the library will be providing the creation methods manually so there's less worry about confusion.

struct Foo {
    Foo(float);
    Foo(int);
    Foo(short);
    Foo(const Foo& rhs);
};

// becomes...
void Foo_new(Foo* self, float);
void Foo_new2(Foo* self, int);
void Foo_new3(Foo* self, short);
void Foo_copy(Foo* self, Foo const* rhs);

Operators

We should just take the function names from the equivalent Rust traits here since they're logical, concise and consistent.

struct Foo {
    Foo operator+(const Foo& rhs) const;
    Foo& operator=(const Foo& rhs);
    Foo& operator+=(const Foo& rhs);
};

// becomes...
void Foo_add(Foo const* self, Foo const* rhs, Foo* result);
void Foo_assign(Foo* self, Foo const* rhs);
void Foo_add_assign(Foo* self, Foo const* rhs);

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions