Hi guys, it’s been actually quite some time I’ve been around. Nowadays I started to play with hxcs to implement another target for my framework. However before I delve into the research which seems sporadic at least and will probably result in a lot of try and see. I have a few specific questions about using Haxe with C#
Asynchronous stuff for example in Unity is quite a common occurrence how would you go on implementing code like this in haxe so it correctly transpiles to Unity C#?
Is there a way to inject a block of C# code into a haxe code? Instead of using multiple untyped calls?
What is the best way to call external C# code from within haxe code? Keeping in mind that in most cases I want to get a return value as well.
So if anyone can at least give me a hint it will definitely save me quite some time that I can spend on coding the actual framework and bringing haxe evangelism even further.
Thanks I am well aware of the -net-lib it would be downright impossible to use Unity with haxe if there wasn’t a way to use unityengine.dll however it doesn’t really answer any of the questions.
Unless you propose that I write down the code in question 1. outside of haxe and then use it inside haxe. Which is something I was thinking about as a last resort basically having all the async stuff in a unity plugin refactoring it into the classic event driven model javascript or as3 use.
The -net-lib option could be an answer to your question 3, but you’d have to compile that external C# code into a dll.
Classic haxe externs could be another way, that’s what I use (but in my configuration haxe only generates C# code, and I compile with dotnet cli; I don’t know if that matters or not for externs).
yield in C# transforms the function into a reentrant state machine (just like async/await) aka coroutine. Haxe does not natively support coroutines at the moment (although it’s planned), but as usual “there’s a macro for that!” IIRC there is one macro exactly for C#/Unity in the unihx project. It might be outdated but still a good start.
And -net-lib is just a fancy automatic extern loader. You can define the same extern types by hand, so you don’t technically need it to interop with C# code.
Thanks nadako I will check the macro, so far I’ve split my implementation into a managed dll plugin that handles all the coroutine stuff and haxe part which goes without.