INI writer/loader

It’s very easy to use.

[lua]
local data = {}
data.owner = {}
data.owner.name = ‘Scarness’
data.owner.pos = Vector(1,1,1)
data.owner.color = Color(213,51,51)

data.admin = {}
data.admin.name = ‘Ray’
data.admin.angle = Angle(123,51,1)

ini.write(‘staff’,data)
[/lua]

Output:
[lua]
[owner]
pos=Vector(1,1,1)
name=Scarness
color=Color(213,51,51,4)

[admin]
name=Ray
angle=Angle(123,51,1)
[/lua]

Reading:

[lua]
local cfg = ini.read(‘staff’)
PrintTable(cfg)
[/lua]

Output:
[lua]
admin:
angle = 123.000 51.000 1.000
name = Ray
owner:
color:
a = 255
b = 51
g = 51
r = 213
name = Scarness
pos = 1.000000 1.000000 1.000000

[/lua]

Feedback is welcome, pull requests are also.

Just a note, this is not supposed to be used for text based data saving (i.e vON/JSON ) this is for user/server configs so lua incapable server owners/players can configure their addon.

What are the Benefits of using your System against JSON?

It’s far from my system and I don’t know about speeds and don’t quite care for them, this is for readable user configs and other stuff and not the crap that JSON spews.
INI configs are used in almost every game AFAIK.

What happens if a guy named “Color(255,255,255)” joins? Is it escaped properly? (didn’t read code)

Actually no it is not escaped, I forgot about that.
I’ll push an update today.

Ini format is much more limited than JSON, you can’t have nested structures for example.
I think YAML would actually be better option: it’s easily readable, has all stuff JSON has (and more), uses indentation so you can’t just spew it onto single line like GMod’s JSON serializer does (though it has inline table/list definitions but they aren’t used often).
I’m probably going to write YAML parser/writer in Lua soon if I won’t be too lazy.

INIs aren’t really meant for deeply nested structures, though.

Added escaping. Color,Vector,Angle etc are escaped, , removed global var detection (i.e %MOVETTYPE_NONE%)

Is it possible to overwrite or remove subtables within the INI file?

Thanks for this I’ll be sure to utilize it.

Do you mean edit the INI file itself? Then yeah sure, I don’t see any reason why not.

Also it looks like some people are confused with the purpose of INI files, I updated the OP.

This is cool, I used an ini file in my Visual Basic programming days to save stuff. In garry’s mod I’m fan of using mysql servers, and config files, but this is really cool!