Re: Structs in gobject-introspection + Javascript



Owen Taylor wrote:
>  set() - assigns a value of another object of the same type to the
>          object [3]
> 
> So, equivalent to the size-request example above you can do:
> 
> widget.connect('size-request', 
>                 function(widget, request) {
>                     request.set({ width: 100, height: 50 });
>                 });

Another argument against this API is that presumably this would break if
the user did

    request = { width: 100, height: 50 };

instead, which would be pretty non-obvious.

> 7. Any field declared in the introspection information can be read
> as an object property. 
> 
> 8. Any field in a simple structure can be set by assignment to an
> object property. Fields in non-simple structures cannot be set. {3}

gtk# automatically converts foo_set_bar() methods into writable
properties (when that's appropriate based on the method signature). So
if you had

    struct NamedPoint {
        int x;
        int y;
        char *name;
    };
    void named_point_set_name (NamedPoint *np, const char *name);

then instead of having an np.set_name() method, you'd just have a
writable np.name property that called named_point_set_name() underneath.
This works well and tends to make the APIs look a lot more native and
less badly-mapped-from-C.

-- Dan


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]