IssueRaiser

Allow custom classes to define their own operator behavior (operator overloading)

### Describe the project you are working on A Mandelbrot set visualization tool ### Describe the problem or limitation you are having in your project This project requires the use of complex numbers (with a real and imaginary component). Godot, understandably, does not support complex numbers, so a custom class is needed to represent them. However to do something involving math for these complex numbers (e.g., addition), I have to now write and call custom functions to do this, instead of using the built-in math operators. ### Describe the feature / enhancement and how it helps to overcome the problem or limitation The feature enhancement would allow custom classes (such as the complex number class described above) to define their own operators so that standard mathematical (or other) operators could be supported. ### Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams I propose this should work in a similar way to Python's current implementation. This would involve having pre-defined function names for the operators that, when implemented, would open up the ability to perform those operations, with the behavior tied to the function's implementation. Essentially, this would be "syntactic sugar" that converts certain operators to a function call, if present. This is also in keeping with GDScript's other paradigms for class functions such as `_init`, `_process`, `_draw`, etc. where defining those function allow someone writing GDScri

Posted by TheCleric on Nov 9, 2023, 6:53 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.2,000 issues0 comments

support (Other)

Allow custom classes to define their own operator behavior (operator overloading)

TheClericNov 9, 2023, 6:53 PM

### Describe the project you are working on A Mandelbrot set visualization tool ### Describe the problem or limitation you are having in your project This project requires the use of complex numbers (with a real and imaginary component). Godot, understandably, does not support complex numbers, so a custom class is needed to represent them. However to do something involving math for these complex numbers (e.g., addition), I have to now write and call custom functions to do this, instead of using the built-in math operators. ### Describe the feature / enhancement and how it helps to overcome the problem or limitation The feature enhancement would allow custom classes (such as the complex number class described above) to define their own operators so that standard mathematical (or other) operators could be supported. ### Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams I propose this should work in a similar way to Python's current implementation. This would involve having pre-defined function names for the operators that, when implemented, would open up the ability to perform those operations, with the behavior tied to the function's implementation. Essentially, this would be "syntactic sugar" that converts certain operators to a function call, if present. This is also in keeping with GDScript's other paradigms for class functions such as `_init`, `_process`, `_draw`, etc. where defining those function allow someone writing GDScri

Comments (0)

No comments yet. Start the discussion.

Comment on this issue