Custom printf
#1

Hello!

I've been trying to make my own printf function that only gets called if debug mode is on. I however can't get them working with strings in it. I made them for integers and floats though but that's useless for me. I tried using getarg to use it at printf.

I read about making a #define to bypass this problem. It didn't work with the state machines at me. I'm not sure if it's even possible what I want but perhaps anyone knows more?

My code:
Код:
sprintf(const format[], {Float,_}:...) <debug:on>
{
	printf(format, getarg(1));
}
Reply
#2

You mean something like this?

pawn Код:
new
    FALSE = 0;
pawn Код:
#define ConsoleMsg(%0,%1) \
do \
{ \
  new \
      string[128]; \
  if(strlen(%0) > 0) \
  { \
    format(string, sizeof(string), %0, %1); \
    print(string); \
  } \
} \
while(FALSE)
Reply
#3

No, that does not support the state machine (<debugn>).

I use this code for a custom print function. I need one that formats the print too.

pawn Код:
sprint(const string[]) <debug:on>
{
    print(string);
}
Reply
#4

pawn Код:
#define DEBUG
pawn Код:
#if defined DEBUG
    #define debug(%1) printf(%1)
#else
    stock asd() { }
    #define debug(%1) asd()
#endif
Use debug() as printf() and when you don't want the debug messages coming up, simply comment out #define DEBUG.
Reply
#5

Sorry for not mentioning it but I'm using a /debug command to put it on and off.
Reply
#6

Quote:
Originally Posted by Don Correlli
You mean something like this?

pawn Код:
new
    FALSE = 0;
pawn Код:
#define ConsoleMsg(%0,%1) \
do \
{ \
  new \
      string[128]; \
  if(strlen(%0) > 0) \
  { \
    format(string, sizeof(string), %0, %1); \
    printf(string); \
  } \
} \
while(FALSE)
I suppose you meant printf(string); to be print(string);.
Reply
#7

Quote:
Originally Posted by Y_Leѕѕ
YSI has a custom format system written in PAWN - take a look in there (YSI_format.own) to see how that's done. Otherwise look in the last two pages of the code optimisations topic for discussion on possible solutions on this problem (passing variable arguments along to varadic functions), there is some nice data there on opcode manipulation, but no solutions yet.
I was reading Code Optimisations before I posted this and as you said there is no solution yet.

Only remaining 'solution' is defines then.

Thanks for the help.
Reply
#8

Quote:
Originally Posted by MenaceX^
I suppose you meant printf(string); to be print(string);.
Yes, edited.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)