mirror of https://github.com/Hilbis/Hilbish
fix(fs): make stat better
return a table with 4 values: name, size, mode and isDir name -> name of path size -> size (obviously) mode -> permissions mode in a string as octal format isDir -> whether path is a directorypull/78/head
parent
df70082a81
commit
6b065dc035
|
@ -3,6 +3,7 @@
|
||||||
package fs
|
package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -72,13 +73,17 @@ func fmkdir(L *lua.LState) int {
|
||||||
func fstat(L *lua.LState) int {
|
func fstat(L *lua.LState) int {
|
||||||
path := L.CheckString(1)
|
path := L.CheckString(1)
|
||||||
|
|
||||||
// TODO: handle error here
|
|
||||||
pathinfo, err := os.Stat(path)
|
pathinfo, err := os.Stat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
luaErr(L, err.Error())
|
luaErr(L, err.Error())
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
L.Push(luar.New(L, pathinfo))
|
statTbl := L.NewTable()
|
||||||
|
L.SetField(statTbl, "name", lua.LString(pathinfo.Name()))
|
||||||
|
L.SetField(statTbl, "size", lua.LNumber(pathinfo.Size()))
|
||||||
|
L.SetField(statTbl, "mode", lua.LString("0" + strconv.FormatInt(int64(pathinfo.Mode().Perm()), 8)))
|
||||||
|
L.SetField(statTbl, "isDir", lua.LBool(pathinfo.IsDir()))
|
||||||
|
L.Push(statTbl)
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue