PDA

View Full Version : Macros help


bgedition
25/08/2018, 09:24 AM
Hello guys,
Is there any way to get the optional parameters from a macro like in C++, with __VA_ARGS__?

To have this:

#define Func1(...) \
Func2(<Some constant like in C++ __VA_ARGS__ here>, 0)



Example:

ShowPlayerDialog(playerid, DIALOG, DIALOG_STYLE_LIST, Func1("HEADER"), Func1("WELCOME_MSG", GetName(playerid)), Func1("Go"), Func1("Quit"));


The intention here is that when the macro is called the 'Func2' will always have at least 2 arguments. Is there any way to do this in pawn?

Thanks,
Michael

bgedition
25/08/2018, 10:30 AM
http://forum.sa-mp.com/showthread.php?t=570933

Thank you. This helps but I am getting run time error. Since I am trying this with a function from your library. How can I add a default for va_args and va_format when none are specified.

bgedition
25/08/2018, 05:30 PM
Sorry, let me clarify. When nothing is specified for 'va_args<>', the server gets run time error 5 which is invalid memory access. How can I prevent this from happening. This is the reason to try with macros but it does not work as expected.

bgedition
25/08/2018, 11:06 PM
YSI v4