kevinresol / napi

Native-friendly API for Haxe targets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Clarification: Communication between Haxe and native targets

Lotes opened this issue · comments

There are a few reasons for that. One of the major reasons is that in order to standardize across targets, Haxe has created it own set of data types, some of which has quite different interfaces than the equivalent types on the native side. And this make it not so easy to communicate between Haxe and the native targets.

Can you enumerate these differences? Where do you get into trouble? I am not aware of such problems. It would be helpful to see some examples.
And how would you solve these problems?

This is already elaborated in the Goals > Data Type section.

Ok, my problem was not the goal or target... it was about understanding Haxe, the source.
Haxe implements its own data structures, instead of reusing existing native solutions.
Now I understand, my mistake.

Then... how can this be done? Let's use the HashMap data type. In C# it is equal to IDictionary. Say you want to pass a list of named objects to a function. How do you write down the signature of this function in Haxe? In C# it has to result in "void func(IDictionary input)". Is that makeable in Haxe? Using a wrapper, you will have to pack your input dictionary first into the Wrapper type.

Another issue are exceptions. If you wrap a native class, you also have to wrap the exception.
Errors have to be reproducible for each target language.

Other thought: A macro in combination with metadata could be used to replace the proxy types with native types.

There is a "code" branch in this repo containing some PoC code, it should demonstrate some solutions to your questions.

The basic idea is to wrap Haxe's data type with native type. So that Haxe devs (library authors) handle haxe types and native devs (library users) handle native types.

You MUST write new data structures to ensure that behaviour is the same on all targets. That is already done by the Haxe team. If you want a native interface for the user, you also will have a native behaviour, which can differ from other target implementations. You could use an adapter to pack a dictionary into a hash map for inputs. Or for outputs you need to unpack your hashmap.

In no way i must do something :)

I want to help. I am just thinking a bit too loud. Of course you do not have to do anything.
I do not understand every trick in Haxe. I am reading your code, but it is hard to understand right now.