[JW Lua] RFC: Adding Methods/Properties to RGP Lua that only exist in certain Finale versions

Daniel Grunwald dgr at leng.de
Thu Aug 25 09:00:58 CEST 2022


Agreed. This is much clearer than a (inexpressively) null check. 

Von meinem Xperia™ von Sony-Smartphone gesendet

---- jwlua-request at jwmusic.nu schrieb ----

>Send JWLua mailing list submissions to
>	jwlua at jwmusic.nu
>
>To subscribe or unsubscribe via the World Wide Web, visit
>	http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
>or, via email, send a message with subject or body 'help' to
>	jwlua-request at jwmusic.nu
>
>You can reach the person managing the list at
>	jwlua-owner at jwmusic.nu
>
>When replying, please edit your Subject line so it is more specific
>than "Re: Contents of JWLua digest..."
>
>
>Today's Topics:
>
>   1. Re: RFC: Adding Methods/Properties to RGP Lua that only exist
>      in certain Finale versions (Nick Mazuk)
>
>
>----------------------------------------------------------------------
>
>Message: 1
>Date: Wed, 24 Aug 2022 16:42:17 +0000
>From: "Nick Mazuk" <nick at nickmazuk.com>
>To: "The JW Lua script plug-in." <jwlua at jwmusic.nu>
>Subject: Re: [JW Lua] RFC: Adding Methods/Properties to RGP Lua that
>	only exist in certain Finale versions
>Message-ID:
>	<l77ufq8b.e8ce6bf0-bc59-4c31-b9b3-c690f52f929c at we.are.superhuman.com>
>Content-Type: text/plain; charset="utf-8"
>
>This seems like a good plan to me.
>
>On Wed, Aug 24, 2022 at 8:58 AM, Robert Patterson < robert at robertgpatterson.com > wrote:
>
>> 
>> Instead of pcall, you do:
>> 
>> 
>> if finenv.RawFinaleVersion >= <min-vers> then
>> do something
>> end
>> 
>> 
>> It doesn't seem much worse than null checking, and it shows what's really
>> going on. This could all be encapsulated in a client library of course.
>> 
>> 
>> 
>> On Wed, Aug 24, 2022 at 10:51 AM Robert Patterson < robert@ robertgpatterson.
>> com ( robert at robertgpatterson.com ) > wrote:
>> 
>> 
>>> I have been experimenting with throwing an error out of C++ this morning ,
>>> and it works seamlessly exactly as one would hope. I much prefer an error
>>> message that says, "modula.lua line 420: Finale 26.9 required". (To make
>>> up a Finale version.)
>>> 
>>> 
>>> Plus, you'll only have to use pcall if you are unwilling to specify
>>> MinFinaleVersion in your plugindef.
>>> 
>>> 
>>> 
>>> 
>>> On Wed, Aug 24, 2022 at 10:26 AM Nick Mazuk < nick@ nickmazuk. com (
>>> nick at nickmazuk.com ) > wrote:
>>> 
>>> 
>>>> Throwing an error might be redundant. For instance, if the following
>>>> prints out nil (for instance, if the method doesn't exist on the object):
>>>> 
>>>> 
>>>> 
>>>> local entry = finale.FCEntry()
>>>> 
>>>> print(entry.FooBar)
>>>> 
>>>> 
>>>> 
>>>> then the following will already be thrown an error since nil is not a
>>>> function:
>>>> 
>>>> 
>>>> 
>>>> local entry = finale.FCEntry()
>>>> 
>>>> entry:FooBar() ? error!
>>>> 
>>>> 
>>>> 
>>>> The only advantage I can think of by having RGP Lua throw an error if you
>>>> even access it is that you'll potentially get more meaningful error
>>>> messages as a user. As a developer, the plugin will still tell you exactly
>>>> what line of code threw the error. However, it has the disadvantage that
>>>> you must use pcall to capture the error and you cannot simply check if the
>>>> method exists or not (which developers should be doing anyways for any
>>>> newly added features to RGP Lua).
>>>> 
>>>> 
>>>> 
>>>> On Wed, Aug 24, 2022 at 5:24 AM, Robert Patterson < robert@ robertgpatterson.
>>>> com ( robert at robertgpatterson.com ) > wrote:
>>>> 
>>>>> Throwing an error is a good idea that I hadn't thought of. However, these
>>>>> errors would have to be thrown out of the PDK Framework, which is not Lua.
>>>>> So far, there is no try/catch/throw in the PDK Framework codebase. That is
>>>>> not to say we couldn't start using it, but it will require approvals from
>>>>> the other clients that share that code.
>>>>> 
>>>>> 
>>>>> Meanwhile, if the function is missing you'll get the same behavior. It
>>>>> just won't have as helpful an error message. And by leaving it missing,
>>>>> you don't have to resort to pcall. You can simply test if it is there.
>>>>> 
>>>>> 
>>>>> 
>>>>> On Wed, Aug 24, 2022 at 6:18 AM Daniel Grunwald < dgr@ leng. de (
>>>>> dgr at leng.de ) > wrote:
>>>>> 
>>>>> 
>>>>>> 
>>>>>> 
>>>>>> Hi there,
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> it seems my first reply didn't get through. So I repeat it. I case you
>>>>>> receive this twice you know why.
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> I am a lua novice having no actual experience in lua so my idea might be
>>>>>> foolish. However from what I learned in terms of clean code in other
>>>>>> languages I would prefer to raise an error instead of not providing the
>>>>>> function.
>>>>>> In order to deal with this users will have to use pcall, as described in https:/
>>>>>> / www. lua. org/ pil/ 8. 4. html ( https://www.lua.org/pil/8.4.html )
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> Although not knowing if it really is (by lack experience) to me it sounds
>>>>>> like a cleaner approach.
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> However if you like to use the nil-approach I suggest putting "OrNil" as
>>>>>> suffix to the function's name so the name indicates it possibly being nil.
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> Hope this was helpful.
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> Best regards
>>>>>> Daniel
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> Von meinem Xperia? von Sony-Smartphone gesendet
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> ---- jwlua-request@ jwmusic. nu ( jwlua-request at jwmusic.nu ) schrieb ----
>>>>>> 
>>>>>> Send JWLua mailing list submissions to
>>>>>> jwlua@ jwmusic. nu ( jwlua at jwmusic.nu )
>>>>>> 
>>>>>> To subscribe or unsubscribe via the World Wide Web, visit
>>>>>> http:/ / jwmusic. nu/ mailman/ listinfo/ jwlua_jwmusic. nu (
>>>>>> http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu )
>>>>>> or, via email, send a message with subject or body 'help' to
>>>>>> jwlua-request@ jwmusic. nu ( jwlua-request at jwmusic.nu )
>>>>>> 
>>>>>> You can reach the person managing the list at
>>>>>> jwlua-owner@ jwmusic. nu ( jwlua-owner at jwmusic.nu )
>>>>>> 
>>>>>> When replying, please edit your Subject line so it is more specific
>>>>>> than "Re: Contents of JWLua digest..."
>>>>>> 
>>>>>> 
>>>>>> Today 's Topics:
>>>>>> 
>>>>>> 1. RFC: Adding Methods/Properties to RGP Lua that only exist in
>>>>>> certain Finale versions (Robert Patterson)
>>>>>> 
>>>>>> 
>>>>>> ----------------------------------------------------------------------
>>>>>> 
>>>>>> Message: 1
>>>>>> Date: Mon , 22 Aug 2022 15:03: 15 -0500 ( tel:15%20-0500 )
>>>>>> From: Robert Patterson < robert@ robertgpatterson. com (
>>>>>> robert at robertgpatterson.com ) >
>>>>>> To: "The JW Lua script plug-in." < jwlua@ jwmusic. nu ( jwlua at jwmusic.nu )
>>>>>> >
>>>>>> Subject: [JW Lua] RFC: Adding Methods/Properties to RGP Lua that only
>>>>>> exist in certain Finale versions
>>>>>> Message-ID:
>>>>>> < CAACnceu23XaymU4XNBZQ-1e6wDdP5xP6-ht8fdk3trUduahrUA@ mail. gmail. com (
>>>>>> CAACnceu23XaymU4XNBZQ-1e6wDdP5xP6-ht8fdk3trUduahrUA at mail.gmail.com ) >
>>>>>> Content-Type: text/plain; charset="utf-8"
>>>>>> 
>>>>>> I will soon be adding to RGP Lua some methods and properties that are not
>>>>>> available before a certain Finale version. Previously when this has
>>>>>> happened, the methods and properties appear in all Finale versions but
>>>>>> return a default value in earlier Finale versions where they aren't
>>>>>> supported. Until now there has always been an appropriate default value.
>>>>>> 
>>>>>> However, these new methods and properties I plan to add do not have useful
>>>>>> 
>>>>>> default values in earlier Finale versions. In fact, it would be a bad idea
>>>>>> 
>>>>>> to return anything at all unless running in an supported Finale version.
>>>>>> 
>>>>>> To me the best solution would appear to be not to hook up these methods
>>>>>> and
>>>>>> properties to Lua if the Finale version doesn't support them. But that
>>>>>> means, in perpetuity, Lua programmers will have to check them for `nil`
>>>>>> before calling them. Does anyone have other/better ideas?
>>>>>> -------------- next part --------------
>>>>>> An HTML attachment was scrubbed...
>>>>>> URL: < http:/ / jwmusic. nu/ pipermail/ jwlua_jwmusic. nu/ attachments/ 20220822/
>>>>>> 224e51a5/ attachment-0001. html&gt (
>>>>>> http://jwmusic.nu/pipermail/jwlua_jwmusic.nu/attachments/20220822/224e51a5/attachment-0001.html&gt
>>>>>> ) ;
>>>>>> 
>>>>>> ------------------------------
>>>>>> 
>>>>>> Subject: Digest Footer
>>>>>> 
>>>>>> _______________________________________________
>>>>>> JWLua mailing list
>>>>>> JWLua@ jwmusic. nu ( JWLua at jwmusic.nu )
>>>>>> http:/ / jwmusic. nu/ mailman/ listinfo/ jwlua_jwmusic. nu (
>>>>>> http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu )
>>>>>> 
>>>>>> 
>>>>>> ------------------------------
>>>>>> 
>>>>>> End of JWLua Digest, Vol 94, Issue 5
>>>>>> ************************************
>>>>>> _______________________________________________
>>>>>> JWLua mailing list
>>>>>> JWLua@ jwmusic. nu ( JWLua at jwmusic.nu )
>>>>>> http:/ / jwmusic. nu/ mailman/ listinfo/ jwlua_jwmusic. nu (
>>>>>> http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu )
>>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> _______________________________________________
>>>>> JWLua mailing list
>>>>> JWLua@ jwmusic. nu ( JWLua at jwmusic.nu )
>>>>> http:/ / jwmusic. nu/ mailman/ listinfo/ jwlua_jwmusic. nu (
>>>>> http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu )
>>>>> 
>>>>> 
>>>>> 
>>>> 
>>>> 
>>>> 
>>>> _______________________________________________
>>>> JWLua mailing list
>>>> JWLua@ jwmusic. nu ( JWLua at jwmusic.nu )
>>>> http:/ / jwmusic. nu/ mailman/ listinfo/ jwlua_jwmusic. nu (
>>>> http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu )
>>>> 
>>> 
>>> 
>>> 
>> 
>> 
>> 
>> _______________________________________________
>> JWLua mailing list
>> JWLua@ jwmusic. nu ( JWLua at jwmusic.nu )
>> http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
>> 
>> 
>>
>-------------- next part --------------
>An HTML attachment was scrubbed...
>URL: <http://jwmusic.nu/pipermail/jwlua_jwmusic.nu/attachments/20220824/befa49c3/attachment.html>
>
>------------------------------
>
>Subject: Digest Footer
>
>_______________________________________________
>JWLua mailing list
>JWLua at jwmusic.nu
>http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu
>
>
>------------------------------
>
>End of JWLua Digest, Vol 94, Issue 8
>************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jwmusic.nu/pipermail/jwlua_jwmusic.nu/attachments/20220825/18a43677/attachment-0001.html>


More information about the JWLua mailing list