SimpleIni

Started by Ankris, Aug 30, 2016, 04:08 PM

Previous topic - Next topic

Ankris

Functions:
  • INI_Open(string filename) -- returns the ini pointer
  • INI_SaveFile(ini pointer, filename)
  • INI_IsEmpty(ini pointer, string filename)
  • INI_SetUnicode(ini pointer, bool)
  • INI_GetSectionSize(ini pointer, string section)
  • INI_Exists(string filename)
  • INI_Close(ini pointer)
  • INI_SetString(ini pointer, string section, string key, string value)
  • INI_SetBool(ini pointer, string section, string key, bool value)
  • INI_SetFloat(ini pointer, string section, string key, float value)
  • INI_SetInteger(ini pointer, string section, string key, integer value)
  • INI_GetString(ini pointer, string section, string key)
  • INI_GetBool(ini pointer, string section, string key)
  • INI_GetFloat(ini pointer, string section, string key)
  • INI_GetInteger(ini pointer, string section, string key)

Download:
- https://github.com/Ankris/vcmp_simpleini/releases
- Source: https://github.com/Ankris/vcmp_simpleini

For Windows versions requires:
Visual C++ Redistributable Packages for Visual Studio 2013

KAKAN

Good one!
The best thing: It loads the whole INI file into memory :D
And also, you can put the downloads in the "releases" section of your github page :D
oh no

Ankris


Kewun

when trying using any function, server crash.

.

#4
I would highly suggest that you implement some error checking as well as checking the received arguments before releasing something. I know that the official plugins thought you to not check for errors and correct input data, but it's not a good practice.

Take this code from the very first function (INI_Open) :
const SQChar *file;
sq->getstring(v, 2, &file);

What if the the argument does not exist?
What if the argument is not a string?
What if it fails to retrieve the string?

You never check for those possibilities. And you're begging for a crash if you get the wrong data. And don't blame it on the scripter if he passes the wrong data because there's always a possibility for anything. It's your job to report what he did wrong.

First of all you check to see if you have that parameter and report which parameter is missing (I used dummy names in this example):
const SQInteger top = sq->gettop(vm);
// Is the first argument there?
if (top <= 1)
{
return sq->throwerror(vm, "Tou forgot to specify the first parameter");
}
// Is the second argument there?
else if (top <= 2)
{
return sq->throwerror(vm, "Tou forgot to specify the second parameter");
}
// Is the third argument there?
else if (top <= 3)
{
return sq->throwerror(vm, "Tou forgot to specify the third parameter");
}

Secondly, you check if you have the correct type and report what type you're expecting and possibly, even what type you received (I'm using dummy types in this example):
// Is the first parameter a user pointer?
if (sq->gettype(vm, 2) != OT_USERPOINTER)
{
return sq->throwerror(vm, "The first parameter is not a user pointer");
}
// Is the second parameter a string? We're expecting a string!
else if (sq->gettype(vm, 3) != OT_STRING)
{
return sq->throwerror(vm, "The first parameter is not a string");
}
// Is the third parameter an integer or float?
else if (sq->gettype(vm, 4) != OT_INTEGER && sq->gettype(vm, 3) != OT_FLOAT)
{
return sq->throwerror(vm, "The first parameter is not a numeric value");
}

Thirdly, some Squirrel functions also return a result which tells you whether or not they failed to do what you asked. So you check that too and return that result (if necessary) so that the VM can raise the proper error message:
// Dummy variable to store the result code where necessary
SQRESULT r = SQ_OK;

SQUserPointer ptr = NULL;
// Store the returned result code
r = sq->getuserpointer(vm, 2, &ptr);
// Check for failures
if (SQ_FAILED(r))
{
return r; // Return that result code to raise that error message
}

const SQChar *str;
// Store the returned result code
r = sq->getstring(vm, 3, &str);
// Check for failures
if (SQ_FAILED(r))
{
return r; // Return that result code to raise that error message
}

SQInteger value;
// Store the returned result code
r = sq->getinteger(vm, 4, &value);
// Check for failures
if (SQ_FAILED(r))
{
return r; // Return that result code to raise that error message
}

Then, You validate the obtained data. You can't start using null pointers incorrect values and not expect a crash:
// Is the specified pointer valid?
if (ptr == NULL)
{
return sq->throwerror(vm, "The specified string is invalid");
}
// Is the specified string valid?
else if (!str || *str == '\0')
{
return sq->throwerror(vm, "The specified string is empty or invalid");
}

And you constantly perform these checks and report back to the scripter so that he knows what he did wrong. A subtle crash or an ignored failure doesn't help anyone.

Another suggestion. Don't name global variables with just one letter, such as 'v' (which you did for the virtual machine). You clearly took this behavior from the official plugins. That's just wrong man. Wrong on so many levels that I simply don't know where to even begin if I were to describe it.

Don't learn anything from the official plugins. Everything there is just bad. Take that as an advice or as a warning. Your choice.
.

Ankris

#5
Quote from: . on Aug 30, 2016, 09:07 PM.

I'm just lazy.

Also there is no like 150 functions to be hard to remember all parameters. Plus I already made some plugins since time ago so these kind of tutorials are useless4me.

Thijn

Quote from: Ankris on Aug 30, 2016, 09:28 PMPlus I already made some plugins since time ago so these kind of tutorials are useless4me.
If this is your way of making plugins, you better just stop making them...

Ankris

Quote from: Thijn on Aug 31, 2016, 12:23 PM
Quote from: Ankris on Aug 30, 2016, 09:28 PMPlus I already made some plugins since time ago so these kind of tutorials are useless4me.
If this is your way of making plugins, you better just stop making them...

If I remember all the functions and parameters of my own plugins, why should I?



New plugin update: https://github.com/Ankris/vcmp_simpleini/releases/tag/R2

Mötley

#8
Quote from: Thijn on Aug 31, 2016, 12:23 PMIf this is your way of making plugins, you better just stop making them...
Quote from: AdTec_224 on Jul 14, 2016, 10:56 PMIt's exactly this kind of thing that stops us as developers having the motivation to continue working on a free mod.
And it's exactly this thing that prevents interesting releases,
We should motivate others not put them down, Ankris was flat out honest with @.. post.
Just a little more motivation and it would of possibly happened.

I like the release and I really would love to see more interesting work :)

KAKAN

Quote from: Ankris on Sep 03, 2016, 01:39 AM
Quote from: Thijn on Aug 31, 2016, 12:23 PM
Quote from: Ankris on Aug 30, 2016, 09:28 PMPlus I already made some plugins since time ago so these kind of tutorials are useless4me.
If this is your way of making plugins, you better just stop making them...

If I remember all the functions and parameters of my own plugins, why should I?
Yes, you can remember as you own that plugin( and other good devs too ). But think about newbies too, they will probably screw things up and atlast, PM/post a topic telling "I was using INI plugin and the server crashed".
Quote from: Mötley on Sep 03, 2016, 01:49 AMAnd it's exactly this thing that prevents interesting releases,
We should motivate others not put them down, Ankris was flat out honest with @.. post.
Just a little more motivation and it would of possibly happened.
true.
oh no

Shadow

#10
Quote from: Mötley on Sep 03, 2016, 01:49 AM...

Quote from: KAKAN on Sep 03, 2016, 10:47 AM
Quote from: Ankris on Sep 03, 2016, 01:39 AM
Quote from: Thijn on Aug 31, 2016, 12:23 PM
Quote from: Ankris on Aug 30, 2016, 09:28 PM...

All SLC did was provide constructive criticism. A bad release is not benefical for neither you, me, or the creator. Ankris has a lot to learn from SLC's advices and by understanding those advices, he can improve himself and his work. There's no reason to be offended at all, I'd be happy if someone pointed out my mistakes so I could fix them and create more efficient code. I really don't understand why you people get angry when people try to help you. SLC didn't call you a noob or anything, he replied with great professionalism, helping you understand why such practices are bad/discouraged.
QuotePS:is trash is ur home language??

Ankris

Quote from: Shadow on Sep 03, 2016, 02:21 PM
Quote from: Mötley on Sep 03, 2016, 01:49 AM...

Quote from: KAKAN on Sep 03, 2016, 10:47 AM
Quote from: Ankris on Sep 03, 2016, 01:39 AM
Quote from: Thijn on Aug 31, 2016, 12:23 PM
Quote from: Ankris on Aug 30, 2016, 09:28 PM...
...

I hate mostly when someone tells me how to do the things because it's like 'THIS IS THE ONLY F***ING WAY, AND EVERYTHING ELSE IS WRONG'. There should be a word in english meaning this.

Shadow

Quote from: Ankris on Sep 04, 2016, 10:11 PMI hate mostly when someone tells me how to do the things because it's like 'THIS IS THE ONLY F***ING WAY, AND EVERYTHING ELSE IS WRONG'. There should be a word in english meaning this.

He didn't say it's the only way. All he did say was that your ways were more dangerous due to the amount of errors that may occur without the end-user knowing about them. If your practice is bad and someone points out it is bad, you might have to change it.
QuotePS:is trash is ur home language??

Ankris

Quote from: Shadow on Sep 04, 2016, 10:13 PM
Quote from: Ankris on Sep 04, 2016, 10:11 PM.
.

I didn't also say he said it's the only way. There was a bit of meaning of it in that reply.

Mötley

INI_SetInteger(ini pointer, string section, string key, integer value)

Lol,,,,...

Could someone tell me what Ini pointer is. I always return errors. No clue as of why,Probably something really dumb on my part