Making libraries for non-Haxe projects

76 views
Skip to first unread message

hayo...@gmail.com

unread,
Nov 2, 2016, 2:43:33 AM11/2/16
to Haxe
Is it possible to build cross-platform libraries with Haxe, that could be used in non-Haxe projects?

What I see is that Haxe compiler generates whole application (checked Java, C++ and C#) with my files converted to target language as well as other files, which I believe are standard library + runtime. Even if I somehow compile all these files into a "library", possibly providing a "target language friendly" interface (non-Haxe), there will still be a problem with another library (say, also made by me) defining the same functions/types causing name clashes. So ideally, I'd like "runtime" to exist in a private namespace/package.

I tried dce=no and looking at generated files it seems it would let me turn common code into a separate shared library, but I have no idea how stable it would be (will one library compiled against one "runtime" be compatible with a newer version?).

Additionally, if creating libraries is possible, should I be concerned with some global state that needs to be initialized or anything?

Thank you!

Hugh

unread,
Nov 3, 2016, 12:26:02 AM11/3/16
to Haxe
I think the easiest solution is to put the haxe classes inside the library namespace in the first place.
So your library would "own" this namespace, and it is understood that applications should not use it.
Java uses the "com." style namespaces to avoid global clashes, but I don't think you need to go to this extreme.

Hugh

hayo...@gmail.com

unread,
Nov 3, 2016, 2:40:19 AM11/3/16
to Haxe
Thanks, Hugh! I am completely new to Haxe... So maybe I misunderstand you here.

So, yes, library will have its own namespace - that's for sure. However, there still will be Haxe library (e.g. haxe/* on Java) and other libraries too, with their own "global" packages/namespaces. Can I control a parent namespace/package for all libraries via compiler's command-line arguments? I could use some refactoring tool to move classes later, but I wonder if there's an easier way.

Slava
Reply all
Reply to author
Forward
0 new messages