Page MenuHomePhabricator

Support default values @property's keys and method's params in eo
Open, Incoming QueuePublic

Description

How about adding a new grammar keyword in eo to support default value for @property's keys and method's params for language bindings?

It is similar to @optional in constructors { }.
(it seems that @optional in method's parameter does not make any change for language bindings.)

However, @optional always sets default value as null but this new grammar keyword can set default value which can be non-null.

Here is an example of efl_ui_win.eo.
Let's assume we follow existing the grammar for @property values. (Thanks @bu5hm4n :))

center @beta {
   params {
      @in h : bool(true);
      @in v : bool(true);
   }
}

We can make the above eo affect C# bindings as follows.

virtual public void Center(bool h = true, bool v = true) {
}

So it helps to simply call win.Center();

There is a possible issue on this support.
e.g. if h has default value and h does not have default value, then it may cause build error on C#.
However, I think this kind of build error can be easily caught and fixed.

Jaehyun_Cho renamed this task from Support override functions for Language Bindings in eo to Support default values @property's keys and method's params in eo.

@q66 @lauromoura @felipealmeida

Could you tell me your opinion on this task?

BTW, C does not support default value on function parameters so this feature is definitely for language bindings.

From eolian side, there is already this syntax:

@property allow_parent_unref @beta {
         [[... ]]
         values {
            allow: bool(false); [[...]]
         }
      }

Which is copied from efl_object.eo

From eolian side, there is already this syntax:

@property allow_parent_unref @beta {
         [[... ]]
         values {
            allow: bool(false); [[...]]
         }
      }

Which is copied from efl_object.eo

Thank you! It looks neat and much simpler! :)

So @property's values can have default value now~ (although it does not set parameter's default value in C# now)
Then I think it seems OK that this default value grammar is applied to @prperty's keys and method's params as well~ (now it is not supported yet)

center @beta {
   params {
      @in h : bool(true);
      @in v : bool(true);
   }
}
Jaehyun_Cho updated the task description. (Show Details)Jun 10 2019, 9:38 PM
segfaultxavi added a subscriber: segfaultxavi.

So, if I understood correctly, when a parameter has a default value in an Eo file like this:

center @beta {
   params {
      @in h : bool(true);
      @in v : bool(true);
   }

these default values should be also present in the C# files like this:

void Center (Bool h = true, Bool v = true);

I think this makes sense. Is it feasible, @lauromoura ?

lauromoura added a comment.EditedSep 20 2019, 7:06 AM

So, if I understood correctly, when a parameter has a default value in an Eo file like this:

center @beta {
   params {
      @in h : bool(true);
      @in v : bool(true);
   }

these default values should be also present in the C# files like this:

void Center (Bool h = true, Bool v = true);

I think this makes sense. Is it feasible, @lauromoura ?

Yeah. It is doable.

But one thing to keep in mind is that many languages (C#, Python, C++) require that default arguments must come after the required arguments (which makes sense to make method calls less ambiguous).

q66 added a comment.EditedSep 20 2019, 8:03 AM

This appears to be wrong. The "default values" are only allowed for property values {} block as well as for @out parameters, Eolian will not accept them for @in parameters. I.e. those values are default fallbacks.