Guest User

Untitled

a guest
Oct 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. I have this function:
  2.  
  3. ```perl6
  4. method set_sort_func (
  5. &sort_func (GtkListBoxRow $a, GtkListBoxRow $b, gpointer $data),
  6. gpointer $user_data = gpointer,
  7. GDestroyNotify $destroy = GDestroyNotify
  8. )
  9. ```
  10.  
  11. And I am calling it like this:
  12.  
  13. ```perl6
  14. $listbox.set_sort_func(-> $a, $b {
  15. %messages{$a}<data><time> <=> %messages{$b}<data><time>
  16. });
  17. ```
  18.  
  19. But I'm getting the following error message:
  20.  
  21. ```
  22. Cannot unpack or Capture `&sort_func`.
  23. To create a Capture, add parentheses: \(...)
  24. If unpacking in a signature, perhaps you needlessly used parentheses? -> ($x) {} vs. -> $x {}
  25. or missed `:` in signature unpacking? -> &c:(Int) {}
  26. in method set_sort_func at /home/cbwood/Projects/p6-GtkPlus/lib/GTK/ListBox.pm6 (GTK::ListBox) line 259
  27. in block <unit> at t/41-listbox.t line 151
  28.  
  29. ```
  30.  
  31. I've tried many variations of the above, including changing how the call was made, how the sub was declared:
  32.  
  33. *VARIANT #1*
  34.  
  35. Defining a sub and then passing it off to the routine:
  36.  
  37. Parameter:
  38. ```
  39. &sort_func:(GtkListBoxRow $a, GtkListBoxRow $b, gpointer $data)"
  40. ```
  41. Sub definition:
  42. ```
  43. sub sort-func($a, $b) {
  44. %messages{$a}<data><time> <=> %messages{$b}<data><time>
  45. };
  46. ```
  47. Invocation:
  48. ```
  49. $listbox.set_sort_func(&sort-func);
  50. ```
  51. Error message:
  52. ```
  53. Constraint type check failed in binding to parameter '&sort_func'; expected anonymous constraint to be met but got Sub (sub sort-func ($a, $b...)
  54. ```
  55.  
  56. I've tried other ways, but I always keep get something similar to the above error message. What is the best way to pass a Perl func off to subroutine that wrapps the C call?
Add Comment
Please, Sign In to add comment