Detect the type of an argument. -
Magic_Time - 30.08.2015
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.
Re: Detect the type of an argument. -
Crayder - 30.08.2015
pawn Код:
//To get a float:
if(tagof(getarg(index)) == tagof(Float:))
//To get a string:
else if(strlen(getarg(index)))
//Everything else
else
Re: Detect the type of an argument. -
Magic_Time - 30.08.2015
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?
Re: Detect the type of an argument. -
Trollerz - 30.08.2015
Show line 69
Re: Detect the type of an argument. -
Magic_Time - 30.08.2015
Quote:
Originally Posted by Trollerz
Show line 69
|
I already specified if you check:
PHP код:
if(tagof(getarg(1)) == tagof (Float:))//Line of error.
Re: Detect the type of an argument. -
Crayder - 30.08.2015
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.
Re: Detect the type of an argument. -
Magic_Time - 30.08.2015
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 035: argument type mismatch (argument 1)
Line of error:
PHP код:
else if(strlen(getarg(1)))