Closed hugopl closed 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.
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.
🎉
Alright, I couldn't resist and pushed a commit generating block taking overloads :)
They use the same mechanism used on signals.