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

Implement fallback_call #647

Merged
merged 4 commits into from
Jan 21, 2024

Conversation

rpatters1
Copy link
Collaborator

This PR implements a fallback call for mixin similar to the solution proposed in #643. I modified the proposed solution as follows:

  • used fallback_call as the name of the proxy method as well as the mixin function. No PDK Framework class will ever use snake case for a property, method, or constant value, at least as long as I am on the project. That means any snake case method name is safe for use by mixin.
  • changed the order of parameters for readability.

This solution has an added benefit that if a mixin version of a missing method is ever implemented, this function should pick it up.

An open question is

  • Should mixin.fallback_call be private instead of public?

@ThistleSifter
Copy link
Member

It might be safe, but I really don't like the idea of mixing case styles in the same context, it's messy.

Perhaps it might be better to add a __FCMBase mixin and put it there instead?

* master:
  chore: autopublish 2024-01-20T22:33:40Z
  fix typo and remove "..." from window title
  clarify how to require an embedded library in the docs
  missed one
  lint fixes and build broken
@rpatters1
Copy link
Collaborator Author

The __FCMBase idea is elegant. It isolates the change, leaving the mixin library itself unchanged. Excellent suggestion.

I also changed the name to use pascal case with a leading underscore. The PDK Library has some public class methods that start with underscore, but none of them are exposed to Lua. I don't plan to start, either.

]]
function methods:_FallbackCall(method_name, fallback_value, ...)
if not self[method_name] then
return fallback_value or self
Copy link
Member

Choose a reason for hiding this comment

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

This should explicitly check for nil so that it doesn't return self if false is passed, which could be a legitimate fallback value.

@rpatters1
Copy link
Collaborator Author

Another excellent catch. I've fixed it, and I'm going to go ahead an merge it because I need to have it in place for the next PR I will be submitting soon. If there are further tweaks we can do it there.

@rpatters1 rpatters1 merged commit f4f357e into finale-lua:master Jan 21, 2024
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