I've decided that they won't like anything similar so I decided to make something else.
Settings File API
Don't you have a program but you can't store any important settings or preferences or other necessary storage stuffies? This API is here to help!!! Please read the below stuff for information about how to set up a settings file and how to use the API. Please post any issues you find with the API and any suggestions for features I should add. I would also love if someone made an editor for settings files. Thanks for checking it out!
Pastebin: FTmDPGRF
On your computer, type: "pastebin get FtmDPGRF settings" or whatever you are supposed to type and it will appear for you.
This API is designed to handle a new type of file I created called a settings file. (Inspired by .ini files)
These are very user friendly and also computer-friendly with this new API. Here's how one would look:
; #Text editor settings file
printer_side: top
debug_mode: 0
last find = " coroutine.r"
[Colors]
text_background: 19
text_foreground: 18
window_border_background: 15
window_border foreground: 10
color_1: 8
[CustomShortcuts]
save = CtrlShiftS
print = CtrlShiftP
help = CtrlH
A settings file is supposed to look utterly simple. You probably understand all of the above already, right??Here are the features of a settings file:
Name-Value Data storage: Your information can be stored as a value, and can be referenced by a name.
For example:
printer_side = top
Simple, right?This simple method contains several features that will make you happier.
Automatic white space removal: names and values are trimmed of leading and ending whitespace. For example:
some key = hehehehe
is the exact same thing as:
some key=hehehehe
Your choice of symbol: You can also use a colon or equals sign as the separator! So:
printer side: top
is the same thing as
printer side = top
Types: Values can be of two types: strings or numbers. A number is anything that works as a number, and a string is anything that doesn't work as a number! When you read them with the API, it will return a value of the correct type. No specification is needed, the API will automatically detect types.Explicit String Declaration: You can even declare a string manually in a value and force it to be treated as a string using quotation marks. Anything within quotation marks won't be changed by the parser, and will be given to you directly. For example:
number_of_cows = "10"
Isn't the same thing as
number_of_cows = 10
Just as
text = " stuff"
Is not the same thing as
text = stuff
Comments: Anything after a semicolon is considered a comment. Pretty simple, huh?
Sections: You can declare a section by placing it's name in square brackets like this:
[section name]
name = value
othername = somevalue
Anything underneath a section title, all the way up to the next section title/file end, is part of that section. Any values you place at the top of the file without declaring a section are considered as unsectioned values, values that don't have a section.That's how a settings file looks. Here's how to use the simple API:
settings.openSettingsFile(filepath)
description: Opens a settings file and returns a handle to itfilepath: The file path of the settings file
returns: a settings file handle from the opened file
settingsfilehandle.addSection(name)
description: Adds a sectionname: Name of the section to add.
settingsfilehandle.getValue(key)
description: Gets a global/unsectioned value from it's namekey: Name of value to retrieve
returns: Value if exists, else nil
settingsfilehandle.getSectionedValue(section, key)
description: Gets a sectioned value from it's name and sectionsection: Section containing the sectioned value
key: Name of the value
returns: Value if exists, else nil
settingsfilehandle.setValue(key, value)
description: Sets a value according to it's name. If it doesn't exist, it gets created.key: Name of the value
value: Value to set it to
settingsfilehandle.setSectionedValue(section, key, value)
description: Sets a sectioned value based on it's name. If it doesn't exist, it gets created.section: Section containing the sectioned value
key: Name of the value
value: Value to set it to
settingsfilehandle.save(path)
description: Saves the settings file to the given path.path: Path to save the settings file to.
Here is an example of how to open the example file at the very beginning of this document, get the value of "printer_side", modify that value, insert a section, insert a sectioned value, and save the file.
os.loadAPI("settings")
local settingsfile = settings.openSettingsFile("examplefile")
print(settingsfile.getValue("printer_side"))
settingsfile.setValue("printer_side", "left")
settingsfile.addSection("Personal Information")
settingsfile.setSectionedValue("Personal Information", "Name", "Joe Shmoe")
settingsfile.save("examplefile")
os.unloadAPI("settings")