without explicit #undef

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
User avatar
Gwledig
Posts: 502
Joined: March 30th, 2009, 5:10 pm
Location: UK

without explicit #undef

Post by Gwledig » July 14th, 2019, 10:36 am

Hi I am trying to figure out why I have a lot of these errors eg
warning preprocessor: Redefining macro CALCULATE_INCOME_BONUS_WESNOTH without explicit #undef
Does this mean I need an ID or something in these macros?

here is an example of the log

Code: Select all

20190714 11:11:17 warning preprocessor: Redefining macro CALCULATE_INCOME_BONUS_WESNOTH without explicit #undef at ~add-ons/Conquestplus/scenarios/conquest_wesnoth_winter.cfg:593
    included from ~add-ons/Conquestplus/_main.cfg:7
previously defined at ~add-ons/Conquestplus/scenarios/conquest_wesnoth_II.cfg:599
    included from ~add-ons/Conquestplus/_main.cfg:7
20190714 11:11:18 warning preprocessor: Redefining macro CALCULATE_INCOME_BONUS_DESERT_EMPIRES without explicit #undef at ~add-ons/Conquestplus/scenarios/desert_empires2.cfg:1762
    included from ~add-ons/Conquestplus/_main.cfg:7
previously defined at ~add-ons/Conquestplus/scenarios/desert_empires.cfg:1764
    included from ~add-ons/Conquestplus/_main.cfg:7
20190714 11:11:20 warning preprocessor: Redefining macro CALCULATE_INCOME_BONUS_FAERIE without explicit #undef at ~add-ons/Conquestplus/scenarios/pirate_islands.cfg:823
    included from ~add-ons/Conquestplus/_main.cfg:7
previously defined at ~add-ons/Conquestplus/scenarios/faerie.cfg:837
    included from ~add-ons/Conquestplus/_main.cfg:7
20190714 11:11:28 warning preprocessor: Redefining macro ABILITY_LEADERSHIP_LEVEL_1 without explicit #undef at ~add-ons/Conquestplus_space/utils/abilities.cfg:14
    included from ~add-ons/Conquestplus_space/_main.cfg:5
previously defined at core/macros/deprecated-utils.cfg:63
    included from core/_main.cfg:18
    included from _main.cfg:18
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)

User avatar
Ravana
Moderator
Posts: 2155
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: without explicit #undef

Post by Ravana » July 14th, 2019, 11:29 am

It says you define macro with same name at
~add-ons/Conquestplus/scenarios/conquest_wesnoth_winter.cfg:593 and
~add-ons/Conquestplus/scenarios/conquest_wesnoth_II.cfg:599

It works as warning in case you unintentionally used already existing macro name.

If you want to silence that warning, #undef CALCULATE_INCOME_BONUS_WESNOTH.

User avatar
Gwledig
Posts: 502
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: without explicit #undef

Post by Gwledig » July 14th, 2019, 5:53 pm

so I have a leadership macro to replace the deprecated version

Code: Select all

#define ABILITY_LEADERSHIP_LEVEL_1
# included in an [abilities] clause
[leadership]
value=25
affect_allies=yes
affect_enemies=no
affect_self=no
cumulative=no
name= _ "Leadership"
female_name= _ "Female^Leadership"
description= _ "This unit can lead your own units that are next to it, making them fight better.
Adjacent own units of lower level will do more damage in battle. When a unit adjacent to, of a lower level than, and on the same side as a unit with Leadership engages in combat, its attacks do 25% more damage times the difference in their levels."
[affect_adjacent]
adjacent=n,ne,se,s,sw,nw
[/affect_adjacent]
[/leadership]
#enddef
then at the end of the abilities.cfg under the above I added
#undef ABILITY_LEADERSHIP_LEVEL_1
However then ruuning the mod I get a load of errors saying the leadership macro is now missing and the log says
20190714 18:48:19 error preprocessor: Macro/file 'ABILITY_LEADERSHIP_LEVEL_1' is missing
at ~add-ons/Chaoz/utils/menu_macro_missile.cfg:129
included from ~add-ons/Chaoz/_main.cfg:5
included from ~add-ons/Chaoz/utils/menu_spells_law.cfg:4
included from ~add-ons/Chaoz/_main.cfg:5
included from ~add-ons/Chaoz/utils/menu_spells.cfg:80
included from ~add-ons/Chaoz/_main.cfg:5
included from ~add-ons/Chaoz/scenarios/Chaoz_2p_Hamlets.cfg:15
included from ~add-ons/Chaoz/_main.cfg:7
Just wondering if I am doing this #undef thing properly?
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)

User avatar
Ravana
Moderator
Posts: 2155
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: without explicit #undef

Post by Ravana » July 14th, 2019, 6:02 pm

After you undef it, it does not exist anymore. So you want to undef it at correct time only. Compare https://github.com/ProditorMagnus/Agele ... fg#L84-L94

User avatar
Gwledig
Posts: 502
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: without explicit #undef

Post by Gwledig » July 14th, 2019, 7:07 pm

Hm can't see #undef anywhere in that code...
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)

User avatar
Ravana
Moderator
Posts: 2155
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: without explicit #undef

Post by Ravana » July 14th, 2019, 7:11 pm

First and last line of the snippet include files which have undef. This itself shows the order in which they are included.

I am not completely sure if it is important to put core macros back after processing my addon, but better be safe.

User avatar
Gwledig
Posts: 502
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: without explicit #undef

Post by Gwledig » July 14th, 2019, 9:40 pm

hm I'm not sure I can undefine most of these macros e.g. leadership replacement is used at any time of the game... as is the bonus gold stuff (used to calculate bonus gold when all vilas in a 'region' are captured).
I there not a way of supressing this/specific kinds of errors? Just good to keep log clean so I can see any proper issues vs spamming this all thro the log...
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)

User avatar
Ravana
Moderator
Posts: 2155
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: without explicit #undef

Post by Ravana » July 14th, 2019, 9:52 pm

If you for some reason want to re-use core macro name, then steps are
1) #define content of old macro under new name
2) #undef old name
3) #define new content under old name
4) load your addon
5) #undef old name
6) #define old saved content under old name
7) #undef new name

It is usually much easier to use different name.

If it is your own macro, then feel free to #undef it right before #define.

User avatar
Gwledig
Posts: 502
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: without explicit #undef

Post by Gwledig » July 14th, 2019, 11:20 pm

thanks that seems to sort out the #undef error for leadership, which I'd added as a custom macro as it's being deprecated... simply by adding #undef MACRONAME before the macro... presumably disabling the core one I spose..
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)

User avatar
octalot
Developer
Posts: 350
Joined: July 17th, 2010, 7:40 pm

Re: without explicit #undef

Post by octalot » July 15th, 2019, 12:07 am

Gwledig wrote:
July 14th, 2019, 9:40 pm
hm I'm not sure I can undefine most of these macros e.g. leadership replacement is used at any time of the game...
The #define statements are handled by the preprocessor, which happens when Wesnoth says "Reading files and creating cache". At this point, all of the WML files are merged in to a single file, and any #defined macros are expanded. All of the #defines have been replaced before any of your WML is run.

User avatar
josteph
Developer
Posts: 631
Joined: August 19th, 2017, 6:58 pm

Re: without explicit #undef

Post by josteph » July 15th, 2019, 12:41 pm

Ravana wrote:
July 14th, 2019, 9:52 pm
If you for some reason want to re-use core macro name, then steps are
No, please don't do this. If the content of the macro in core changes, anything that uses your addons will then use the old version of the core macro, which could cause all sorts of errors. As Ravana says, just define your own macros with different names.

User avatar
Ravana
Moderator
Posts: 2155
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: without explicit #undef

Post by Ravana » July 15th, 2019, 3:45 pm

Gwledig wrote:
July 14th, 2019, 11:20 pm
thanks that seems to sort out the #undef error for leadership, which I'd added as a custom macro as it's being deprecated... simply by adding #undef MACRONAME before the macro... presumably disabling the core one I spose..
That is exactly the worst thing to do, that could break all the addons that are loaded after yours.

User avatar
Gwledig
Posts: 502
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: without explicit #undef

Post by Gwledig » July 15th, 2019, 4:13 pm

Thanks will rename the local one vs use of undef...
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)

User avatar
josteph
Developer
Posts: 631
Joined: August 19th, 2017, 6:58 pm

Re: without explicit #undef

Post by josteph » July 15th, 2019, 7:38 pm

I wonder if the preprocessor should implicitly start a macros scope when it starts reading an addon and end that scope when it finishes reading the addon. This way, #define's from one addon will never be in force for other addons, unless the second addon explicitly does {~add-ons/FirstAddOn/foo.cfg}.

User avatar
Ravana
Moderator
Posts: 2155
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: without explicit #undef

Post by Ravana » July 15th, 2019, 7:44 pm

I tried out that they actually are in separate scope. So we can just override it however we want.

Post Reply