Difference between revisions of "MiniFS"

m
(Moonscript)
 
(One intermediate revision by the same user not shown)
Line 10: Line 10:
 
== Examples ==
 
== Examples ==
 
=== Moonscript ===
 
=== Moonscript ===
<source lang="coffeescript">
+
<source lang="lua">
fs = require "minifs"
+
fs = require("minifs")
 +
print(fs.system(true)) -- print the operating system
 
fs.mkdir("test")
 
fs.mkdir("test")
fs.write("test/test.txt", "Hello")
+
fs.write("test/test.txt", "Hello") -- write to a file in one line without file handles
 
fs.mkdir("test/test2")
 
fs.mkdir("test/test2")
 
fs.move("test/test.txt", "test/test2/test.txt")
 
fs.move("test/test.txt", "test/test2/test.txt")
 
fs.usetmp((path) ->
 
fs.usetmp((path) ->
 +
    -- path is a temporary file that is removed when the function ends
 
     print(path)
 
     print(path)
 
)
 
)
fs.rmdir("test", true)
+
fs.rmdir("test", true) -- recursive remove
 
</source>
 
</source>
  
 
=== Lua ===
 
=== Lua ===
 
<source lang="lua">
 
<source lang="lua">
fs = require "minifs"
+
fs = require("minifs")
 +
print(fs.system(true)) -- print the operating system
 
fs.mkdir("test")
 
fs.mkdir("test")
fs.write("test/test.txt", "Hello")
+
fs.write("test/test.txt", "Hello") -- write to a file in one line without file handles
 
fs.mkdir("test/test2")
 
fs.mkdir("test/test2")
 
fs.move("test/test.txt", "test/test2/test.txt")
 
fs.move("test/test.txt", "test/test2/test.txt")
 
fs.usetmp(function(path)
 
fs.usetmp(function(path)
 +
    -- path is a temporary file that is removed when the function ends
 
     print(path)
 
     print(path)
 
end)
 
end)
fs.rmdir("test", true)
+
fs.rmdir("test", true) -- recursive remove
 
</source>
 
</source>
  
 
[[Category:Libraries]]
 
[[Category:Libraries]]

Latest revision as of 18:17, 21 May 2016


MiniFS is a small but powerful module for easy filesystem access. It uses LuaFileSystem, the Lua standard I/O module and the standard OS module to form a convenient API.

MiniFS is written in MoonScript, a language that compiles to Lua. There is a pre-compiled version in the repository if you don't want to embed Moonscript in your Lua programs.

You can grab it from GitLab. Documentation of the module can be seen here. You can also install it through LuaRocks.

Examples

Moonscript

fs = require("minifs")
print(fs.system(true)) -- print the operating system
fs.mkdir("test")
fs.write("test/test.txt", "Hello") -- write to a file in one line without file handles
fs.mkdir("test/test2")
fs.move("test/test.txt", "test/test2/test.txt")
fs.usetmp((path) ->
    -- path is a temporary file that is removed when the function ends
    print(path)
)
fs.rmdir("test", true) -- recursive remove

Lua

fs = require("minifs")
print(fs.system(true)) -- print the operating system
fs.mkdir("test")
fs.write("test/test.txt", "Hello") -- write to a file in one line without file handles
fs.mkdir("test/test2")
fs.move("test/test.txt", "test/test2/test.txt")
fs.usetmp(function(path)
    -- path is a temporary file that is removed when the function ends
    print(path)
end)
fs.rmdir("test", true) -- recursive remove