Extending classes doesn't work with nested #includes

Bugs that have been investigated and resolved somehow.

Moderator: GZDoom Developers

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.
User avatar
Xeotroid
Posts: 438
Joined: Sat Jun 23, 2012 7:44 am
Graphics Processor: nVidia with Vulkan support
Location: Czech Rep.

Extending classes doesn't work with nested #includes

Post by Xeotroid »

I'm using a ZScript library that comes with its own file full of #includes. I wanted to extend one of its classes so that updating the library wouldn't cause issues. I put my extensions into a separate file and #include it after the library. However, I receive an error that the class to be extended could not be found in the current translation unit.

This approach doesn't work:
Main ZScript file:

Code: Select all

#include "library/includes.zs"
#include "zscript/extensions.zs"
includes.zs:

Code: Select all

#include "library/library.zs"
Including library.zs directly in the main ZS file (omitting the library's includes file) works fine:

Code: Select all

#include "library/library.zs"
#include "zscript/extensions.zs"
For the modder it's easy to just put all #includes into one file, so the severity of this is more or less zero, and a fix doesn't sound worth the trouble (how often do you access your main ZScript file?), but I couldn't find a mention of this. Should it be clarified in the wiki article for future reference?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49098
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Extending classes doesn't work with nested #includes

Post by Graf Zahl »

That's due to how includes get processed in ZScript. This is not a preprocessor that pulls in the text. It merely adds the file to the end of the list of script files to compile.

What this means is that your files get processed in the wrong order, as
#include "zscript/extensions.zs"
gets parsed before
#include "library/library.zs"

and therefore compiled before the library. This is a technical limitation of how the compiler works so it's not really fixable.

Return to “Closed Bugs [GZDoom]”