SA-MP Forums Archive
[Include] pointers.inc - Pointers for PAWN! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] pointers.inc - Pointers for PAWN! (/showthread.php?tid=311757)

Pages: 1 2 3


Re: pointers.inc - Pointers for PAWN! - Slice - 28.03.2016

Quote:
Originally Posted by Day_
Посмотреть сообщение
Yes, but not in the situation, in a following:
PHP код:
SomeFunc(playeridGLOBAL_TAG_TYPES:...)
{
   if(
tagof(@arg[1]) == tagof(Float:)){ // 0x43
   
}

But the variable in pointers.inc is created with no tag.

But I can possible using the macro.
PHP код:
#define SomeFunc(%0,%1) _SomeFunc(%0,tagof(%1),%1)
_SomeFunc(playeridtagGLOBAL_TAG_TYPES:...)
{
   if(
tagof(tag) == tagof(Float:)){ // 0x43
   
}

I wanted to know if there is another way.

PS: Sorry if not get express better. My english is not fluent
The only way to do it is how I showed you - you can not get the tag for dynamic arguments.


Re: pointers.inc - Pointers for PAWN! - Dayvison_ - 28.03.2016

Ok, thanks.


Re: pointers.inc - Pointers for PAWN! - Slice - 28.03.2016

There is one way to do it.. But it's a bit ugly.

pawn Код:
stock MyFunc(
    {Float, _, unused}:var1 = unused:0,
    {Float, _, unused}:var2 = unused:0,
    {Float, _, unused}:var3 = unused:0,
    {Float, _, unused}:var4 = unused:0,
    tag1 = tagof(var1),
    tag1 = tagof(var2),
    tag1 = tagof(var3),
    tag1 = tagof(var4)
) {
    if (tagof(var1) == tagof(unused:)) {
        num_vars = 0;
    } else if (tagof(var2) == tagof(unused:)) {
        num_vars = 1;
    } else if (tagof(var3) == tagof(unused:)) {
        num_vars = 2;
    } else if (tagof(var4) == tagof(unused:)) {
        num_vars = 3;
    } else {
        num_vars = 4;
    }

    var values[4], tags[4];
    values[0] = _:var1;
    values[1] = _:var2;
    values[2] = _:var3;
    values[3] = _:var4;
    tags[0] = tag1;
    tags[1] = tag2;
    tags[2] = tag3;
    tags[3] = tag4;

    // you now have values and tags in an array
    // if you want to allow many arguments, you must manually add more
}



Re: pointers.inc - Pointers for PAWN! - Spmn - 25.05.2016

Is it possible to access addresses across scripts? Or addresses can be read/written only from the AMX instance where variables were declared and this can't be done unless using lowER level libraries like amx_assembly?


Re: pointers.inc - Pointers for PAWN! - Yashas - 26.05.2016

You can't share variables/addresses across scripts because each script runs on its own AMX instance. It's basically each script running on its own computer. Even if you did manage to share the addresses (using CallRemoteFunction maybe?), using those address will either crash your server or give an error (they make no sense for the non-host scripts).

In other words, you are trying to store something in your computer and passing the address to me who is at some other part of the world using a different computer in an attempt to give me access to that data


Re: pointers.inc - Pointers for PAWN! - Ivan_Ino - 26.05.2016

I use this for a long time, and works perfect! usefull


Re: pointers.inc - Pointers for PAWN! - vannesenn - 26.05.2016

Slice, I don't see point of this include. Can You explain me for what I should use it? Thanks!


Re: pointers.inc - Pointers for PAWN! - Yashas - 01.03.2017

https://github.com/Zeex/pawn/issues/137

I think that bug can be abused to avoid functions calls completely.

Код:
new pointer[][] = {{1},{1,2}}; //1 and 1,2 are placeholders
//the compiler will allocate space for the array as if it was pointer[2][]
//but it does not store the maximum size for the second dimension in the compiler's compile-time symbol table
//therefore, the compiler does not know the size of the second dimension
//this will allow you to use any index for the 2nd dimension
//pointer[0][1000] the compiler won't complain about the index being 1000

getaddress(pointer, array); //fix the indirection table

pointer[0][5000]; //no warning, no error
This would make it pretty fast because it eliminates the function call needed for every access.

The extra space (pointer[1][0 and 1]) can be used to store some useful information if needed.


Re: pointers.inc - Pointers for PAWN! - Nero_3D - 02.03.2017

I think this is somehow related

It is possible to create empty arrays for pointer usage

Just an example how to use such a pointer without bounds to simplify emit code
For memory outside of the stack / heap we need to use additional functions (getData, setData)
PHP код:
new pData[][] = {{}};
Init() {
    new 
data;
    
#emit lctrl 1
    #emit stor.s.pri data
    
setPointer(pData0, -data); // set pData[0] to -data
    
data getData(pData[0][4]); // just for show
    
new // load offsets
        
publics getData(pData[0][8]) - data,
        
natives getData(pData[0][9]) - data,
        
libraries getData(pData[0][10]) - data,
        
pubvars getData(pData[0][11]) - data;
    
printf("%d %d %d %d %d"datapublicsnativeslibrariespubvars);
}
stock setPointer(pointer[][], indexaddress) {
    
#emit load.s.alt pointer
    #emit load.s.pri index
    #emit idxaddr
    #emit move.alt
    #emit load.s.pri address
    #emit sub
    #emit stor.i
}
stock setData(&addressvalueaddress value// sref
stock getData(&address) return address// lref 



Re: pointers.inc - Pointers for PAWN! - nG Inverse - 31.07.2017

This raises issues with BUD::SetStringEntry when passing a value by a pointer. Any current workaround?
pawn Код:
BUD::SetStringEntry(
    PlayerData[playerid][uID], g_AccountData[i][e_Name],
    @ptr[address, playerid]
);
printf("SAVING: %s|%s", g_AccountData[i][e_Name], @ptr[address, playerid]);
Prints the correct value "AAAAA", but inside user table
Код:
AADATE `users` SET `deaths`=0 WHERE `uid`=1
I can PM the full code if you would like.


Re: pointers.inc - Pointers for PAWN! - Damian - 08.03.2019

Homestly, quite embarrassed I’ve never even looked into this.