[Include] pointers.inc - Pointers for PAWN!
#1

Hey,

Here's a neat implementation of pointers for PAWN! This include makes it a lot easier to deal with variadic functions (functions that can take a varying number of arguments), but also allows you to, for example, have pointers from large enum structures into other arrays, parts of strings, etc.
One example would be to have an array for player gangs, then use a pointer from a player array into the player's gang (think C structures, sort of).

A quick example:
pawn Код:
new
    g_Test[] = {123, 456, 789}
;

public OnGameModeInit() {
    new address = GetVariableAddress(g_Test);
   
    // Change the 2nd value
    @ptr[address][1] = 444;
   
    // Print out the values
    printf("%d, %d, %d", @ptr[address][0], @ptr[address][1], @ptr[address][2]);
}
Here's an example of a function that appends all string arguments to a given string.
pawn Код:
public OnGameModeInit() {
    new buf[128] = "Lorem";
   
    concat(buf, sizeof(buf), "ipsum", "dolor", "sit", "amet,", "consectetur", "adipiscing.");
   
    // Prints out: Lorem ipsum dolor sit amet, consectetur adipiscing.
    print(buf);
}

// Append all strings to szOutput
stock concat(output[], maxsize = sizeof(output), ...) {
    new
        arg_count = numargs()
    ;
   
    for (new i = 2; i < arg_count; i++) {
        // First add a space
        strcat(output, " ", maxsize);
       
        // Then add the string
        strcat(output, @arg[i], maxsize);
    }
}
Syntax:
pawn Код:
@ptr[address] // This is now a pointer to "address"
@arg[2] // This is now a pointer to the 3rd argument (0 is the first)
Download: pointers.inc
Reply
#2

:O WTF ! omg this is fucking awesome.Great release Sir Slice as usual
Reply
#3

That's great.
Reply
#4

Exelent script for get to Hight Roller Exelent Include (999 Messages )
Good job
Reply
#5

Excellent release!
Reply
#6

I was waiting for this! But I cannot give you rep
Reply
#7

Could someone give me an example of what it can be used for?
Reply
#8

Thank you dude, this is f*ucking awesome!
Reply
#9

Can I point a part of an array to make it easier, like:
The variable: PlayerInfo[playerid][gPlayerPos][3].

I make a pointer _point that points to PlayerInfo[playerid] and I just use (example) _point[gPlayerPos][3] ?
Reply
#10

OmMa GawD Freaka amaaaaazing!
Reply
#11

Script: awesome but I don't understand this, it makes new mouse pointers or?
Reply
#12

Does it have the same usage as
pawn Код:
...

    #define _d[%0] diInfo[slot][%0]
    _d[Rot] = rot;
    _d[Pos][0] = pos[0];
    _d[Pos][1] = pos[1];
    _d[Pos][2] = pos[2];
    _d[Label] = CreateDynamic3DTextLabel(str, -1, _d[Pos][0], _d[Pos][1], _d[Pos][2], 5.0, .testlos = 1, .worldid = _d[World]);
    #undef _d
...
?
Reply
#13

Quote:
Originally Posted by Stewie`
Посмотреть сообщение
Can I point a part of an array to make it easier, like:
The variable: PlayerInfo[playerid][gPlayerPos][3].

I make a pointer _point that points to PlayerInfo[playerid] and I just use (example) _point[gPlayerPos][3] ?
I'm not entierly sure how well enums are handled - you might get tag mismatch warnings. I'm currently thinking of ways to deal with enums - I'll get back to you if I come up with anything good!

@CaHbKo:
No, not really. That's just a way to have to type less code - this is a bit more complicated.

@******:
I must've overlooked doing it that way, I'll update the macros!
And yeah, the the reason it could be done this simple is because that bug/feature with round brackets that I stumbled upon while developing this.
Reply
#14

Very nice , omg
Reply
#15

Indeed. That's just awesome.
Reply
#16

wow 0.0
Reply
#17

Quote:
Originally Posted by System64
Посмотреть сообщение
Script: awesome but I don't understand this, it makes new mouse pointers or?
Take a look at some C/++ tutorials. And no, it's not used for this. It returns the address of a variable.
Reply
#18

I like the idea. Very nice done, will take a look at the code.
Reply
#19

People here are going crazy, OMG WHAT THA FACK and all this shit, but they have absolutely no idea what this is.

I apparently don't have an idea what this is either, but it's from Slice, and it has a post by ****** in it, so it must be cool.
Reply
#20

Quote:
Originally Posted by Zh3r0
Посмотреть сообщение
People here are going crazy, OMG WHAT THA FACK and all this shit, but they have absolutely no idea what this is.

I apparently don't have an idea what this is either, but it's from Slice, and it has a post by ****** in it, so it must be cool.
http://www.cplusplus.com/doc/tutorial/pointers/
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)