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

Instructions for services & multi targeting #2

Open
Lelelo1 opened this issue Apr 9, 2021 · 2 comments
Open

Instructions for services & multi targeting #2

Lelelo1 opened this issue Apr 9, 2021 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@Lelelo1
Copy link
Owner

Lelelo1 commented Apr 9, 2021

Instructions for services & multi targeting

Prepare native implementations extending the native class. Create an interface for what is needed by your application and let all the native implementations implement it.

// interface MyService
// MyNativeAImpl extends NativeA implements MyService
// MyNativeBImpl extends NativeB implements MyService
// MyNativeCImpl extends NativeC implements MyService

.. where A, B and C represents different platforms

Register during initialisation:

var constructor = () -> {
    var impl: INativeImpl = null;
            
    try {
        impl = new NativeImplA();
    }
    try {
        impl = new NativeImplB();
    }
    try {
        impl = new NativeImplC();
    }
    return impl;
}
Dep.registerNative("IService", constructor); // <---

Later anywhere in the code, get service with implementation of the runtime platform:

var service: IService = cast Dep.getNative("IService");
Sys.println(service.useSomethingNative());

See tests for dep usage: https://github.com/Lelelo1/seek-search/blob/master/src/DepTests.hx#L33

This is related to the Xamarin DependencyService, and was initially aimed to be used with #13. It can be tweaked and be used for internal haxe dependences

@Lelelo1 Lelelo1 added the documentation Improvements or additions to documentation label Apr 9, 2021
@Lelelo1
Copy link
Owner Author

Lelelo1 commented Apr 19, 2021

To setup haxe -> swift

  • Build watchos.xml eg two times:
haxelib install build.hxml
haxe build.hxml

Drag libMain.a and Main.h into the Xcode project,

When watchos: drag it to ProjectName WatchKit Extension set other linker flags to -lc++

Screenshot 2021-04-19 at 18 34 51

Create a bridging.h file in the folder of libMain.a and Main.h- set it in settings:

Screenshot 2021-04-19 at 18 40 14

And you should be able to run the xcode swift project

@Lelelo1 Lelelo1 closed this as completed Aug 28, 2021
@Lelelo1 Lelelo1 reopened this Aug 29, 2021
@Lelelo1
Copy link
Owner Author

Lelelo1 commented Sep 26, 2021

For .Net target:

....

I'ts that simple!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant