Skip to content
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

Feature: Implement 'global' parameter #12

Open
KES777 opened this issue Dec 25, 2020 · 1 comment
Open

Feature: Implement 'global' parameter #12

KES777 opened this issue Dec 25, 2020 · 1 comment

Comments

@KES777
Copy link

KES777 commented Dec 25, 2020

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
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants