godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.97k stars 20.18k forks source link

[GDExtension] operators unary-/unary+ unavialable in gdnative_interface.h #64083

Closed touilleMan closed 2 years ago

touilleMan commented 2 years ago

Godot version

4.0-rc13

System information

all

Issue description

Operator unary+ and unary- are referenced in extension_api.json

{
    "name": "int",
    "is_keyed": true,
    "operators": [
                [...]
        {
            "name": "unary+",
            "return_type": "int"
        },
               [...]
        {
            "name": "+",
            "right_type": "int",
            "return_type": "int"
        },

However they are not present in the GDNativeVariantType

https://github.com/godotengine/godot/blob/836fe9adcd94e68c30d6042d1ce5bfabde6b3473/core/extension/gdnative_interface.h#L104-L137

This is most likely because unary-/unary+ is equivalent to the operator -/+ with a right_type set to Nil. However this is currently unclear, especially given other operator like ~ and not are not called unary but work similarly.

So I would suggest to drop the "unary" part of the name and just consider the absence of the right_type field indicate it is an unary operator.

Steps to reproduce

n/a

Minimal reproduction project

No response

touilleMan commented 2 years ago

My bad, I just realized the unary +/- is actually present:

     "+": "GDNATIVE_VARIANT_OP_ADD",
     "-": "GDNATIVE_VARIANT_OP_SUBTRACT",

     "unary-": "GDNATIVE_VARIANT_OP_NEGATE",
     "unary+": "GDNATIVE_VARIANT_OP_POSITIVE",