Forums

New GTK# docs

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

New GTK# docs

Postby Charles » Fri Nov 04, 2011 8:18 pm

Thanks to user "callisto" for contributing GTK# docs including screenshots, example code for various widgets, layouts, menus, etc. It starts here:

http://cobra-language.com/trac/cobra/wiki/GtkLibrary
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: New GTK# docs

Postby callisto » Sat Nov 05, 2011 4:35 am

Thanks Charles - I hope the material is useful. (You beat me to the announcement!)

A cobra question: is it possible to write something like:

listen button.clicked, ref do(obj,e)=Application.quit  # this doesn't work!


i.e. pass a reference to an anonymous method? (I've tried creating sigs and local variables, but can't find a combination that works.) This would save a lot of boilerplate code, constructing single-use methods, just to get a name to reference.

The wiki entry for Listen, http://cobra-language.com/trac/cobra/wiki/Listen, ends with "# Todo example using closure/anonymous method", but I'm not sure that is referring to what I need.
callisto
 
Posts: 10

Re: New GTK# docs

Postby Charles » Sat Nov 05, 2011 10:44 am

Good question.
listen button.clicked, do(sender, args as EventArgs)
print 'Quitting'
Application.quit

The "do(args)=expr" form is only for expressions and is suitable when the return value is of interest and will be used. In the case where you need statements, they go on the next line indented and you can have as many statements as you like.

The type for "args" is currently required because Cobra is not yet as good as it should be about inferring the arg types. That will be improved in the future.

You need the "ref" keyword to refer to a named method so that it is not invoked. You never need "ref" and "do" at the same time--just one of them.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: New GTK# docs

Postby callisto » Sat Nov 05, 2011 5:14 pm

Charles wrote:The "do(args)=expr" form is only for expressions and is suitable when the return value is of interest and will be used. In the case where you need statements, they go on the next line indented and you can have as many statements as you like.


Thanks, that's a helpful clarification. I've got a few examples working now, and, in the right place, the anonymous methods are a convenient simplification.
callisto
 
Posts: 10


Return to Discussion

Who is online

Users browsing this forum: No registered users and 48 guests