[SOLVED] Why can't I --macro include() Kha, Iron, or Armory (Help me fix modding!)

So I am working on getting modding working for Armory, but I am having a small issue. I want Armory mods to have have the ability to call the Kha, Iron, and Armory APIs. The way I do that is by Kha, Iron, and Armory being built like normal into the main game, while mods include the APIs as externs. This means that when mods are built, they include only the code that makes up the mod functionality and not the entire Kha and Iron code along with it. This work mostly great. The problem that I have is that if the main game doesn’t use a class from Iron, for example, Haxe won’t build that class at all and then when the mod needs to use that class, it won’t exist.

This is actually similar to the problem you have when building Haxe documentation, where you want to generate the .xml class reference file for a library, but by default haxe won’t include classes that aren’t used in a program. The solution is to use the include() macro in your .hxml file. This is supposed to make Haxe include the whole package in the compliation, regardless of whether or not it is actually used ( reference ). For some reason, though, I have problems adding --macro include("iron"). Each different library has it’s own reason for failing the build. To boil it down to the smallest number of variables I tried generating the documentation XML as a test:

-cp Kha/Sources
-cp Kha/Backends/Krom
-cp armory/Sources
-cp iron/Sources
--macro include("iron")
--no-output
-D doc-gen
-xml krom-doc.hxml
-js krom.js.test

Running this produces:

--macro:1: character 1 : Invalid package : iron.data should be <empty>

Including Kha results in:

Kha/Sources/kha/graphics4/hxsl/Eval.hx:108: characters 36-41 : Unexpected final

And including Armory results in:

Kha/Sources/kha/graphics4/hxsl/Eval.hx:108: characters 36-41 : Unexpected final

In practice I need to be able to add the following lines to a Khafile.js and have it work:

project.addParameter("--macro include('armory')");
project.addParameter("--macro include('kha')");
project.addParameter("--macro include('iron')");

Does anybody have any idea why I’m having issues with this? The doc generation at least should work somehow. How else can @lubos and @RobDangerous generate their API documentation sites?

Note: On a sidenote I am actually able to do project.addParameter("--macro include('armory.logicnode')"); and it works as expected. I don’t know what the correlation is.

I think I’ve figured it out! Apparently, because the include macro will go and include, by default, every file that ends in .hx in your classpath, the imports fail because there are some broken classes in each package that just aren’t used at the moment. Therefore, when I try to import the packages, I get errors from all of those classes that aren’t working or aren’t needed for the game. All I had to do to fix this was add exclusions for every class or package that threw errors. The result is:

project.addParameter("--macro include('armory', ['armory.system.*'])");
project.addParameter("--macro include('kha', ['kha.graphics4.hxsl.*', 'kha.network.NodeProcessClient', 'kha.HaxelibRunner', 'kha.internal.*'])");
project.addParameter("--macro include('iron', ['iron.data.GreasePencilData'])");

Well that was a lot simpler than it could have been. I’ve still got to do some testing, but I think that will fix it. :smiley: :tada:

1 Like