-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to deffer subroutine/constant calling #4
Conversation
@@ -167,11 +167,6 @@ subtest 'define errors' => sub { | |||
match qr/rev must be either 'int', or 'str'/, | |||
); | |||
|
|||
is( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of removing this test, please substitute another unsupported type, like a scalar ref.
@@ -202,6 +202,9 @@ sub ffi_custom_type_api_1 | |||
foreach my $value (@values) | |||
{ | |||
my $name; | |||
if( ref $value eq 'CODE' ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if( ref $value eq 'CODE' ) { | |
if(is_coderef $value) { |
You will need to import is_coderef
from Ref::Util
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to document the new usage.
I'm not 100% sure this is the best way to handle enum aliasing tbh, I think there might be a better interface. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also a test should be added to test passing a subref in as a value.
I think a more general approach would be something like: $ffi->load_custom_type('::Enum', 'foo_t',
'default',
'better',
['best' => 12, alias => ['abc','xyz']],
); |
I think I prefer #6 which doesn't rely on the load order. I think you should still be able to do what you need. |
I am doing perl binding for SDL2 https://www.libsdl.org/download-2.0.php
in
include/SDL_pixels.h
there is next enum:I convert it like next:
because of
?:
works first beforeload_custom_type
is called. I get error:This patch allow to defer call to
SDL_PIXELFORMAT_ABGR8888
. Now declaration looks like:and works without problem