Skip to content

Default values for missing class methods #643

Closed

Description

@rpatters1

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

Activity

  1. ThistleSifter commented on Jan 20, 2024

    @ThistleSifter
    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.

  2. rpatters1 commented on Jan 20, 2024

    @rpatters1
    CollaboratorAuthor

    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?

  3. rpatters1 commented on Feb 9, 2024

    @rpatters1
    CollaboratorAuthor

    This was closed with #649.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions