[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


Messages In This Thread
pointers.inc - Pointers for PAWN! - by Slice - 18.01.2012, 08:26
Re: pointers.inc - Pointers for PAWN! - by Ronaldo_raul™ - 18.01.2012, 08:33
Re: pointers.inc - Pointers for PAWN! - by SoUrAv - 18.01.2012, 08:39
Respuesta: pointers.inc - Pointers for PAWN! - by [Nikk] - 18.01.2012, 08:43
Re: pointers.inc - Pointers for PAWN! - by Lorenc_ - 18.01.2012, 08:50
Re: pointers.inc - Pointers for PAWN! - by T0pAz - 18.01.2012, 09:16
Re: pointers.inc - Pointers for PAWN! - by CaHbKo - 18.01.2012, 09:48
Re: pointers.inc - Pointers for PAWN! - by [S]trong - 18.01.2012, 10:20
Re: pointers.inc - Pointers for PAWN! - by steki. - 18.01.2012, 10:23
Re: pointers.inc - Pointers for PAWN! - by Niko_boy - 18.01.2012, 11:07
Re: pointers.inc - Pointers for PAWN! - by System64 - 18.01.2012, 11:14
Re: pointers.inc - Pointers for PAWN! - by CaHbKo - 18.01.2012, 11:30
Re: pointers.inc - Pointers for PAWN! - by Slice - 18.01.2012, 12:10
Re: pointers.inc - Pointers for PAWN! - by Ricop522 - 18.01.2012, 13:47
Re: pointers.inc - Pointers for PAWN! - by steki. - 18.01.2012, 15:26
Re: pointers.inc - Pointers for PAWN! - by Brian_G - 18.01.2012, 16:11
Re: pointers.inc - Pointers for PAWN! - by KingHual - 18.01.2012, 16:39
Re: pointers.inc - Pointers for PAWN! - by RyDeR` - 18.01.2012, 16:42
Re: pointers.inc - Pointers for PAWN! - by Zh3r0 - 18.01.2012, 17:11
Re: pointers.inc - Pointers for PAWN! - by steki. - 18.01.2012, 17:13
Re: pointers.inc - Pointers for PAWN! - by Zh3r0 - 18.01.2012, 17:17
Re: pointers.inc - Pointers for PAWN! - by steki. - 18.01.2012, 17:21
Re: pointers.inc - Pointers for PAWN! - by CaHbKo - 18.01.2012, 17:43
Re: pointers.inc - Pointers for PAWN! - by Slice - 18.01.2012, 17:50
Respuesta: pointers.inc - Pointers for PAWN! - by Adoniiz - 19.01.2012, 02:37
Re: pointers.inc - Pointers for PAWN! - by Slice - 19.01.2012, 04:58
Re: pointers.inc - Pointers for PAWN! - by The King's Bastard - 01.02.2012, 20:51
Re: pointers.inc - Pointers for PAWN! - by Slice - 02.02.2012, 06:42
Re: pointers.inc - Pointers for PAWN! - by The King's Bastard - 02.02.2012, 07:45
Re: pointers.inc - Pointers for PAWN! - by (LifeStealeR) - 02.02.2012, 08:32
Re: pointers.inc - Pointers for PAWN! - by Slice - 13.06.2012, 13:57
Re: pointers.inc - Pointers for PAWN! - by Hiddos - 13.06.2012, 14:38
Re: pointers.inc - Pointers for PAWN! - by Slice - 25.06.2012, 07:06
Re: pointers.inc - Pointers for PAWN! - by Яlackon - 28.07.2012, 22:04
Re: pointers.inc - Pointers for PAWN! - by BMB1 - 28.07.2012, 22:07
Re: pointers.inc - Pointers for PAWN! - by Ballu Miaa - 11.11.2012, 22:40
Re: pointers.inc - Pointers for PAWN! - by Dayvison_ - 27.03.2016, 23:31
Re: pointers.inc - Pointers for PAWN! - by Slice - 27.03.2016, 23:38
Re: pointers.inc - Pointers for PAWN! - by Dayvison_ - 28.03.2016, 00:01
Re: pointers.inc - Pointers for PAWN! - by Kar - 28.03.2016, 00:30
Re: pointers.inc - Pointers for PAWN! - by Slice - 28.03.2016, 08:20
Re: pointers.inc - Pointers for PAWN! - by Dayvison_ - 28.03.2016, 14:26
Re: pointers.inc - Pointers for PAWN! - by Slice - 28.03.2016, 16:18
Re: pointers.inc - Pointers for PAWN! - by Spmn - 25.05.2016, 20:56
Re: pointers.inc - Pointers for PAWN! - by Yashas - 26.05.2016, 04:29
Re: pointers.inc - Pointers for PAWN! - by Ivan_Ino - 26.05.2016, 11:24
Re: pointers.inc - Pointers for PAWN! - by vannesenn - 26.05.2016, 15:43
Re: pointers.inc - Pointers for PAWN! - by Yashas - 01.03.2017, 10:22
Re: pointers.inc - Pointers for PAWN! - by Nero_3D - 02.03.2017, 23:15
Re: pointers.inc - Pointers for PAWN! - by nG Inverse - 31.07.2017, 00:24
Re: pointers.inc - Pointers for PAWN! - by Damian - 08.03.2019, 14:46

Forum Jump:


Users browsing this thread: 1 Guest(s)