Fellow monks,
I've written perl bindings for etk, (cpan). I'm currently writing the test suit and came across some inconsistencies:
Etk's objects mostly all extend the Etk::Widget object and the perl objects are simply blessed hash references that have an IV that points to the C object.
Most of the C functions that take objects take Etk_Widget and those that return them will also return an Etk_Widget, which the programmer has to cast to the appropriate type. Here's an example:
Etk_Bin * bin; Etk_Button * button; // assume the above initialized. etk_bin_child_set(bin, ETK_WIDGET(button); // and the get the button. button = ETK_BUTTON(etk_bin_child_get(bin));
Now in the perl version:
$bin->ChildSet($button); $button = $bin->ChildGet();
The problem is, passing $button to ChildSet works because of the inheritance, and $button is a widget, so it's cast correctly in the XS code, but ChildGet will return an Etk_Widget, and through the typemap the returned object will have Etk::Widget as a class, and therefore the programmer has to bless the object to the appropriate type, but that's not very perly.
I'm wondering on how best to keep track of what the objects were to return them. Here are the few options I can think of:
package Etk::Bin; sub ChildSet { my $self = shift; my $widget = shift; # do some checks. child_set($self, $widget); # this is the XS call $self->{_CHILD} = $widget; } sub ChildGet { my $self = shift; return $self->{_CHILD} if $self->{_CHILD}; return child_get($self); }
Any pointers or comments are greatly appreciated.
--In reply to Keeping track of classes by Leviathan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |