SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 26/04/2018, 09:59 AM   #1
IS4
Little Clucker
 
IS4's Avatar
 
Join Date: Apr 2018
Posts: 11
Reputation: 59
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:
Code:
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:
Code:
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.

Containers
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.

Threads
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.

Code:
print("begin");
threaded(sync_explicit)
{
    for(new i = 0; i < 10000; i++) printf("%d", i);
}
print("end");
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; 09/07/2018 at 11:46 PM.
IS4 is offline   Reply With Quote
Old 26/04/2018, 11:51 AM   #2
Dice_
Huge Clucker
 
Dice_'s Avatar
 
Join Date: Sep 2015
Location: Indonesia
Posts: 494
Reputation: 56
Default Re: PawnPlus

Interesting.
__________________
Dice_ is offline   Reply With Quote
Old 26/04/2018, 03:55 PM   #3
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,746
Reputation: 793
Default Re: PawnPlus

Great features, i haven't tried it yet but looks good.
__________________
Gammix is online now   Reply With Quote
Old 26/04/2018, 04:23 PM   #4
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,915
Reputation: 1460
Default Re: PawnPlus

Great to see this released, nice work!
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is offline   Reply With Quote
Old 26/04/2018, 04:24 PM   #5
SyS
High-roller
 
SyS's Avatar
 
Join Date: Oct 2015
Posts: 1,981
Reputation: 451
Default Re: PawnPlus

Nice
SyS is offline   Reply With Quote
Old 26/04/2018, 04:44 PM   #6
ikkentim
High-roller
 
ikkentim's Avatar
 
Join Date: Jan 2010
Location: Kampen, The Netherlands
Posts: 1,081
Reputation: 195
Default Re: PawnPlus

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

Projects
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   Reply With Quote
Old 26/04/2018, 05:24 PM   #7
cuber
Gangsta
 
cuber's Avatar
 
Join Date: Oct 2016
Location: KS.
Posts: 776
Reputation: 134
Default Re: PawnPlus

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

Nice work
__________________

IP: 192.99.94.236:7771 / Website: www.gtatorcidas.net

Procurando VPS para hospedar seu servidor? --> www.blasthosting.com.br


CaioTJF is offline   Reply With Quote
Old 26/04/2018, 06:58 PM   #9
Kaperstone
High-roller
 
Kaperstone's Avatar
 
Join Date: May 2011
Location: Russia
Posts: 3,354
Reputation: 822
Default Re: PawnPlus

Don't understand the thread stuff
Quote:
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   Reply With Quote
Old 26/04/2018, 07:53 PM   #10
IS4
Little Clucker
 
IS4's Avatar
 
Join Date: Apr 2018
Posts: 11
Reputation: 59
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   Reply With Quote
Reply

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 01:41 PM
[Tool/Web/Other] [0.1] PawnPlus IDE - PAWNO alternative WopsS Tools and Files 62 13/04/2016 10:32 PM
[Tool/Web/Other] PawnPlus IDE - PAWNO alternative WopsS Tools and Files 94 14/01/2016 09:32 PM


All times are GMT. The time now is 02:57 AM.


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