• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

 Macro inconsistencies

GMWolf

aka fel666
So i was playing around with macros, Realizing that they are true, preprocessor macros, i tried splitting expressions into multiple macros, Like so:
Code:
#macro FOO irandom( //First 1/2
#macro BAR 100) //Second 1/2


//This is legal, and works just fine
var a =  FOO BAR;
show_message(a);

//This wont work. IDE shows error
show_message(FOO BAR);
However, The IDE doesnt always like it, as shown in the code snippet.

I love being able to split expressions, it allows you to 'hack' in new syntax, so i would love it to stay that way.
What would be great is for it to be fixed in the code editor, when used as an argument.

Having worked on parsers, im pretty sure i understand where it gets stuck. Perhaps feeding the preprocessed code to the syntax checker would fix this?
 

GMWolf

aka fel666
What other cases?
for example:
Code:
#macro foo irandom
#macro bar (100)

show_message(foo + bar);
But that makes sense. it shouldnt work.

Macros will just get replaced with the macro before being compiled.

The problem is with the syntax checker that treats macors as variables (or identifiers).
 

psyke

Member
Yeah, I guess you need to add "(" so the compiler can recognize the "irandom" as a function and not a variable, but I don't think this is a problem for what you're doing, or is it?
 

GMWolf

aka fel666
Yeah, I guess you need to add "(" so the compiler can recognize the "irandom" as a function and not a variable, but I don't think this is a problem for what you're doing, or is it?
Well, for now im mainly playing around with it.
but if this is legal in GM:
Code:
#macro FOO irandom( //First 1/2
#macro BAR 100) //Second 1/2
//This is legal, and works just fine
var a =  FOO BAR;
show_message(a);
So should this
Code:
#macro FOO irandom( //First 1/2
#macro BAR 100) //Second 1/2

//This wont work. IDE shows error
show_message(FOO BAR);
 

Mike

nobody important
GMC Elder
They are not technically pre-procressor directives. They are parse-tree node replacements, and as such will not work "quite" the way you're expecting, and probably won't hook together for compilation properly for this kind of patching.
 

GMWolf

aka fel666
They are not technically pre-procressor directives. They are parse-tree node replacements, and as such will not work "quite" the way you're expecting, and probably won't hook together for compilation properly for this kind of patching.
Sooo, you are saying this is how it is and won't change?!

That's fine with me as it does work as intended. I was pushing it to see how far you could go...
 

Mike

nobody important
GMC Elder
No....just how it is just now. We don't really want to make them full blown C++ style macros, because it's the first rider of the apocalypse in terms of code readability :)
 
Top