Coder Social home page Coder Social logo

southclaws / samp-ini Goto Github PK

View Code? Open in Web Editor NEW
5.0 4.0 7.0 37 KB

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

License: MIT License

Pawn 98.65% Makefile 1.35%
pawn-package ini pawn sa-mp

samp-ini's Introduction

samp-ini

GitHub Travis

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

samp-ini's People

Contributors

southclaws avatar spacemud avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

samp-ini's Issues

Failure to load certain key names

I'm having trouble reading values with certain key names. Here's the original file that I tried to read:

server=irc.gtanet.com
port=6667

And the code to test it:

#include <ini>

main()
{
    ini_open("test.ini");

    new
        key1[16],
        key2,
        error;

    error = ini_getString("key1", key1);
    printf("key1: %s error: %d", key1, error);

    error = ini_getInt("key2", key2);
    printf("key2: %d error: %d", key2, error);

    ini_close();

    return 1;
}

Gives:

server: irc.gtanet.com error: 0
port: 0 error: 6

It seems to read the first key fine, but reading later keys fail.

Renaming the keys to something else works fine, for example changing server to key1 and port to key2 as in the example code above gives:

key1: irc.gtanet.com error: 0
key2: 6667 error: 0

invalid code

samp-ini/ini.inc

Lines 155 to 166 in 13e146b

stock _ini_printCache(const message[]) {
Logger_Log(message);
Logger_Log("begin ini cache");
for(new i = 0, j = ini_recordsRead + ini_recordsAdded; i < j; ++i) {
Logger_Log("--record",
Logger_I("index", i),
Logger_I("deleted", ini_cache[i][E_CACHE_DELETED]),
Logger_S("key", ini_cache[i][E_CACHE_KEY]),
Logger_S("value", ini_cache[i][E_CACHE_VALUE]));
}
Logger_Log("end ini cache");
}

Just wondering if you're aware that this code is uncompilable, it seems unfinished.

Uhmhn map.inc

So basically im trying to compile your scavange and survive gamemode, and it says this:

C:\Users\Matas.DESKTOP-LGK3FU9\Desktop\uRPG\pawno\include\ini.inc(15) : fatal error 100: cannot read from file: "map"

Compilation aborted.Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase

1 Error.

When i go and edit ini.inc it has included map.inc, but i dont have it, and dont know where to get it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.