Re: NSSpeechRecognizer commands
Understood.
But even if there was a check at compile time, you would still be in a trial-and-error mode to figure out which string to use for the call (message to send).
In this respect, the Lispworks Java Interface is really well done.
A call to lw-ji:import-java-class-definitions with the class name as a string argument returns the list of all callable methods.
Bruno
> On Jun 29, 2018, at 02:20, Alexey Veretennikov <txm.fourier@gmail.com> wrote:
>
> Hi,
>
> IIRC there is no compile-time checks on if method is implemented by the
> class, as calling Obj-C method is a way to "send a message" to the
> class, and Obj-C may define runtime ways to determine what to do if the
> method is not found.
>
> Bruno Emond <emond.bruno@gmail.com> writes:
>
>> Hi Ron,
>> thanks for your quick response, unfortunately it is not helping.
>> The kind of issue you are having is quite different than mine.
>> It has noting to do with application delivery, and only remotely with Foreign
>> Language Interface.
>>
>> LispWorks has specific functions and methods to use Objective-C and Cocoa on
>> MacOS.
>> http://www.lispworks.com/documentation/lw60/OBJC/html/objc.htm
>> I was trying to figure out some method names I want to call.
>> Some methods can be easily identified from the Apple documentation
>> (ex. “setCommands:" from my previous message).
>>
>> Others are more difficult like "startSpeaking(_:)”.
>> After many trial-and-errors, I finally figured that one out as well.
>> (objc:can-invoke-p *ss* "startSpeakingString:")
>> T
>>
>> Bruno
>>
>>> On Jun 28, 2018, at 16:00, Ron Lewis <rlewis-4d@indinfer.com> wrote:
>>>
>>> I have NOT done this and don't really know what I am doing. Still, maybe what
>>> I say could help figure out how to do what you want to do.
>>>
>>> Hopefully, someone who DOES know what they are doing will reply with a more
>>> useful answer.
>>>
>>> I think that LispWorks produces DLLs that are compatible with C Language
>>> access. And LispWorks can access DLLs compiled by a C compiler. So, DLLs go
>>> both ways, Lisp calls to DLL functions and C calls to DLL functions.
>>>
>>> So in my thinking, what you want to do involves learning the "LispWorks
>>> Delivery User Guide", particularly at these links:
>>> http://www.lispworks.com/documentation/lw71/DV/html/delivery-130.htm
>>>
>>>
>>> http://www.lispworks.com/documentation/lw60/LW/html/lw-200.htm#pgfId-885976
>>>
>>> and maybe this as well for Foreign Language Interface
>>> http://www.lispworks.com/documentation/lw60/FLI/html/fli.htm
>>>
>>> I have perused a little but not actually tried interfacing with C.
>>>
>>> I think the LispWorks compiler can compile a C Language program if the file
>>> ends with ".c" . This is Windows. You are doing Mac. So, maybe you designate a
>>> C source file differently.
>>>
>>> I tried to compile a file named "try.c" with contents
>>> void f (void) {}
>>>
>>> I loaded the file into LispWorks. Clicked the Compile Buffer button. The
>>> output looked to me that LispWorks was doing a C Language compile by
>>> automatically calling a C compiler that I had installed. LispWorks was not
>>> doing a Lisp source code compilation.
>>>
>>> My test did not compile because "Error: the variable 'void' is unbound. So,
>>> for sure I am not doing something right.
>>>
>>> Still, what I have said maybe could lead you to find the answer for what you
>>> are trying to do. If so, I hope you will share what you figure out on this C
>>> and Lisp interfacing because I anticipate going there at some point.
>>>
>>> Or, maybe you have already been to the links I suggested and it is not
>>> helpful.
>>>
>>> Hopefully, someone who knows what they are doing will respond. I am trying to
>>> post in the spirit of Lisp HUG members trying to help each other. I know I
>>> have been helped fantastically several times in Lisp HUG.
>>>
>>>
>>> Ron Lewis
>>> Baltimore, MD 21215-3551
>>> USA
>>>
>>>
>>> -----Original Message-----
>>> From: owner-lisp-hug@lispworks.com <owner-lisp-hug@lispworks.com> On Behalf Of
>>> Bruno Emond
>>> Sent: Thursday, June 28, 2018 2:55 PM
>>> To: Lisp HUG <lisp-hug@lispworks.com>
>>> Subject: Re: NSSpeechRecognizer commands
>>>
>>> I am just wondering.
>>>
>>> Is there a way to inspect the list of available Objective-C methods for a
>>> class?
>>>
>>> Calling objc:can-invoke-p on a trial and error basis is not very optional.
>>>
>>> I am looking specifically to know what would be the method name for
>>> startSpeaking(_:)
>>> https://developer.apple.com/documentation/appkit/nsspeechsynthesizer/1448378-startspeaking
>>>
>>> Thanks.
>>>
>>> Bruno
>>>
>>>
>>>> On Jun 27, 2018, at 14:36, Bruno Emond <emond.bruno@gmail.com> wrote:
>>>>
>>>> Sorry for the noise.
>>>> I just found the solution:
>>>>
>>>> (objc:invoke *Speech-Recognizer* "setCommands:" (vector "Hello”))
>>>>
>>>> Bruno
>>>>
>>>>
>>>>> On Jun 27, 2018, at 13:06, Bruno Emond <emond.bruno@gmail.com> wrote:
>>>>>
>>>>> I am trying to set a list of commands for the MacOS NSSpeechRecognizer class
>>>>> (Objective-C/Cocoa) without success.
>>>>>
>>>>> Here is some of the code I am using:
>>>>>
>>>>> (objc:ensure-objc-initialized
>>>>> :modules
>>>>> '("/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/
>>>>> SpeechRecognition.framework/Versions/A/SpeechRecognition"))
>>>>>
>>>>> (defparameter *Speech-Recognizer*
>>>>> (objc:alloc-init-object "NSSpeechRecognizer"))
>>>>>
>>>>> (objc:description *Speech-Recognizer*) —> "<NSSpeechRecognizer:
>>>>> 0x10290b880>"
>>>>>
>>>>> So far so good.
>>>>>
>>>>> The Apple documentation says that NSSpeechRecognizer has a “commands"
>>>>> variable with the following signature.
>>>>> var commands: [String]? { get set }
>>>>>
>>>>> Unfortunately, the objc:objc-object-var-value method does not allow to set
>>>>> or get this value.
>>>>> Because as its documentation says: "Note that it is only possible to access
>>>>> instance variables that are defined in Lisp by define-objc-class, not those
>>>>> inherited from superclasses implemented in Objective-C.”
>>>>>
>>>>> Interestingly, it appears that there is a “commands” method that can be
>>>>> invoked on an NSSpeechRecognizer instance.
>>>>>
>>>>> (objc:can-invoke-p *Speech-Recognizer* "commands”) —> T
>>>>>
>>>>> (objc:invoke *Speech-Recognizer* “commands”) returns a null pointer,
>>>>> which would make sense given that there is no list of commands yet.
>>>>>
>>>>> This is where I am stuck. How could I add to the list of commands ?
>>>>>
>>>>> Bruno
>>>>>
>>>>
>>>
>>>
>>> _______________________________________________
>>> Lisp Hug - the mailing list for LispWorks users lisp-hug@lispworks.com
>>> http://www.lispworks.com/support/lisp-hug.html
>>>
>>>
>>> _______________________________________________
>>> Lisp Hug - the mailing list for LispWorks users
>>> lisp-hug@lispworks.com
>>> http://www.lispworks.com/support/lisp-hug.html
>>
>>
>> _______________________________________________
>> Lisp Hug - the mailing list for LispWorks users
>> lisp-hug@lispworks.com
>> http://www.lispworks.com/support/lisp-hug.html
>
> --
> Br,
> /Alexey
_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html