SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Closed Thread
Thread Tools Display Modes
Old 26/04/2018, 10:59 AM   #1
Join Date: Apr 2018
Posts: 15
Reputation: 66
Default PawnPlus v0.5

What is this about?
PawnPlus enhances the Pawn programming language and the standard library with new syntax, new functions and mechanisms which allow coding in Pawn using better techniques akin to modern programming languages.

Asynchronous programming
Having to wait for a certain event forces you to spread the code over several functions, making it harder to maintain. Using PawnPlus, waiting for a specific event is as easy as calling one function, be it a result from a MySQL query, a completed dialog, or just sleeping in milliseconds. The wait is non-blocking and no threading is involved, but the execution of your code will continue when the event is completed. Using PawnPlus can reduce loading player data with MySQL to this:
SendClientMessage(playerid, -1, "Loading...");
await LoadPlayerAsync(playerid);
SendClientMessage(playerid, -1, "Loaded!");
The await statement pauses the execution of the current code until the task it is provided with is completed. In the meantime, any other code can run, be it from the same script or another. It is very easy to implement a function like LoadPlayerAsync by dynamically registering a callback handler to any callback, making virtually any event convertible to tasks. More usage and examples.

Dynamically-allocated strings
Strings in Pawn are cumbersome at best. Having to always specify the size of the string buffer leads to either wasting space, allocating more memory for the string than necessary, or trimmed strings at best and buffer overflow at worst when the target buffer is smaller than needed. PawnPlus adds dynamic strings with their memory and size completely governed by the plugin, freeing you of needing to always have that on mind. They are also garbage-collected, meaning you don't have to free any intermediate values when you are done with them, preventing common memory leaks.

Since the memory assigned to the string is not stored in the AMX machine, the string value can be safely passed or returned from functions.

PawnPlus strings are not null-terminated, meaning they can even store the null character, making them viable option for storing binary data in memory. Their characters are cell-sized, making them able to hold any array. Most operations on dynamic strings are faster than on normal strings, because the length of the string is always available.

Moreover, it is very easy to adapt almost any SA-MP or plugin function to take a PawnPlus string instead. For example, SendClientMessage can be modified in this way:
native SendClientMessageStr(playerid, color, AmxString:message) = SendClientMessage;

SendClientMessageStr(playerid, -1, @("Hello, id ") + str_val(playerid));
The @ operator creates a new dynamic string from a string literal. + can be used to create a new string by joining two strings together. More examples.

PawnPlus adds the Map and the List containers (implemented as std::unordered_map and std::vector, respectively). These containers support standard operations like adding or removing elements, lookup and iterating. Moreover, inserting any value into the container also stores its tag, so it is possible to access elements in the containers in a type-safe way.

These containers are heterogenous, meaning they can store any number of values of any type, even arrays. The tag of the value can be also obtained. Lists are indexed by integers starting from 0, while maps can use any value as a key (even strings/arrays), and the tag of the key must also be correct when obtaining the value. Since the map is implemented using a hash table, accessing any key can be quite fast, because there is no need to traverse the whole map.

It is also really easy to pass objects of any type around, because this plugin also adds a type called variant. A variant is an object that can store a single cell, or a whole array, together with its tag. It can be for example obtained from a list and inserted into another list, without having to deal with the type. str_val also works with the variant and is able to correctly format the stored value. Variants can be even passed to native functions by calling pawn_call_native together with the "v" format specifier. This function also accepts a list ("l") and handles it as a variable number of arguments.

Even though asynchronous programming is preferred, there could also be a need for performing a parallel computation. However, since having to work with threads and synchronisation primitives is non-trivial, causing common code errors, this plugin uses a different approach. Any code that needs to be executed in parallel with the server is contained in a threaded block, which ensures that the code runs in parallel with the server, but once the block ends, the execution continues as normal.

    for(new i = 0; i < 10000; i++) printf("%d", i);
A threaded block is initialized with synchronisation flags, specifying the nature of the thread and the way calls are handled. More information here.

Since the AMX machine is not designed to handle multiple threads accessing it, only at most one thread can execute the code in a given AMX script. However, the server will still not be blocked.

Callbacks and hooking
Several new functions were also added, allowing to register and unregister callbacks at runtime without having to actually place the public function in the code, which is useful for creating tasks. You can also call any native function (without specifying it in Pawn) with any number of arguments, and you can also hook any native function with whatever code you wish, modifying the arguments or the return value.

More information on the wiki. The plugin is currently in a pre-release stage, but all the features are implemented and should be fully working.

Last edited by IS4; 08/08/2018 at 02:45 AM.
IS4 is offline  
Old 26/04/2018, 12:51 PM   #2
Huge Clucker
Dice_'s Avatar
Join Date: Sep 2015
Location: Indonesia
Posts: 479
Reputation: 56
Default Re: PawnPlus

Dice_ is offline  
Old 26/04/2018, 04:55 PM   #3
Gammix's Avatar
Join Date: Jan 2015
Location: Canada
Posts: 1,814
Reputation: 831
Default Re: PawnPlus

Great features, i haven't tried it yet but looks good.

My GitHub:

Gammix is offline  
Old 26/04/2018, 05:23 PM   #4
[HLF]Southclaw's Avatar
Join Date: Apr 2009
Location: England
Posts: 4,963
Reputation: 1550
Default Re: PawnPlus

Great to see this released, nice work!



[HLF]Southclaw is online now  
Old 26/04/2018, 05:24 PM   #5
SyS's Avatar
Join Date: Oct 2015
Posts: 2,012
Reputation: 491
Default Re: PawnPlus

SyS is offline  
Old 26/04/2018, 05:44 PM   #6
ikkentim's Avatar
Join Date: Jan 2010
Location: Kampen, The Netherlands
Posts: 1,076
Reputation: 199
Default Re: PawnPlus

Nice implementation! Was expecting this to use a custom compiler, but it’s actually just a plug-in! Neat!
Tim Potze

GAMEDEV | Part-time developer working on Parkitect. | Steampage
LSRES | A SA:MP server from the past, and hopefully, back in the future.
SampSharp | Plugin for writing SA:MP gamemodes in C#. | Topic Website Github
SanMap | San Andreas in G00GLE MAPS! | Topic Github Sample
ikkentim is offline  
Old 26/04/2018, 06:24 PM   #7
Join Date: Oct 2016
Location: KS.
Posts: 791
Reputation: 140
Default Re: PawnPlus

Love it, nice work.
cuber is offline  
Old 26/04/2018, 06:30 PM   #8
CaioTJF's Avatar
Join Date: Sep 2012
Location: Rio de Janeiro
Posts: 537
Reputation: 148
Default Re: PawnPlus

Nice work

IP: / Website:

Procurando VPS para hospedar seu servidor? -->

CaioTJF is offline  
Old 26/04/2018, 07:58 PM   #9
Join Date: May 2011
Location: Russia
Posts: 3,338
Reputation: 824
Default Re: PawnPlus

Don't understand the thread stuff
Since the AMX machine is not designed to handle multiple threads accessing it, only at most one thread can execute the code in a given AMX script. However, the server will still not be blocked.
So the server will still work as fine, but the AMX script (the gamemode) behind it will stop working until the block will finish computing.
So it works in parallel with the server not the gamemode script.
Kaperstone is offline  
Old 26/04/2018, 08:53 PM   #10
Join Date: Apr 2018
Posts: 15
Reputation: 66
Default Re: PawnPlus

Yes, it works in parallel with the server. I was trying to make it work for the script too, but it is more tricky.
IS4 is offline  
Closed Thread

Thread Tools
Display Modes

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Help] PawnPlus IDE Manda21 Scripting Help 4 29/10/2016 02:41 PM
[Tool/Web/Other] [0.1] PawnPlus IDE - PAWNO alternative WopsS Tools and Files 62 13/04/2016 11:32 PM
[Tool/Web/Other] PawnPlus IDE - PAWNO alternative WopsS Tools and Files 94 14/01/2016 10:32 PM

All times are GMT. The time now is 01:13 PM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.