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

Use FFI types to enforce sane resolution values. #41

Merged
merged 2 commits into from
Dec 25, 2018
Merged

Conversation

seanhandley
Copy link
Owner

@seanhandley seanhandley commented Dec 23, 2018

Also includes some changes to make the attach_function more readable i.e. alias int and pointer to more descriptive values.

Copy link
Contributor

@fxn fxn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good refactor, the declarations read better.

Also, super clean way to validate resolutions and have parameter types documented in one shot!

Only feedback would be that the natural type to represent a range in Ruby is Range. While the current array-based code works, I believe it would be even more concise to do this:

RES_RANGE = 0..15

There is no need to freeze because ranges are inmutable.

Then, efficient testing is

RES_RANGE.cover?(value)

and there is also API to get both ends of the range for the error message.

@seanhandley
Copy link
Owner Author

Ooh nice - I didn't realise this method existed 😁

Thanks!

Copy link
Contributor

@fxn fxn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎄

@seanhandley seanhandley merged commit 8a5e558 into master Dec 25, 2018
@seanhandley seanhandley deleted the ffi_types branch January 23, 2019 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants