lukaskollmer / objc

🔮 NodeJS ↔ Objective-C bridge (experimental)
MIT License
98 stars 20 forks source link

Clarification of use of offsets in type encoding in custom classes #4

Closed jmbldwn closed 6 years ago

jmbldwn commented 6 years ago

Again, great package! This might just be a clarification, but as I'm trying to figure out why my delegate doesn't work, I'm noticing a few things I don't entirely understand that might help me figure it out.

I've created a custom class so I can register a delegate. I've used the FileManagerDelegate example as a template for my own.

Your readme mentions:

Note: You might have to specify individual offsets in the type encoding, see this example.

I'd love to know what you mean by this, and what it means for how I define my delegate.

For reference, I'm creating a delegate for AVCaptureVideoDataOutputSampleBufferDelegate. One thing I noted is the use of the term 'c40' for the return value of the FileManagerDelegate example, which is a bool. I assume this means bool and char are the same, but not sure what the 40 is for.

This may not be my problem, but it might be nice to have this be clearer in the docs.

const AVCaptureVideoDataOutputSampleBufferDelegate = objc.createClass(
    'AVCaptureVideoDataOutputSampleBufferDelegate',
    'NSObject',
    {
        'captureOutput:didOutputSampleBuffer:fromConnection:': (
            self,
            cmd,
            captureOutput,
            sampleBuffer,
            connection
        ) => {
            console.log(
                '-[AVCaptureVideoDataOutputSampleBufferDelegate captureOutput:didOutputSampleBuffer:fromConnection:]'
            );
            return 1;
        },

        _encodings: {
            'captureOutput:didOutputSampleBuffer:fromConnection:': [
                'v',
                ['@0', ':8', '@16', '@24', '@32']
            ]
        }
    }
);
jmbldwn commented 6 years ago

I think I figured out I should be using 'v' for void return value. I'd still like to understand the offset notation, though.

lukaskollmer commented 6 years ago

have a look at this: https://gcc.gnu.org/onlinedocs/gcc-6.1.0/gcc/Method-signatures.html

jmbldwn commented 6 years ago

Thanks for that. It looks like the correct encoding for

- (void)captureOutput:(AVCaptureOutput *)output 
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer 
       fromConnection:(AVCaptureConnection *)connection;

is

        _encodings: {
            'captureOutput:didOutputSampleBuffer:fromConnection:': [
                'v40',
                ['@0', ':8', '@16', '@24', '@32']
            ]
        }