This tutorial will cover on how to make a real, useful API. But before making this api, make sure you have made Your first API and a Apiloader. If you allready have done those, let's make a Custom File API, which will simplify reading and writing files.
Let's get working. Open the folder "api" and create a file named "file"
-- Custom File API v. 1.0 -- Written by Brainless243 -- Posted to The Tekkit Wiki on 24/10/2012 function read(sFile, mode) -- sFile stands for the file to read, and the modes are: "r" for just reading one line, and "a" for reading all lines local hRead = assert(fs.open(sFile, "r")) if mode == "r" then text = hRead.readLine() hRead.close() return text elseif mode == "a" then text = hRead.readAll() hRead.close() return text end end function write(sFile, mode, input) -- As before, sFile stands for the file to open, but the modes are diffrent. "w" is overwriting the existing document, "a" continues the document. Input is what to be written. local hWrite = assert(fs.open(sFile, mode)) text = hWrite.write(input) hWrite.close() return text end
And thats that. To call, for example, the read function, type
That will print whatever text is found in the file "potato".