Detect the type of an argument.
#1

Let's suppose I have the following function:

PHP код:
stock SomeFunc(const somestring[],  { _,Float }:...)
{
    
    return 
1;

Is there any way to detect what type of value is the second argument?

I want to detect if it's either a Float, string or an integer, don't ask why I want to do that.

Thanks for helping.
Reply
#2

pawn Код:
//To get a float:
if(tagof(getarg(index)) == tagof(Float:))
//To get a string:
else if(strlen(getarg(index)))
//Everything else
else
Reply
#3

Quote:
Originally Posted by Crayder
Посмотреть сообщение
pawn Код:
//To get a float:
if(tagof(getarg(index)) == tagof(Float:))
//To get a string:
else if(strlen(getarg(index)))
//Everything else
else
Ok I tried that and the following errors appeared:

PHP код:
stock SomeFunc(const somestring[],  { _,Float }:...)
{
    if(
tagof(getarg(1)) == tagof (Float:))//Line of error.
    
{
        
printf("%f"val);
    }
    else if(
strlen(getarg(1)))
    {
        
printf("%s"getarg(1));
    }
    else
    {
        
printf("%i"getarg(1));
    }
    return 
1;

ERROR code:

Код:
test.pwn(69) : error 001: expected token: ")", but found "("
test.pwn(69) : warning 215: expression has no effect
test.pwn(69) : error 001: expected token: ";", but found ")"
test.pwn(69) : error 029: invalid expression, assumed zero
test.pwn(69) : fatal error 107: too many error messages on one line
It seems that tagof() doesn't accept getarg.
How can I fix that?
Reply
#4

Show line 69
Reply
#5

Quote:
Originally Posted by Trollerz
Посмотреть сообщение
Show line 69
I already specified if you check:
PHP код:
if(tagof(getarg(1)) == tagof (Float:))//Line of error. 
Reply
#6

pawn Код:
new arg = getarg(bleh);

if(tagof(arg) == tagof (Float:))
tagof is a built in function like sizeof, it has very specific specifications. I didn't know it didn't accept function, now I see why Slice always assigned his vars before testing them with tagof.




ALSO: It looks like you may be trying to make a format type of function, and trust me, you're doing it way wrong. You need to use emit calls and shit to get it to use the actual format specifiers.
Reply
#7

Quote:
Originally Posted by Crayder
Посмотреть сообщение
pawn Код:
new arg = getarg(bleh);

if(tagof(arg) == tagof (Float:))
tagof is a built in function like sizeof, it has very specific specifications. I didn't know it didn't accept function, now I see why Slice always assigned his vars before testing them with tagof.




ALSO: It looks like you may be trying to make a format type of function, and trust me, you're doing it way wrong. You need to use emit calls and shit to get it to use the actual format specifiers.
I'm not trying to do that, I would use YSI\y_va instead with va_args<>


EDIT: tested the code now I get the following errors

PHP код:
sqltest.pwn(74) : error 035argument type mismatch (argument 1
Line of error:

PHP код:
else if(strlen(getarg(1))) 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)