Why doesn't the preprocessor substitude a macro as a prefix of an event's name?
Moderator: Forum Moderators
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.
-
- Posts: 582
- Joined: August 4th, 2019, 5:27 pm
- Contact:
Why doesn't the preprocessor substitude a macro as a prefix of an event's name?
Hi everyone! Got a question about how the preprocessor works.
Let's say I have the following code
I expected that {TEST} will be macrosubstituted and I'll get an event with name "Test my event", instead I got an error during the preprocessing stage saying "Unexpected characters after variable name (expected , or =)" at the line with "name={TEST} my event".
It only works if I make {TEST} the suffix, so
this works.
But if I put my event inside a macro with PREFIX being a macro-parameter instead of a full-fledged macro, it works in the prefix form too
this works too.
I don't really understand why the first snippet doesn't work. I expected the preprocessor to substitude the macro independently of where it is in the line
Let's say I have the following code
Code: Select all
#DOESN'T WORK FOR SOME REASON
#define TEST
Test
#enddef
[event]
name={TEST} my event
...
[/event]
It only works if I make {TEST} the suffix, so
Code: Select all
#works
#define TEST
Test
#enddef
[event]
name=my event {TEST}
...
[/event]
But if I put my event inside a macro with PREFIX being a macro-parameter instead of a full-fledged macro, it works in the prefix form too
Code: Select all
#somehow works too
#define MY_EVENTS PREFIX
[event]
name={PREFIX} first_event
...
[/event]
#enddef
{MY_EVENTS Test}
I don't really understand why the first snippet doesn't work. I expected the preprocessor to substitude the macro independently of where it is in the line
Co-founder and current maintainer of IsarFoundation, Afterlife Rated and overall Wesnoth Autohost Project
MP versions of classical mainline campaigns: UtBS, TRoW, SotA
Developer and maintainer of my fork of World Conquest, Invincibles Conquest II
MP versions of classical mainline campaigns: UtBS, TRoW, SotA
Developer and maintainer of my fork of World Conquest, Invincibles Conquest II
- Spannerbag
- Posts: 761
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: Why doesn't the preprocessor substitude a macro as a prefix of an event's name?
I think you're embedding a trailing carriage return in the macro.dwarftough wrote: ↑August 22nd, 2024, 11:00 am Hi everyone! Got a question about how the preprocessor works.
Let's say I have the following code
Code: Select all
#DOESN'T WORK FOR SOME REASON #define TEST Test #enddef
Code: Select all
#DOESN'T WORK FOR SOME REASON
#define TEST
Test#enddef
Cheers!
-- Spannerbag
-
- Posts: 582
- Joined: August 4th, 2019, 5:27 pm
- Contact:
Re: Why doesn't the preprocessor substitude a macro as a prefix of an event's name?
Spannerbag wrote: ↑August 22nd, 2024, 11:39 amShould work as you want.Code: Select all
#DOESN'T WORK FOR SOME REASON #define TEST Test#enddef
Indeed, that works! Thanks a lot!gnombat wrote: ↑August 22nd, 2024, 12:35 pm This is documented here:
PreprocessorRef#Whitespace_in_Macros
Co-founder and current maintainer of IsarFoundation, Afterlife Rated and overall Wesnoth Autohost Project
MP versions of classical mainline campaigns: UtBS, TRoW, SotA
Developer and maintainer of my fork of World Conquest, Invincibles Conquest II
MP versions of classical mainline campaigns: UtBS, TRoW, SotA
Developer and maintainer of my fork of World Conquest, Invincibles Conquest II