• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML [Solved] Is there an equivalent to #define name()?

H

Hieran_Del8

Guest
I'm interested in having inline evaluations, but I'm not sure if GMS has something similar to the define keyword in C.

In C, it would look something like:
C:
enum char_type {
    Word = 0x100,
    Digit = 0x200 | Word,
    Letter = 0x400 | Word,
    ...etc...
};
#define char_is_word(c) (c & char_type.Word)

...

if (char_is_word(ch)) {
    ...
}
Is there something similar in GML? Like this:
GML:
enum char_type {
    Word = 0x100,
    Digit = 0x200 | Word,
    Letter = 0x400 | Word,
    ...etc...
}
#macro char_is_word(c) (c & char_type.Word)

...

if (char_is_word(ch)) {
    ...
}
 
H

Hieran_Del8

Guest
Since you mention inline evaluation, perhaps you can investigate the use of gml_pragma("forceinline") in the function definition.
This is the closest alternative to a macro with parameters. Thanks for the lead!
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
GMEdit has an "#mfunc" preprocessor that helps with stitching macros together to achieve the effect of macros with arguments - e.g.
Code:
#mfunc char_is_word(c) (c & char_type.Word)
var z = char_is_word(c);
would be converted to and from
Code:
//!#mfunc char_is_word {"args":["c"],"order":[0]}
#macro char_is_word_mf0  (
#macro char_is_word_mf1  & char_type.Word)
var z = char_is_word_mf0 c char_is_word_mf1;
in saved code.
 
Top