GML Multi-pass Macro expansion not fully working?

D

Deleted member 45063

Guest
Hello GMC,

When using macros I expect that they will be fully expanded before any attempts on actual compilation of the GML code (like separate preprocessor and compilation phases). However I noticed that it doesn't seem to always be the case. For example:

Create a new project and in the room creation event of the only room add:
Code:
#macro HELLO_WORLD "Hello World!"
#macro MESSAGE HELLO_WORLD

#macro LOG_FUNCTION show_debug_message
#macro DEBUG LOG_FUNCTION

DEBUG(MESSAGE);
Looking at the code I would expect it to be expanded to:
Code:
show_debug_message("Hello World!");
Yet it gives a compile-time error:
Code:
Creation Code in Room: room0 at line 7 : unknown function or script LOG_FUNCTION
But if we change it to:
Code:
#macro HELLO_WORLD "Hello World!"
#macro MESSAGE HELLO_WORLD

#macro LOG_FUNCTION show_debug_message
#macro DEBUG LOG_FUNCTION

LOG_FUNCTION(MESSAGE);
Then it compiles and behaves as expected. This means that multi-pass macro expansion does work just that it doesn't seem to be consistent in all scenarios.

I was wondering if this is to be expected of if it is indeed a bug with the macro system.

Runtime Version: 2.2.4.374
 

samspade

Member
I can confirm that it works that way for me as well. I'm not sure if it is a bug or as expected. Reading the manual doesn't seem to help.

The one thing that stands out is that "Hello World!" makes it through while show_debug_message does not.

I tested it with a few other things and it seems like function and script references don't make it through but other values, including function and script calls, will. However, you can do it with script execute which only works with scripts (not functions):

Code:
#macro HELLO_WORLD "Hello World!"
#macro MESSAGE HELLO_WORLD

#macro LOG print
#macro DEBUG LOG

script_execute(DEBUG, MESSAGE);
So the above works, where print() is a function that simply wraps show_debug_message.

So it seems like for whatever reasons functions and script references don't make it through while other things can. This seems like a bug, or at least an oversight to me.
 
D

Deleted member 45063

Guest
I can confirm that it works that way for me as well. I'm not sure if it is a bug or as expected. Reading the manual doesn't seem to help.

The one thing that stands out is that "Hello World!" makes it through while show_debug_message does not.

I tested it with a few other things and it seems like function and script references don't make it through but other values, including function and script calls, will. However, you can do it with script execute which only works with scripts (not functions):

Code:
#macro HELLO_WORLD "Hello World!"
#macro MESSAGE HELLO_WORLD

#macro LOG print
#macro DEBUG LOG

script_execute(DEBUG, MESSAGE);
So the above works, where print() is a function that simply wraps show_debug_message.

So it seems like for whatever reasons functions and script references don't make it through while other things can. This seems like a bug, or at least an oversight to me.
Thanks for confirming the behaviour. It is exactly because the "Hello World!" goes through that I consider this to not be intentional. Although with inlining you don't really need macro-based function definition but it would still be nice to have the expansion work as expected. Furthermore, I know that the script_execute version works but it adds an extra layer of indirection where using the macro approach you'd be calling the function directly.
 
Top