Raised This Month: $ Target: $400
 0% 

tagof tests


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Longcat
Junior Member
Join Date: Jan 2015
Location: as_oilrig
Old 01-30-2015 , 14:08   tagof tests
Reply With Quote #1

Hello.

There is an interest connected with the tagging system of PAWN.

There is a tagof operator, but I cannot understand how does it work.

Quote:
tagof s
results in the a unique number that represents the tag of the variable,
the constant, the function result or the tag label.
When used in a default value for a function argument, the expression
is evaluation at the point of the function call, instead of in the
function denition.
The context is the following: when we use a function like this one:
Code:
func({Float, bool, _}: x)
{
    ...
}
we may have a question about an actual tag of x. In the tutor it is claimed that a following construct should be used:
Code:
func({Float, bool, _}: x, type_x = tagof x)
{
    ...
}
I checked this with a following combination:
Code:
public timed(id)
{    
    new Float: x = 3.0;
    new bool: y = true;
    new z = 4;
    
    func1(x, y);
    func1(y, y);
    func1(z, y);
}

func1({Float, _}: a, type_a = tagof a)
{
    new Float: flt, bool: bl, int;
    
    switch(type_a)
    {
        case tagof(flt):     log_amx "a is float";
        case tagof(bl):        log_amx "a is bool";
        case tagof(int):    log_amx "a is int";
    }
}
The output looks like:
Code:
a is int
a is int
a is int
So, what is the right usage of tagof?
Thanks.

Last edited by Longcat; 01-30-2015 at 14:09.
Longcat is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-30-2015 , 15:04   Re: tagof tests
Reply With Quote #2

It's probably kind of bugged, and also tricky.

To fix tagof inside function header, you need to use a macro so compiler computer the actual tag value, something like:

Code:
#define do_test(%1) func(.type = tagof %1) public timed() {         new Float:x = 3.0;     new bool:y = true;     new z = 4;     do_test(x);     do_test(y);     do_test(z); } func(type) {     new Float:a, bool:b, c;     switch(type)     {         case tagof(a): log_amx "a is float";         case tagof(b): log_amx "a is bool";         case tagof(c): log_amx "a is int";     }         #pragma unused a     #pragma unused b     #pragma unused c }

Passing a value, you would need to use the any: magic tag.

Code:
#define do_test(%1) func(.value = %1, .type = tagof %1) func(any:value, type) {     new Float:a, bool:b, c;     switch(type)     {         case tagof(a): log_amx "value = %f", value;         case tagof(b): log_amx "value = %d", value;         case tagof(c): log_amx "value = %d", value;     }         #pragma unused a     #pragma unused b     #pragma unused c }

I'm not sure why you would get different value doing if (tagof(Float:)) and if (tagof(a))n because using variable is kind of dumb.

EDIT: About this ^, it would seem that I can fix it easily. In compiler it misses a flag. After the patch, tagof in the header work fine (and against tagof(Float:) too).
EDIT2: https://github.com/alliedmodders/amxmodx/pull/191
__________________

Last edited by Arkshine; 01-30-2015 at 19:40.
Arkshine is offline
Longcat
Junior Member
Join Date: Jan 2015
Location: as_oilrig
Old 01-31-2015 , 02:13   Re: tagof tests
Reply With Quote #3

Quote:
Originally Posted by Arkshine View Post
Thank you very much for the response.

But, how can I use the GitHub files to get the compiler patched?
Longcat is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-31-2015 , 11:03   Re: tagof tests
Reply With Quote #4

You can grab compiler from latest build : http://www.amxmodx.org/snapshots.php

Be aware that it's compiler from 1.8.3-dev.
__________________
Arkshine is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:48.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode