[Gd-hackers] gtk interface: shorten identifiers, ... ?
Andreas Bogk
andreas at andreas.org
Mon Nov 27 02:26:17 CET 2006
Danny Milosavljevic schrieb:
> I wonder how to modify the gtk interface in
> to make an example like this possible:
[snip]
> That is,
> 1) use short identifiers for "object methods"
I don't think that's a good idea. The GTK API is specified in terms of
the identifiers with prefix, and somehow munging that seems odd. You
will probably also run into trouble deciding which prefix to drop when,
as GTK doesn't really have object methods. Also, the author constantly
has to look up whether a specific prefix is dropped or not (and dropping
all of them will probably make a mess).
Adding a name mapper to melange might do it, but you might have to touch
parts of the GTK support code.
> 2) use symbols for flags
That one should be doable using a mapping, as you guessed. Use the map:
and equate: arguments in the melange definition, and play around with
export-value and import-value. Grepping for those functions in the
repository should find you examples.
> 3) add actual slots for signals (so that it isn't so easy to specify
> non-existant signals)
I don't think that's a good idea either, there might be signals added
dynamically. But if you want it, play around with gobject2-tool, and
try to get your fingers at a list of signals for a class, and then emit
functions for each.
In fact, enough of glib is probably wrapped, so you can write the
generator in Dylan.
Note that semantically there is no difference between a slot access and
a function call. You can just emit code like this:
define method response (dialog :: <gtk-dialog>)
make(<signal-reference>, object: dialog, name: "response")
end;
for every signal, with the following support code:
define class <signal-reference> (<object>)
constant slot signal-object, required-init-keyword: object:;
constant slot signal-name, required-init-keyword: name:;
end;
define method connect (signal :: <signal-reference>,
callback :: <function>)
g-signal-connect(signal.signal-object, signal.signal-name, callback)
end;
The syntax would be slightly different, though:
connect(dialog.response, method() ...
An expression like:
dialog.connect.response(method() ...
would try to access a slot response on the object returned by connect,
and call the value of that slot as a function, passing in the method.
But still, this construction generates overhead for almost no value.
> 4) add support for "make(<window>" etc
The g_object_new call is what you need to look at to implement this.
Andreas
More information about the hackers
mailing list