Program: Config API
Version: 1.0
Author: ben657
Description: This API allows you to easily make configs for
your users to edit, rather than them having to
read code and edit variables. These files can
then be read by this API and the values can be
used in your programs.
Installing
To use this API, copy and paste the code into a blank document, and follow the steps below for how you want it to work.
- World-wide usage (any computer in the world/server can use the API)
- Copy the document into "modsComputerCraftluaromapis" naming it as "config".
- Per-computer usage (only the computer installed on can use the API)
- Use cc-get or copy the document into the computer that needs to use its file system.
Code: Pastie
cc-get: cc-get install config-api (info)
Usage
config.load(directory,fileName)
This method allows you to load a config to memory,
so you can read and write variables to it.
If no file is found, one will be created.
directory - The folder to look in for the file.
fileName - The file to look for in the directory.
config.load("foo","bar") --[[ Finds the file at "/foo/bar" ]]
config.writeVal(key,value)
This method allows you to store avalue with a given name
into the internal memory.
It will not be saved to file until config.save() is called.
key - The name of the value in the config.
value - The value to store in the config.
config.writeVal("foo","bar") --[[ Writes the value "bar" with the name "foo" in the config, it will look like "foo = bar" in the file. ]]
[/CODE]
[i]config.readVal(key)[/i]
This method allows you to read a value from the loaded config.
[i]key [/i]- The name of the value to be read.
[CODE]
var = config.readVal("foo") --[[ Going off the last example, this will return the value "bar" into the variable. ]]
config.save()
This method commits all changes to the config to file, in the currently
loaded path.
config.save() --[[ Going off the last example, the file "/foo/bar" will have "foo = bar" written to it on the top line. ]]
[/CODE]
[b][size=5]Notes[/size][/b]
Please feel free to use the API, but if you need people to download it, please link to this page, or at least credit
me in your post, a little recognition is all I ask!
Also, any bugs or errors, give me a shout in this topic and i'll do my best to help you out!
Finally, i'd love for anyone to give me suggestions on anything you'd like added to the API.