I recently discovered Haxe and I want to prototype something in it to see its capabilities. I like to do things myself and I am already used to working with OpenGL.
I want to create my own port for the OpenGL specification but I don’t have the desire to write every existing GL function or typedef by hand. Luckily OpenGL provides a spec XML file that I found out how to parse through a macro. I also found out how to create functions in an empty type by using @:build(…call to my macro…) . Where I am stuck at is adding the typedef’s for the OpenGL language. I wanto to be able to generate with a macro a typedef similar to this:
typedef GLenum = Int;
… but with a macro. I tried build macros and initialization macros but there is not enough documentation or articles on the subject of how to create custom types or classes.
These are nice! More like I wanted to toy around with the macros and automatic type generation (from what I understand one of the strong points of Haxe).
I even consider to actually write a parser for C++ headers (using libclang) that would produce an intermediate json/xml document that haxe could then use for generating the glue code for calling the native methods.
Well, I couldn’t get intellisense working. I tried vscode and haxe develop which are the two IDE environments I am willing to work with.
The compiler doesn’t complain and successfully replaces calls for example to GLint with whatever I put to be the alias. Its just that I don’t get any suggestions while typing or when I request using the ctrl + space shortcut.
EDIT: Also I found out that it shows documentation if I set the doc field and hove over a typed field. I just don’t get the suggestion.
EDIT 2: If I generate a field for the OpenGLContext class (from the example) I do get intellisense for the field. I just wanted to metion that its wierd I don’t get it for typedefs.
Your macro might be run too late, you should instead use an init macro, that way all of your types will be available as soon as the compilation starts, which should help with ide support.
An alternative would be to generate haxe files from your xml ahead of time, instead of running the macro at each compilation. Less flexible but faster compilation.
Hi,
could it be the unspecified build order that prevents it? I’ve had quite a project working for months since inception, only to discover it doesn’t compile at all on another machine. It turned out I unknowingly relied on a specific build order which was different on the new machine.
The solution was to have two passes of compilation. One that does only generate .hx files (and write them to disk) skipping actual compilation, followed by the actual compilation pass which skips the .hx file generation. All controlled by the presense/absence of a compile flag.
P. S. I later heard about Syntax Hub but haven’t tried it out yet.