[Include] Yet another INI/key-value reader/writer
#1

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) {
    err("failed to get ini value", _i("errorCode", error));
}

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

new Float:valueFloat;
new error = ini_getFloat("keyFloat", valueFloat);
if(error != 0) {
    err("failed to get ini value", _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) {
    err("failed to set ini value", _i("errorCode", error));
}

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

new Float:valueFloat = 5.5;
new error = ini_setFloat("keyFloat", valueFloat);
if(error != 0) {
    err("failed to set ini value", _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
Reply
#2

thank you im testing this right now.
Reply
#3

Nice release

Btw, some function's names are very similar to this one (like ini_setString, ini_getInteger etc.). You could also add a compatibility mode with this include, and maybe it will be useful for its users (actually there are many people who prefer to use mxINI instead of dini, y_ini and others).
Reply
#4

Quote:
Originally Posted by OstGot
Посмотреть сообщение
Nice release

Btw, some function's names are very similar to this one (like ini_setString, ini_getInteger etc.). You could also add a compatibility mode with this include, and maybe it will be useful for its users (actually there are many people who prefer to use mxINI instead of dini, y_ini and others).
it would be kickass if he made it easy to replace dini with this, gj sc gonna test this and see how it goes.
Reply
#5

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
it would be kickass if he made it easy to replace dini with this, gj sc gonna test this and see how it goes.
There's already an alternative that is compatible with dini - https://sampforum.blast.hk/showthread.php?tid=611399
Reply
#6

Quote:
Originally Posted by Calgon
Посмотреть сообщение
There's already an alternative that is compatible with dini - https://sampforum.blast.hk/showthread.php?tid=611399
I realize that but for some reason it doesn't load for me when i use this in both an FS and my gamemode simply doesn't give me the stats for ex the cash, just everything reset to 0.
Reply
#7

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
I realize that but for some reason it doesn't load for me when i use this in both an FS and my gamemode simply doesn't give me the stats for ex the cash, just everything reset to 0.
Even with the new update?

I would discuss this in my thread.
Reply
#8

Quote:
Originally Posted by Gammix
Посмотреть сообщение
Even with the new update?

I would discuss this in my thread.
Yeah i didn't want to report this to you to not bother u with that shit just thought i would transfer the filterscript and my code into one gamemode and try first then report to you, and okay true it's better to discuss this on ur thread, you made a new update? i will test it right now.
Reply
#9

Includes?
for ini.inc, we need this map.inc
for map.inc, we need this, but it not working with last map.inc!
Reply
#10

Quote:
Originally Posted by Vadyanga
Посмотреть сообщение
Include map?
___

10 years later...
welcome
...

for map: this
Don't use the old memory access plugin, instead use the successor!
Reply
#11

Thanks
Reply
#12

I always used Slick's (SII) and it always worked fine, but I now like this API more because of the use of a reference parameter, leaving the return value for error codes.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)