jhass / crystal-gobject

gobject-introspection for Crystal
BSD 3-Clause "New" or "Revised" License
127 stars 13 forks source link

Add a proper constructor to GTK Closures. #58

Closed hugopl closed 4 years ago

hugopl commented 4 years ago

They use the same mechanism used on signals.

hugopl commented 4 years ago

Future improvement: Would be nice to have all methods receiving a closure to (also) accept a block, so the user wouldn't need to explicit create the Closure object themselves.

jhass commented 4 years ago

Future improvement: Would be nice to have all methods receiving a closure to (also) accept a block, so the user wouldn't need to explicit create the Closure object themselves.

Yes this shouldn't be too hard and very similar to the GValue convenience stuff. https://github.com/jhass/crystal-gobject/blob/master/src/g_i_repository/info/function_info.cr#L76-L84

Basically there if there's a single arg of the GObject::Closure type, replace it with &#{arg.name} and then in the method body do #{arg.name} = GObject::Closure.new(#{arg.name}) before the lib call.

jhass commented 4 years ago

🎉

jhass commented 4 years ago

Alright, I couldn't resist and pushed a commit generating block taking overloads :)