PerlFFI / FFI-Platypus-Type-Enum

Custom platypus type for dealing with C enumerated types
2 stars 2 forks source link

Feature: Implement 'global' parameter #12

Open KES777 opened 3 years ago

KES777 commented 3 years ago

image

by providing a package I still want that constant is created at specified package.

It would be nice if we also specify some global space for all constants (this is useful for large libraries)

  $ffi->load_custom_type('::Enum', 'SDL_RendererFlip',
    { ret => 'int', package => 'SDL2::Render', global => 'SDL2' },
    ...

And when $ffi is instantiated we can pass parameter which trigger spoil global namespace or not:

my $ffi = FFI::Platypus->new( api => 1, global => 1 ); # Enable all globals
my $ffi = FFI::Platypus->new( api => 1, global => [ 'SDL2', 'SomeOtherSpace' ] );  # Enable only these two
my $ffi = FFI::Platypus->new( api => 1, global => 0 ); # Constant still accessable via SDL2::Render::SDL_FLIP_NONE
my $ffi = FFI::Platypus->new( api => 1 );                     # Constant still accessable via SDL2::Render::SDL_FLIP_NONE

Also would be nice if it automatically remove some prefix:

  $ffi->load_custom_type('::Enum', 'SDL_RendererFlip',
    { ret => 'int', package => 'SDL2::Render', remove => 'SDL_' },
    ['SDL_FLIP_NONE'       => 0x00000000],    #  /**< Do not flip */

will create SDL2::Render::FLIP_NONE. This will save us from repeating SDL because it is already at package name

plicease commented 3 years ago

It would be nice if we also specify some global space for all constants (this is useful for large libraries)

  $ffi->load_custom_type('::Enum', 'SDL_RendererFlip',
    { ret => 'int', package => 'SDL2::Render', global => 'SDL2' },
    ...

How about package accepts an array reference in addition to just a scalar:

  $ffi->load_custom_type('::Enum', 'SDL_RendererFlip',
    { ret => 'int', package => ['SDL2::Render', 'SDL2'] },
    ...

And when $ffi is instantiated we can pass parameter which trigger spoil global namespace or not:

my $ffi = FFI::Platypus->new( api => 1, global => 1 ); # Enable all globals
my $ffi = FFI::Platypus->new( api => 1, global => [ 'SDL2', 'SomeOtherSpace' ] );  # Enable only these two
my $ffi = FFI::Platypus->new( api => 1, global => 0 ); # Constant still accessable via SDL2::Render::SDL_FLIP_NONE
my $ffi = FFI::Platypus->new( api => 1 );                     # Constant still accessable via SDL2::Render::SDL_FLIP_NONE

I'm not quite sure how you would use this, or why you can't specify the package spaces when you load the custom type.

Also would be nice if it automatically remove some prefix:

  $ffi->load_custom_type('::Enum', 'SDL_RendererFlip',
    { ret => 'int', package => 'SDL2::Render', remove => 'SDL_' },
    ['SDL_FLIP_NONE'       => 0x00000000],    #  /**< Do not flip */

will create SDL2::Render::FLIP_NONE. This will save us from repeating SDL because it is already at package name

I'm not dogmatically apposed to this, but why can't you just specify the constant names without the prefix?