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

Re: [Libguestfs] example script for GObject



On Thu, Jan 26, 2012 at 12:54:55PM +0100, Hilko Bengen wrote:
> * Richard W.M. Jones:
> 
> >   var optargs = new Guestfs.AddDriveOpts ({readonly: true});
> >   g.add_drive_opts (filename, optargs);
> >
> > This awkward style is required because GObject Introspection doesn't
> > support optional arguments.
> 
> This is really, really ugly. Couldn't one use some sort of list instead?

That's somewhat of an overly dramatic statement really.

   g.add_drive_opts (filename, Guestfs.AddDriveOpts({format: "raw"}))

is really not all that different & more complex from what you show below

> Something that could be translated to Javascript as
> 
>     g.add_drive_opts (filename, [ Guestfs.AddDriveOpts.FORMAT, "raw" ] )

In GObject list elements cannot be of variant types as you would
require with this example, so this would only work if every single
variadic parameter to the function was of the same data type, ie
all strings, or all ints, etc.

> or even
> 
>     g.add_drive_opts (filename, Guestfs.AddDriveOpts.FORMAT, "raw" )

And doing variadic functions is even less possible, hence why
Matt did things the way they are now.

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|


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