What I wrote above was not quite the last iteration. What I did in the end was just like you suggested, MyClass.x() and MyClass.x(v). In MATLAB this makes sense, since the parenthesis for a function with no arguments is optional, meaning that you will refer to the getter as "MyClass.x", e.g. "x = MyClass.x;". It would be nice to have the syntax "MyClass.x = 4;", but this has the different meaning "create a structure named MyClass with a field named x" in MATLAB, a behavior that cannot be overloaded.

So in conclusion, for global variables "value = mymodule.x" for the getter and "mymodule.x(value);" for the setter. For static class variables "value = mymodule.MyClass.x" for the getter and "mymodule.MyClass.x(value);" for the setter. The "mymodule." prefix can be skipped by first doing "import mymodule.*".

I decided to handle constants the same way, but without the setter. Enums are also handled this way currently, but I consider changing that to generating a MATLAB "enumeration class.".

Thanks for feedback!
Joel




2014-04-22 8:00 GMT+02:00 William S Fulton <wsf@fultondesigns.co.uk>:
On 15/04/14 22:35, Joel Andersson wrote:

In any case, I went for the syntax "v = MyClass.x();" for getting the
value of static variable "x" and "MyClass.set_x(v)" for setting the
value. But that can easily be changed. I'll implement a similar support
for getting and setting global variables "v = x()" and "set_x(v)".

That is rather odd in my opinion. Either MyClass.x() and MyClass.x(v) should be used or MyClass.set_x() and MyClass.get_x(). In Java, it is MyClass.getX() and MyClass.setX() as this is the commonly used Javabean pattern. I'm not saying you should copy this pattern, but at least getter/setter syntax should be what is normally used in Matlab for setting properties/variables (whatever that is) or should be symmetric in its naming (use both a set and get prefix).

William

Best regards,
Joel



2014-04-15 21:36 GMT+02:00 William S Fulton <wsf@fultondesigns.co.uk
<mailto:wsf@fultondesigns.co.uk>>:


    Wouldn't the syntax be the same as in Octave? What does that do?


    On 15/04/14 13:30, Joel Andersson wrote:

        Hello,

        MATLAB does not support static member variables (static
        properties in
        MATLAB terminology) unless they are constant. And afact, there
        is no way
        of overloading "MyClass.my_class_variable".

        Are there any opinions on the preferred syntax for wrapping them?

        Options for wrapping a variable named "foo":
        1. Adding a get/set prefix and make static method:
        "MyClass.set_foo(v)"
        and "v = MyClass.get_foo()"
        2. Same, but without any prefix (checking the number of arguments):
        "MyClass.foo(v)" and "v = MyClass.foo()"
        3. Prefix only for set method: "MyClass.set_foo(v)" and "v =
        MyClass.foo()"
        4. Something else?

        I don't have any static member variables in the public API of
        the C++
        code I write, so I do not really have any opinion.

        Best regards.
        Joel

        P.S. Non-static member variables work just fine and have already
        been
        implemented, i.e. "a = my_instance.foo;" and "my_instance.foo = a;"
        where "my_instance" is an instance of MyClass.


        --

        --
        Joel Andersson
        Ptge. Busquets 11-13, atico 3
        E-08940 Cornella de Llobregat, Spain
        Home: +34-93-6034011 <tel:%2B34-93-6034011>
        Mobile: +32-486-672874 <tel:%2B32-486-672874> (Belgium) /
        +34-63-4408800 <tel:%2B34-63-4408800> (Spain) /
        +46-707-360512 <tel:%2B46-707-360512> (Sweden)


        ------------------------------__------------------------------__------------------

        Learn Graph Databases - Download FREE O'Reilly Book
        "Graph Databases" is the definitive new guide to graph databases
        and their
        applications. Written by three acclaimed leaders in the field,
        this first edition is now available. Download your free book today!
        http://p.sf.net/sfu/NeoTech



        _________________________________________________
        Swig-devel mailing list
        Swig-devel@lists.sourceforge.__net
        <mailto:Swig-devel@lists.sourceforge.net>
        https://lists.sourceforge.net/__lists/listinfo/swig-devel

        <https://lists.sourceforge.net/lists/listinfo/swig-devel>





--

--
Joel Andersson
Ptge. Busquets 11-13, atico 3
E-08940 Cornella de Llobregat, Spain
Home: +34-93-6034011
Mobile: +32-486-672874 (Belgium) / +34-63-4408800 (Spain) /
+46-707-360512 (Sweden)




--

--
Joel Andersson
Ptge. Busquets 11-13, atico 3
E-08940 Cornella de Llobregat, Spain
Home: +34-93-6034011
Mobile: +32-486-672874 (Belgium) / +34-63-4408800 (Spain) / +46-707-360512 (Sweden)