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

Default values for missing class methods #643

Closed
rpatters1 opened this issue Jan 19, 2024 · 3 comments
Closed

Default values for missing class methods #643

rpatters1 opened this issue Jan 19, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@rpatters1
Copy link
Collaborator

Is your feature request related to a problem? Please describe.

I am working on localization of some scripts using new localization tools I am developing. Specifically, I would like to localize the transposition scripts as a pilot project for other scripts in the repo. But these scripts still work with JW Lua. I would like to find an elegant solution for skipping the new method calls in RGP Lua so that the scripts can continue to work with JW Lua.

Describe the solution you'd like

It occurred to me that mixin might be able to provide default implementations of missing methods. What I have in mind is that any method call could provide an optional additional parameter. If the additional parameter were present (non nil), the mixin library would check for the existence of the underlying RGP Lua method. If not found, it would return either return the default value passed in or (if the method is fluid) ignore the call entirely and simply return self. (If found it would call the method and behave as it does now.)

Describe alternatives you've considered

I suppose I could write one-off versions of the new methods that do the same thing. Or I could pepper the scripts with ugly if-statements.

@ThistleSifter

@rpatters1 rpatters1 added the enhancement New feature or request label Jan 19, 2024
@ThistleSifter
Copy link
Member

As far as mixin solutions go, I think there are two reasonable options here.

  1. Write the methods
    Self explanatory...

  2. Wrapping function & wrapping method
    Add a function to the mixin namespace, like the example below. This could be used for anything (eg if a new function is added to RGPLua along the lines of each, etc)

local str = mixin.FCMString()
mixin.fallback_call("fallback_value", str.MethodName, self, arg_1, arg_2)

For DX/readability, a method can be added which proxies the function above. Eg

local str = mixin.FCMString()
str:__FALLBACK__("fallback_value", "MethodName", arg_1, arg_2)

If you want it to be fluid, pass self as the fallback value.

@rpatters1
Copy link
Collaborator Author

After I posted this, it occurred to me that it would be possible to rewrite the methods in Lua. It's not like the OSs provide a lot of support for automatic control sizing, but (especially macOS) provides at least some.

I like the fallback call idea. I'm not crazy about the double-underscores (aesthetically) for the proxy. Do you think simply all caps would sufficient future-proofing?

@rpatters1
Copy link
Collaborator Author

This was closed with #649.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants