Releases: IS4Code/PawnPlus
PawnPlus v1.4.3
- Added
str_capacity
andstr_reserve
to control the internal string's buffer capacity. str_addr
,var_addr
, and co. now have a second parameter specifying the particular behaviour of strings copied into the dynamic string viaamx_SetString
. For example,amx_buffer_string_auto_fit
allows resizing the string to fit any number of characters inside. Note that not all SA-MP functions useamx_SetString
, so this will only improve interop with those that do.- Added support for reading two special environment variables,
PAWNPLUS_NO_AMX_HOOKS
andPAWNPLUS_NO_FILE_HOOKS
. This allows circumventing Zeex/samp-plugin-crashdetect#127 if the server is launched viaPAWNPLUS_NO_FILE_HOOKS=1 ./samp03svr
orexport PAWNPLUS_NO_FILE_HOOKS=1 ./samp03svr
- Fixed
pawn_try_call_native_msg
and similar functions to correctly load their arguments.
PawnPlus v1.4.2
-
Unifies the result of
str_addr
andstr_buf_addr
(andvar_addr
andvar_buf_addr
) so that both functions can be used interchangeably.AmxStringBuffer:
(andstr_buf_addr
) should still be used in situations where the implementation of the native is known to rely on the value being an actual address of the character data, but it is valid to be used instead ofstr_addr
in all situations.Please note that the address returned from
str_addr
andstr_buf_addr
is meant to be temporary, only to be used for the native for which it was created for. and might become unusable sooner than in the previous versions. -
pp_max_recursion
now returns the old value. -
pp_toggle_exec_hook
can be used to disable modifications to the AMX execution, at the cost of making certain advanced features (like async, threading, custom callbacks etc.) unavailable.
PawnPlus v1.4.1
Additions
- (
task_
)await_str
(_s
) (#49 from @Se8870). handler_inverted_return
for compatibility with y_hooks (#52 from @AGraber).math_random_generator
(and therandom_generator
enum) to set the concrete generator for random functions.
Changes
pawn_on_init
andpawn_on_exit
use shorter names internally, allowing 7 characters longer identifiers. Scripts do not have to be recompiled.- Random generation was changed to guarantee consistency on both Windows and Linux. The default generator is now
generator_mt19937
(used to begenerator_minstd_rand0
on Linux). See this article for more details on how random number generation works between compilers. Consistency of generated numbers with previous versions is not guaranteed!
Fixes
- Fixed the use of
tagof
andsizeof
in parameters for older compilers with YSI (see #48). regex_cached_addr
verifies that the memory location was not destroyed.str_set_format
allows using the target string during the formatting before it is replaced.- Fixed the
amx_FindPublic
hook to hide new callbacks fromamx_NumPublics
called inside the original function. - Fixed custom callbacks calls when
amx_Exec
has nullretval
. (#53 from @AGraber).
Note: Starting from this release, the "-static" binary is compiled on a different machine than before and may not work on old systems.
PawnPlus v1.4
Additions
- Added the possibility to register and handle a custom format selector, including the
str_register_format
andstr_get_format_tag
functions and thetag_op_format
tag operation. More here. str_val_*
functions have a newformat
string parameter to use the format operation instead of string conversion. The value corresponds to a format specifier instr_format
.- An expression (in
{
,}
) instr_format
may be followed by a format specifier like an argument substitution. - Added
tag_set_op_expr
to allow handling a tag operation with an expression. - Added
regex_start_at_pos
to treat thepos
argument as an absolute start of the string (for^
). - All families of functions that accept variant parameters now also accept dynamic strings natively.
- Added
pp_daytime
to obtain the time of day in milliseconds.
Changes
- The
d
format selector does not necessarily imply signed integer conversion when applied on tagged values, only "decimal", meaning it can be used onFloat:
andunsigned:
. str_format
and similar functions treat a sole"%s"
format string specially and do not use a tag operation, primarily to speed-up the case of appending a single string viastr_append_format
.- Functions that do not return a meaningful value are marked with
unit:
in the include. This does not denote an actual tag, only that the function always returns 1 (or raises an error on failure). task_set_error
raises an error when used with a non-error code.var_delete
raises an error when used on an invalid variant reference.- The debug module on Windows now also hooks
CreateFileW
in addition toCreateFileA
to accomodate for different host environments. It is now also restricted to.amx
files. This could affect plugins that useCreateFileA
to open a file, then close the file and expect the file to be immediately available withCreateFileW
again, or that useCreateFileW
to open a file, close it and then try to open it in another thread. The lifetime of all prolonged handles still ends with the next tick, and now also when an AMX is fully loaded.
Fixes
ConstStringTag:
is used instead ofStringTag:
in a couple of places.- Fixed assertion error on an invalid format specifier.
- Clearing containers properly invalidates their iterators.
- Fixed a crash on exit related to unsetting the locale.
- Fixed assertion error when
regex_cached_addr
is used on a dynamic string. - Added missing
tag_uid_amx_guard
to the include. tag_call_op
now also supportstag_op_handle
.iter_set_*
is now regarded as cell-returning in metadata.- Fixed a potential memory leak on
amx_commit
(thanks @GermanAizek).
PawnPlus v1.3.2
- Newly added callback handlers are not called from the same callback handler for the current callback.
- Do not extend the lifetime of the last opened file (used by the debug module) indefinitely, preventing locking files for external access.
- Added fallback for trampoline creation for
CreateFileA
/fopen
, fixing crashes on some platforms.
PawnPlus v1.3.1
expr_parse
supports hex escape sequences for producing any character cell via its numeric value. The syntax is\xXX
or\uXXXXXXXX
.- Removing a callback handler from a callback handler no longer stops other handlers from executing or causes crashes when
false
is returned. pp_module_name
fixed for Linux.- subhook has been updated to the latest version, hopefully solving crashes on some platforms.
PawnPlus v1.3
Additions:
map_new
andpool_new
allow specifying the ordered state at creation.bool:stay
parameter foriter_erase
specifying the iterator shouldn't move to the next element. Usable in loops. Newiter_empty
function, also usable viaoperator!
.var_iter
accepts count like initer_repeat
.handle_iter
added.- Task-related optimizations.
Fixes:
- Cloning a pool doesn't reassign the indices.
- Cloning a map or a pool preserves its ordered state.
- Deep clear of some containers doesn't delete them anymore.
PawnPlus v1.2.1
math_try_round
,math_try_floor
,math_try_ceiling
, andmath_try_truncate
for when the result might not fit in a 32-bit integer.- Missing tags added to
PP_ALL_TAGS
. start
parameter instr_get
is actually used.- Fixed a potential crash when
*_delete_deep
is called on an ordered pool.
PawnPlus v1.2
list_sort_expr
added for sorting lists based on an expression.math_random_seed
added to configure the random generator; the initial seed is also different each time.pawn_add_filter
pushes the addresses of arguments directly if possible.- Various fixes regarding callbacks, AMX initialization, and incorrect parameter counts.
PawnPlus v1.1
Additions
Pools
- A new type of collection providing support for efficient storage of data using reusable integer indices.
- When an element is added to a pool, it gets assigned an index which is then used to refer to the element.
- Pools come in two versions with the same API – ordered (new indices are assigned in a specific order), and unordered. Ordered pools will always assign the lowest unused index to a newly added element.
- A pool can grow to any size if there are no unused slots for new elements.
Expressions
- Dynamic run-time representations of operations.
- Can be constructed from components in a tree-like manner, or parsed from string with
expr_parse
. - The parser supports all standard Pawn operators and some PawnPlus-specific ones. It can also find and use non-public Pawn variables (via the debug API).
- Expressions can be used in collections and new types of iterators to easily perform queries on multiple elements.
Async
async
pseudo-attribute for functions using the async pattern (together withreturn async
).- The
await
macro has an alternative definition supporting multiline expression, but requires additional configuration for all tags (enabled viaPP_MULTILINE_AWAIT
). await_arr
andawait_var
added.
Collections
- The API is now more unified, so all collections have roughly the same functions with the same semantics.
- The capacity of the underlying container can be obtained.
Strings
- If
{…}
is used instr_format
and it doesn't correspond to a color code or a parameter selector, it is parsed and executed as a piece of code. %f
instr_format
accepts a width parameter.str_append_format
added.
Pawn and AMX
pawn_create_callback
can be used to create a new callback/public function and attach it to the current script. The function consists of an expression that is executed every time the public function is called.- Declarational initializers and finalizers added. Any public function whose name starts with
_pp@on_init@
will be called first before every other function, when the script is loaded. Any function whose name starts with_pp@on_exit@
will be called last after all other functions, when the script is unloaded. Macrospawn_on_init
andpawn_on_exit
can be used for easy creation of these functions. - AMX guards introduced. While a Pawn guard protects the object for the duration of the current context (analogous to a local variable), an AMX guard protects it for the duration of the script (analogous to a global/static local variable).
- Handling public function index incompatibility with SAMPGDK can be resolved by
pp_public_min_index
orpp_use_funcidx
. Callback handlers can be registered for negative indices. - Captured arguments (in
pawn_register_callback
orpawn_add_hook
) now acceptv
,h
, andx
as new types of values.v
corresponds to aVariant:
argument which is copied to the closure and loaded when it is restored,h
corresponds to aHandle:
argument which is prolonged by the closure (so the underlying object is not destroyed) and whose value is loaded when the closure is restored, andx
corresponds to anExpression:
argument containing an expression which is executed every time the argument is restored.
Error handling
- Dynamically called external natives that raise a system error/signal do not crash the server, but are handled and reported via PawnPlus errors.
C API
- Support for errors and serialization.
Changes
Error handling
pp_on_error
is only called for a native called directly by the script. Errors in internally called natives are handled or propagated by the code that called them.pawn_try_call_native
never invokespp_on_error
.
Collections
- Iterators are invalidated on addition only when necessary (when the underlying buffer needs to be reallocated).
Variants
- Calling operations on variables that are incompatible (different tags or sizes) now produces an error (used to return null).
Math
- Dynamically called operations on
signed:
andunsigned:
values can raise an error.
Pawn and AMX
- Incorrect public function index caused by SAMPGDK is detected and warned about.
Fixes
Variants
collect
operation is now correctly called in some places.
Async
- When a context is stored after a call to an asynchronous function,
reset_stk
andreset_hea
are now used to correctly restore the original values ofstk
andhea
, fixing a memory leak that happened when a public function with parameters was stored (because the parameters were not taken into account whenstk
was restored).
Math
signed:
andunsigned:
subtraction fixed.
Error handling
- Allocation of more data than the script supports is prevented.
Pawn and AMX
- Removing a hook handler when it is running will not crash the server.
Examples
Format expressions
new val1 = 5, val2 = 10;
print_s(str_format("the sum of {val1} and {val2} is {val1 + val2}"));
Queries
new Map:m = map_new();
map_add(m, 1, 10);
map_add(m, 2, 21);
map_add(m, 3, 30);
map_add(m, 4, 41);
map_add(m, 5, 50);
map_remove_if(m, expr_parse("10*$key != $value")); //removes 2 and 4
Caching expressions
static Expression:expr;
if(!expr)
{
expr = expr_parse("$value*$value");
amx_guard(expr);
}
Declarational callback handler
pawn_on_init[callback1]
{
new id = pawn_create_callback("OnPlayerConnect", expr_const(0));
pawn_register_callback(amx_encode_public(id), "MyOnPlayerConnect");
}