SA-MP Forums Archive
[HELP] Macro. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [HELP] Macro. (/showthread.php?tid=354069)



[HELP] Macro. - paulor - 25.06.2012

I have a problem with macro, I tried many things and so I am here to ask for your help.
The macro is this:

pawn Код:
#define Test(%0,%1,%2) forward @%0(%2); public @%0(%2) { CallRemoteFunction(#%0,%1,%2); } forward %0(%2); public %0(%2)
I'm posting only one example of what happens with my macro!
If I do it this way:

pawn Код:
Test(FuncTest, "is", playerid, string[]) {
    printf("%i %s", playerid, string);
    return 1;
}
Of error, because as it is a macro parameter is replace all the past, then the replacement is CallRemoteFuction 'string[]' with this key and that the error, if anyone can help me I'm thankful!

Note: I've read and reread the topic ****** Pre-processor, but did not solve my problems for use with more than one parameter, such as integer, string and floating, so getting harder to fix!

Sorry if you do not understand something of what he said, because I am English and used the ****** translator to help me!


Re: [HELP] Macro. - iggy1 - 25.06.2012

I'm not actually sure what it is supposed to do. I spotted one bug straight away. Your calling a function with CallRemoteFunction but it has not yet been forwarded or defined.

EDIT: Also your macro Test is defined as having 3 params you supply 4 in your code.

This wont produce an error but it is still bugged because it's calling a function that does not exist. Problem is i have no idea what your trying to do.
pawn Код:
#define Test(%0,%1,%2) forward @%0(%2); public @%0(%2) { CallRemoteFunction(#%0,#%1,%2); } forward %0(%2); public %0(%2)

Test(FuncTest, "is", playerid)
{
    printf("is", playerid);
    return 1;
}



Re: [HELP] Macro. - paulor - 25.06.2012

Quote:
Originally Posted by iggy1
Посмотреть сообщение
I'm not actually sure what it is supposed to do. I spotted one bug straight away. Your calling a function with CallRemoteFunction but it has not yet been forwarded or defined.
No, it's expensive macro, will make a replacement. See:
pawn Код:
forward @FuncTest(playerid, string[]);
public @FuncTest(playerid, string[]) {
    CallRemoteFunction(#FuncTest, "is", playerid, string[]); //And what will replace it is with '[]' thus giving the compilation error!
}
forward FuncTest(playerid, string[]);
public FuncTest(playerid, string[]) {
    printf("%i %s", playerid, string);
    return 1;
}
After going to be built exactly this way.

@Edit

About the number of parameters does not affect anything, since starting the third parameter will be all in 2%. Test it this way and true that there is no problem with that:

pawn Код:
Test(FuncTest, "i", playerid) { //Compile
    printf("%i", playerid);
    return 1;
}

Test(FuncTest, "s", string[]) { //Does not Compile
    printf("%s", string);
    return 1;
}



Re: [HELP] Macro. - iggy1 - 25.06.2012

I edited my post maybe that helps you?

Quote:
Originally Posted by paulor
Посмотреть сообщение
No, it's expensive macro, will make a replacement. See:
Yeah i wasn't thinking straight.


Re: [HELP] Macro. - paulor - 25.06.2012

Quote:
Originally Posted by ******
Посмотреть сообщение
The last section actually covers exactly this.
It was there that I tried, but only works with one parameter, with several did not work, only compiled but did not work!

@Edit
Quote:
Originally Posted by iggy1
Посмотреть сообщение
I edited my post maybe that helps you?



Yeah i wasn't thinking straight.
No problem!


Re: [HELP] Macro. - paulor - 25.06.2012

Quote:
Originally Posted by ******
Посмотреть сообщение
Then you went wrong somewhere because I can assure that I've been using that exact technique for quite a while now in many places.
pawn Код:
#define string:
#define TYPES:%0) _:TYPE_N:TYPE_M:##%0,,)
#define TYPE_N:TYPE_M:##,,) "")
#define TYPE_M:##%2,%3) TYPE_0:TYPE_1:TYPE_E:##|||%2|||%3)
#define TYPE_0:TYPE_1:TYPE_E:#%0#%1|||%2[%8]%9|||%3,%4) TYPE_0a:TYPE_0b:#%0#%1|||%2|||%3,%4)
#define TYPE_0a:TYPE_0b:#%0#%1|||%9string:%2|||%3,%4) TYPE_0:TYPE_1:TYPE_E:#%0s#%1,%2|||%3|||%4)
#define TYPE_0b:#%0#%1|||%2|||%3,%4,%5) TYPE_0:TYPE_1:TYPE_E:#%0ai#%1,%2,%3|||%4|||%5)
#define TYPE_1:TYPE_E:#%0#%1|||%2|||%3,%4) TYPE_1a:TYPE_1b:#%0#%1|||%2|||%3,%4)
#define TYPE_1a:TYPE_1b:#%0#%1|||%6:%2|||%3,%4) TYPE_0:TYPE_1:TYPE_E:#%0i#%1,_:%2|||%3|||%4)
#define TYPE_1b:#%0#%1|||%2|||%3,%4) TYPE_0:TYPE_1:TYPE_E:#%0i#%1,%2|||%3|||%4)
#define TYPE_E:#%0#%1||||||%3) #%0#%1)
   
#define Test(%0,%1,%2) forward @%0(%2); public @%0(%2) { CallRemoteFunction(#%0,%1,TYPES:%2); } forward %0(%2); public %0(%2)
correct me if I'm wrong!


Re: [HELP] Macro. - paulor - 26.06.2012

Now I understand why that did not work, your macro returns the format and the vars, but still does not help me because I have to Add active more static parameters before those, I'll try to see if I can get an idea of starting your macro.


Re: [HELP] Macro. - paulor - 26.06.2012

Quote:
Originally Posted by ******
Посмотреть сообщение
Try this:

http://slice-vps.nl/ppg/

Put your code in there and click "Show preprocessed output" and you can see how all the macros expand one-by-one to give the outputs.

Edit: I ran those macros in the link I gave and discovered a possible problem - you are still explicitly passing "is" when you don't need to any more. EITHER generate the specifier automatically OR give it explicitly - don't do both.
pawn Код:
CallRemoteFunction(#FuncTest,_:TYPE_N:TYPE_0:TYPE_1a:TYPE_0a:TYPE_0b:#i#, playerid||| string|||,);
It was buggy, and that link you gave me, I do not remember?


Re: [HELP] Macro. - paulor - 26.06.2012

Quote:
Originally Posted by ******
Посмотреть сообщение
You do not remember what? And it's not buggy, you've not read the section in my other topic on strings properly.
Now I understand perfectly what you said, it is also I realized the error, but still buggy!

pawn Код:
CallRemoteFunction(#FuncTest,_:TYPE_N:TYPE_0:TYPE_1a:TYPE_0a:TYPE_0b:#i#, playerid||| string|||,);
He left it in the link you gave me ...


Re: [HELP] Macro. - paulor - 26.06.2012

Quote:
Originally Posted by ******
Посмотреть сообщение
If that's the result then you haven't understood perfectly what I said.
pawn Код:
#define string:
#define TYPES:%0) _:TYPE_N:TYPE_M:##%0,,)
#define TYPE_N:TYPE_M:##,,) "")
#define TYPE_M:##%2,%3) TYPE_0:TYPE_1:TYPE_E:##|||%2|||%3)
#define TYPE_0:TYPE_1:TYPE_E:#%0#%1|||%2[%8]%9|||%3,%4) TYPE_0a:TYPE_0b:#%0#%1|||%2|||%3,%4)
#define TYPE_0a:TYPE_0b:#%0#%1|||%9string:%2|||%3,%4) TYPE_0:TYPE_1:TYPE_E:#%0s#%1,%2|||%3|||%4)
#define TYPE_0b:#%0#%1|||%2|||%3,%4,%5) TYPE_0:TYPE_1:TYPE_E:#%0ai#%1,%2,%3|||%4|||%5)
#define TYPE_1:TYPE_E:#%0#%1|||%2|||%3,%4) TYPE_1a:TYPE_1b:#%0#%1|||%2|||%3,%4)
#define TYPE_1a:TYPE_1b:#%0#%1|||%6:%2|||%3,%4) TYPE_0:TYPE_1:TYPE_E:#%0i#%1,_:%2|||%3|||%4)
#define TYPE_1b:#%0#%1|||%2|||%3,%4) TYPE_0:TYPE_1:TYPE_E:#%0i#%1,%2|||%3|||%4)
#define TYPE_E:#%0#%1||||||%3) #%0#%1)
   
#define Test(%0,%1) forward @%0(%1); public @%0(%1) { CallRemoteFunction(#%0,TYPES:%1); } forward %0(%1); public %0(%1)

Test(FuncTest, playerid, string[]) {
    printf("%i %s", playerid, string);
    return 1;
}
output

pawn Код:
#define string:
#define TYPES:%0) _:TYPE_N:TYPE_M:##%0,,)
#define TYPE_N:TYPE_M:##,,) "")
#define TYPE_M:##%2,%3) TYPE_0:TYPE_1:TYPE_E:##|||%2|||%3)
#define TYPE_0:TYPE_1:TYPE_E:#%0#%1|||%2[%8]%9|||%3,%4) TYPE_0a:TYPE_0b:#%0#%1|||%2|||%3,%4)
#define TYPE_0a:TYPE_0b:#%0#%1|||%9string:%2|||%3,%4) TYPE_0:TYPE_1:TYPE_E:#%0s#%1,%2|||%3|||%4)
#define TYPE_0b:#%0#%1|||%2|||%3,%4,%5) TYPE_0:TYPE_1:TYPE_E:#%0ai#%1,%2,%3|||%4|||%5)
#define TYPE_1:TYPE_E:#%0#%1|||%2|||%3,%4) TYPE_1a:TYPE_1b:#%0#%1|||%2|||%3,%4)
#define TYPE_1a:TYPE_1b:#%0#%1|||%6:%2|||%3,%4) TYPE_0:TYPE_1:TYPE_E:#%0i#%1,_:%2|||%3|||%4)
#define TYPE_1b:#%0#%1|||%2|||%3,%4) TYPE_0:TYPE_1:TYPE_E:#%0i#%1,%2|||%3|||%4)
#define TYPE_E:#%0#%1||||||%3) #%0#%1)
   
#define Test(%0,%1) forward @%0(%1); public @%0(%1) { CallRemoteFunction(#%0,TYPES:%1); } forward %0(%1); public %0(%1)

forward @FuncTest( playerid, string[]); public @FuncTest( playerid, string[]) { CallRemoteFunction(#FuncTest,_:TYPE_N:TYPE_0:TYPE_1a:TYPE_0a:TYPE_0b:#i#, playerid||| string|||,); } forward FuncTest( playerid, string[]); public FuncTest( playerid, string[]) {
    printf("%i %s", playerid, string);
    return 1;
}
Please correct me if I'm wrong, because that's what I understood ...