Lelelo1 / seek-search

Haxe embedded client search
0 stars 0 forks source link

Instructions for services & multi targeting #2

Open Lelelo1 opened 3 years ago

Lelelo1 commented 3 years ago

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 commented 3 years ago

To setup haxe -> swift

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 commented 3 years ago

For .Net target:

....

I'ts that simple!