This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
LeDark Lua's profile picture

CCINI API

Started by LeDark Lua, 10 November 2015 - 03:03 PM
LeDark Lua #1
Posted 10 November 2015 - 04:03 PM
INI ( INITIALIZATION/CONFIG ) files for ComputerCraft


What is INI and why do I need it?

INI files are config files that stores information. For example:
[PLAYER] –This is a section–
–These are keys with values–
Name=LeDark Lua
HP=100
XP=120
MAX_XP=500

Why to use it? Because it is cool and easy.


Ok, you got me, where do I get it?

INI API pastebin:


Test program pastebin:
pastebin get tSR02Mry ini_test


How to use it?

Read INI:

INI_TABLE=INI.retrieve(path)
VALUE=
INI_TABLE.SECTION_NAME.KEY_NAME
print(VALUE) –output: Hello, world!

Write INI:
INI_TABLE={
SECTION_NAME={
KEY_NAME="Hello, world!";
}
}

INI.write(path, INI_TABLE)
Edited on 23 December 2015 - 08:43 AM
Creator #2
Posted 10 November 2015 - 04:22 PM
So this is basically like a fancy version of serialize, which implements file reading/writing?
LeDark Lua #3
Posted 10 November 2015 - 04:24 PM
Yeah, but INI style :)/>

EDIT: Yeah and Nope. Because I did my parser for the INI files and stuff.
Edited on 10 November 2015 - 03:30 PM
DannySMc #4
Posted 21 December 2015 - 02:41 PM
Does this get multiple values on a single line? As INI files do support multiple values per line, example:

[section]
key=value1,value2,value3
Creator #5
Posted 21 December 2015 - 03:59 PM
Does this get multiple values on a single line? As INI files do support multiple values per line, example:

[section]
key=value1,value2,value3

A variable with multiple values?
DannySMc #6
Posted 21 December 2015 - 05:34 PM
Does this get multiple values on a single line? As INI files do support multiple values per line, example:

[section]
key=value1,value2,value3

A variable with multiple values?
Pretty much what I said…
LeDark Lua #7
Posted 23 December 2015 - 08:12 AM
I'll add multi values, and I didn't know that ini's support that.
DannySMc #8
Posted 23 December 2015 - 08:58 AM
I'll add multi values, and I didn't know that ini's support that.

Yeah neither did I tbh, but when I was looking at the syntax, multiple values came up, so yeah, I made one, but of course it doesn't support it, and I don't really want to re-make it :D/>
LeDark Lua #9
Posted 23 December 2015 - 09:46 AM
UPDATED!

Added multi value support!

Ini file:

[TEST]
testas=1,2,Hello world! STR,3
Example:

os.loadAPI("ini")

local content=ini.retrieve("test.ini")

ini.write("testas.ini", {
 TEST={
  testas={
   123;
   "Hello world!";
   456;
  }
 }
})

print(content.TEST.testas)

for i=1, #content.TEST.testas do
 print(content.TEST.testas[i])
end