filesystem utility for gopher-lua. This project is inspired by layeh/gopher-lfs.
go get github.com/kohkimakimoto/gluafs
Returns true if the file exists.
Reads file content and return it. If this function fails, it returns nil
, plus a string describing the error.
Writes content to the file. If this function fails, it returns nil
, plus a string describing the error.
Create directory. If this function fails, it returns nil
, plus a string describing the error.
Remove path. If this function fails, it returns nil
, plus a string describing the error.
Create symbolic link. If this function fails, it returns nil
, plus a string describing the error.
Returns all but the last element of path.
Returns the last element of path.
Returns the real path of a given path in the os. If this function fails, it returns nil
, plus a string describing the error.
Returns the current working directory. If this function fails, it returns nil
, plus a string describing the error.
Changes the current working directory. If this function fails, it returns nil
, plus a string describing the error.
Returns the script file path. If this function fails, it returns nil
, plus a string describing the error.
Returns the directory path that is parent of the script file. If this function fails, it returns nil
, plus a string describing the error.
Run the callback function with the files matching pattern. See below example:
local fs = require("fs")
local ret, err = fs.glob("/tmp/*", function(file)
print(file.path)
print(file.realpath)
end)
package main
import (
"github.com/yuin/gopher-lua"
"github.com/kohkimakimoto/gluafs"
)
func main() {
L := lua.NewState()
defer L.Close()
L.PreloadModule("fs", gluafs.Loader)
if err := L.DoString(`
local fs = require("fs")
local ret = fs.exists("path/to/file")
`); err != nil {
panic(err)
}
}
Kohki Makimoto kohki.makimoto@gmail.com
MIT license.