-
Notifications
You must be signed in to change notification settings - Fork 0
Informations
A Macro works like a queue and at the same time a redirector, for example, instead of use forward
and public
we set a macro that execute both, so we don't need to type all that stuff...
Before we set up the macro we have to call both forward
and public
to cast:
forward someFunction(playerid);
public someFunction(playerid){
//your function....
}
After we set up a macro we can just call the trigger, and the macro will take care of declarations...
PFWD::someFunction(playerid){
//your function....
}
A macro is setting up using a #define, for example, the PFWD macro is:
#if !defined PFWD
#define PFWD::%0(%1) forward %0(%1);\
public %0(%1)
#endif
→ Why is that public function doesn't end with a ';' or a '{...}'? ←
Because we need to let the function open, so we can open and close brackets '{' at the beggining and at the end '}' when the macro has been called, directly on the code, at this example macro is working pretty much like a copy and paste, imagine that: When you start compiling, the compiler will made a search and replace, where PFWD is gonna be replaced by forward and public, if you close/open brackets or something like that, compiler will do this:
forward myFunction(something);
public myfunction(something){}{
// your code....
}
Code will broke! Also, if you pop something that "isn't right" you be contemplated with a error!
→ We can do more difficult things with macros? ←
Sure you can, go to 'art_definitions.inc' and check that bloody hell 'is_null' macro ;D (And yes, that is a medium one, not even harder...).
→ Does the macro consume more of the server's processing? ←
No, #defines are pretty much static, we just set a number functions to be executed. Like a normal function calling other function. They just redirect us to what we need!