pointers.inc - Pointers for PAWN! -
Slice - 18.01.2012
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
Re: pointers.inc - Pointers for PAWN! -
Ronaldo_raul™ - 18.01.2012
:O WTF ! omg this is fucking awesome.Great release Sir Slice as usual
Re: pointers.inc - Pointers for PAWN! -
SoUrAv - 18.01.2012
That's great.
Respuesta: pointers.inc - Pointers for PAWN! -
[Nikk] - 18.01.2012
Exelent script for get to Hight Roller
Exelent Include
(999 Messages
)
Good job
Re: pointers.inc - Pointers for PAWN! -
Lorenc_ - 18.01.2012
Excellent release!
Re: pointers.inc - Pointers for PAWN! - T0pAz - 18.01.2012
I was waiting for this! But I cannot give you rep
Re: pointers.inc - Pointers for PAWN! -
CaHbKo - 18.01.2012
Could someone give me an example of what it can be used for?
Re: pointers.inc - Pointers for PAWN! - [S]trong - 18.01.2012
Thank you dude, this is f*ucking awesome!
Re: pointers.inc - Pointers for PAWN! -
steki. - 18.01.2012
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] ?
Re: pointers.inc - Pointers for PAWN! -
Niko_boy - 18.01.2012
OmMa GawD Freaka amaaaaazing!
Re: pointers.inc - Pointers for PAWN! -
System64 - 18.01.2012
Script: awesome but I don't understand this, it makes new mouse pointers or?
Re: pointers.inc - Pointers for PAWN! -
CaHbKo - 18.01.2012
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
...
?
Re: pointers.inc - Pointers for PAWN! -
Slice - 18.01.2012
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.
Re: pointers.inc - Pointers for PAWN! -
Ricop522 - 18.01.2012
Very nice , omg
Re: pointers.inc - Pointers for PAWN! -
steki. - 18.01.2012
Indeed. That's just awesome.
Re: pointers.inc - Pointers for PAWN! -
Brian_G - 18.01.2012
wow 0.0
Re: pointers.inc - Pointers for PAWN! -
KingHual - 18.01.2012
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.
Re: pointers.inc - Pointers for PAWN! -
RyDeR` - 18.01.2012
I like the idea. Very nice done, will take a look at the code.
Re: pointers.inc - Pointers for PAWN! -
Zh3r0 - 18.01.2012
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.
Re: pointers.inc - Pointers for PAWN! -
steki. - 18.01.2012
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/