samp.directory
← Scripts et bibliothèques

Southclaws/samp-ini

A simple cache based ini format file parser, stores file contents in memory to manipulate in order to minimise actual file operations.

Bibliothèque★ 6mis à jour oct. 2020MITPawnsampctl
Ouvrir sur GitHub

Installer avec sampctl

sampctl package install Southclaws/samp-ini

Lance ceci dans le dossier de ton projet. sampctl télécharge le paquet et ce dont il dépend.

L’essayer dans le compilateur Pawn →

Ajoute ses fichiers include, avec les bibliothèques dont il dépend, au compilateur Pawn de ton navigateur, prêts à être inclus dans un script.

Dépend de 4 paquets

README.md

samp-ini

A super simple and fast ini reader and writer Pawn package.

Not as feature rich as y_ini but has a simpler API. Suitable for configuration, cookies, small user systems, etc.

Installation

Simply install to your project:

sampctl package install Southclaws/samp-ini

Include in your code and begin using the library:

#include <ini>

Usage

This library uses a simple open-modify-close design. Open an ini format file with ini_open, modify it with ini_get* and save it with ini_commit.

If you just need to read values, skip ini_commit and use ini_close.

Reading

Below is an example of reading a string, integer and float value from a file with proper error handling, that looks like:

keyString=hello
keyInteger=3
keyFloat=3.3
ini_open("file.ini");

new valueString[32];
new error = ini_getString("keyString", valueString);
if(error != 0) {
    Logger_Err("failed to get ini value", Logger_I("errorCode", error));
}

new valueInteger;
new error = ini_getInt("keyInteger", valueInteger);
if(error != 0) {
    Logger_Err("failed to get ini value", Logger_I("errorCode", error));
}

new Float:valueFloat;
new error = ini_getFloat("keyFloat", valueFloat);
if(error != 0) {
    Logger_Err("failed to get ini value", Logger_I("errorCode", error));
}

ini_close();

Writing

Below is an example of writing a string, integer and float value to a file with proper error handling.

ini_open("file.ini");

new valueString[32] = {"hello world"};
new error = ini_setString("keyString", valueString);
if(error != 0) {
    Logger_Err("failed to set ini value", Logger_I("errorCode", error));
}

new valueInteger = 5;
new error = ini_setInt("keyInteger", valueInteger);
if(error != 0) {
    Logger_Err("failed to set ini value", Logger_I("errorCode", error));
}

new Float:valueFloat = 5.5;
new error = ini_setFloat("keyFloat", valueFloat);
if(error != 0) {
    Logger_Err("failed to set ini value", Logger_I("errorCode", error));
}

ini_commit();

More Examples

Please see the unit test script for examples of every function's usage. You can run these unit tests by simply using sampctl package run --forceBuild --forceEnsure.

Testing

To test, simply run the package:

sampctl package run

And observe the y_testing unit test output

inipawnpawn-packagesa-mp

Cette page est construite à partir de ce que GitHub publie sur le dépôt. samp.directory n’héberge pas le code. Signaler un problème avec cette fiche

Southclaws/samp-ini : Bibliothèque SA-MP | samp.directory