So, a couple questions:
-
What are you proposing the correct syntax be here? I've tried several different things and none worked. I'm not sure what to name the selector, particularly since any additional
:in the name causes the function to need new arguments. -
Isn't my current function accepting the sender? See the first argument, which I ignore for now.
extern "C" fn speech_synthesizer_did_finish_speaking(_: &Object, _: Sel, _: BOOL) {
I'll address these, but note that nice code that doesn't work is worse than ugly code that does.
At least the latter can be fixed up.
I thought so, but I don't fully understand the new/alloc/init distinction. Figured I'd get this working then iterate on that. If it works, then I can clean it up until it doesn't, then roll the breaking change back.
If I do:
unsafe { msg_send![obj, setDelegate: delegate_obj] };
I get:
error[E0282]: type annotations needed
--> src/backends/ns_speech_synthesizer.rs:31:18
|
31 | unsafe { msg_send![obj, setDelegate: delegate_obj] };
| 41 caret characters consider giving `result` a type
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error
Also, the type annotation is required as per the docs:
// Even void methods must have their return type annotated
let _: () = msg_send![obj, release];
Could be that I'm misunderstanding something.
Yes I should, but code that doesn't work and cleans up after itself isn't really useful to me. Plus, there's going to be much more cleanup later when I'm managing a Vec<NSString> so might as well just do it all then once things work.
I've done a bit more digging, and it seems like the issue may be my lack of an NSRunLoop. Formerly my example did:
io::stdin().read_line(&mut _input)?;
to block and allow for text to speak. But apparently that doesn't let delegates run. Now I'm doing:
let run_loop: id = unsafe { NSRunLoop::currentRunLoop() };
unsafe {
let _: () = msg_send![run_loop, run];
}
// io::stdin().read_line(&mut _input)?;
The example still blocks, and Enter doesn't terminate anymore. So it seems like the NSRunLoop may be working. But the delegate still isn't running.
Thanks for any help. Ugh, this is way more painful than working with Microsoft's preview WinRT bindings in a VM was. ![]()