-
Notifications
You must be signed in to change notification settings - Fork 5
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
C++ and Objective-C dependencies into C? #33
Comments
Hey @Lelelo1! You can use both C++ and Objective-C libraries from haxe – the haxe code in the watchOS project from earlier is translated into C++ through hxcpp so you can access anything you could normally use from C++, this includes objective-c things There's several ways of calling native code, one is you could simple emit C++ inline with your haxe untyped __cpp__('// this will be copied into the C++ file as-is, referencing this variable {0}', someVariable);
untyped __cpp__('printf("hello world %d", {0})', 1234); Or using the untyped __global__.printf("hello world %d", 1234); Of course you'll need to include header files to actually call the functions, so generally the best way is to make externs, where you can specify the required headers with here's an example for opengl hxcpp has some built-in externs for some common Objective-C types: I think when working with objective-c, it can help to add There's not much in the way of guides so the best way to learn right now is looking at the example code in hxcpp and asking in the forum At present HaxeCBridge doesn't help with calling native code from haxe, rather it helps with the inverse calling haxe code from native (more to come in the future tho!) Good luck, let me know how it goes! |
Is it possible to use a Objective-C library in haxe, output it in C++ and then used in a C# project, for instance? Or is that ability to use both C++ and Objective-c limited to the clock project? Thanks for the samples! |
Yes, it's possible to use Objective-C from haxe and then use the result from a C# project but you'll need to take care to understand how everything interconnects. Objective-C is largely syntax sugar over C++ if you rename your Once you've got that working and you've figured out externs so you can use the library you want in haxe, the next step is using the result from C#. C# can call native code compiled into a dynamic library, which is like an exe but you don't run it, instead it contains native code for other programs to use (extension is However, it depends on what platform you're using – if it's on mac it'll work, linux and window probably not because I've not yet tested those platforms. The changes requires to haxe-c-bridge will be minor, I just can't justify the time investment right now |
My use case is to embed a search engine that can be used in a mobile app, watch projects, potentially existing/upcoming ARGlasses as well. |
Hey
I got great instructions in the Haxe community forums, and it worked out well for Haxe code to compile and be used in a watchOS project in swift (via an Objective-C bridging header file).
I wonder though when it come to dependencies - is it restricted strictly C - or can Cpp be used like LucenePlusPlus in the watchOS projects as well?
My understanding so far about haxe in general is that the project becomes tied and dependent to for instance Java - if you use a Java dependency in Haxe. But I am inexperienced in the realm of C, C++ and Objective-C, and HaxeCBridge for that matter.
So can I pick out C++ and Objective C dependencies, and have it compiled into C still?
The text was updated successfully, but these errors were encountered: