Home
Installation instructions
mrentrasil.github.io/fs.lua/setup
Example
Ok, this is an example of how you can make a mini project with fs.lua.
In this tutorial, you will learn how to make a custom fs module.
Directories
First, we need to initialize a module.
fs.lua
Let's do some basic functions.
local fslua = require("fslua")
local module = {}
-- read file function
module.read = function(name)
-- check if arguments exists
assert(name, "Argument 1 missing.")
-- calling C function
local content = fslua.readfile(name)
-- return value
if type(content) ~= nil then return content else return "Could not open file(file does not exists)." end
end
-- write file function
module.write = function(name, toWrite)
-- check if arguments exists
assert(name, "Argument 1 missing.")
assert(toWrite, "Argument 2 missing.")
-- calling C function
local success = fslua.writefile(name, toWrite)
-- return value
return success
end
return module
Now, we can use the functions.
main.lua
local fs = require("fs")
local file_content = fs.read("fs.lua")
print("file's content: "..file_content)
End
Tutorial finished! You can see the reference guide on the reference's tab.
License: MIT License