Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Objective-C support #142

Closed
yairchu opened this issue May 10, 2023 · 5 comments
Closed

Objective-C support #142

yairchu opened this issue May 10, 2023 · 5 comments

Comments

@yairchu
Copy link
Contributor

yairchu commented May 10, 2023

What would it take to support Objective-C too?

@bitonic
Copy link
Collaborator

bitonic commented May 10, 2023

I don't know -- I've never used Objective-C.

If its tooling is close to C/C++'s it would probably be pretty easy.

@yairchu
Copy link
Contributor Author

yairchu commented May 10, 2023

If its tooling is close to C/C++'s it would probably be pretty easy.

Yeah the tooling is close afaik. As a clang user I just compile a .m file instead of a .c.

Trying to look on inline-c's side but I'm having trouble following it.
I see that inlineCode creates a new ffiImportName to use, and I understand that emitVerbatim above it somehow emits the C code for it but I'm not really following how it works.

@yairchu
Copy link
Contributor Author

yairchu commented May 10, 2023

Ok I still don't know exactly how the internals work but I got it working!

Just changing TH.LangC to TH.LangObjc in initialiseModuleState makes Objective-C work.

Then I can do

cglCtx <- [C.block| void* {
    NSOpenGLContext* object = (NSOpenGLContext*) $(void* nsglCtx);
    return [object CGLContextObj];
}|]

Instead of

cglCtx <- [C.block| void* {
    id object = (id) $(void* nsglCtx);
    SEL selector = sel_registerName("CGLContextObj");
    Method method = class_getInstanceMethod(object_getClass(object), selector);
    IMP imp = method_getImplementation(method);
    return ((CGLContextObj (*)(id, SEL))imp)(object, selector);
}|]

How would we like it do work? In a separate module/package like C++? If you have a general design for how this should work then I can make a PR for it.

@bitonic
Copy link
Collaborator

bitonic commented May 10, 2023 via email

@bitonic
Copy link
Collaborator

bitonic commented May 20, 2023

Fixed by #143 .

@bitonic bitonic closed this as completed May 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants