-
Notifications
You must be signed in to change notification settings - Fork 9
/
util.go
52 lines (46 loc) · 969 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package lfs
import (
"os"
"path/filepath"
"github.com/yuin/gopher-lua"
)
func attributes(L *lua.LState, statFunc func(string) (os.FileInfo, error)) int {
fp := L.CheckString(1)
stat, err := statFunc(fp)
if err != nil {
L.Push(lua.LNil)
L.Push(lua.LString(err.Error()))
return 2
}
table := L.NewTable()
if err := attributesFill(table, stat); err != nil {
L.Push(lua.LNil)
L.Push(lua.LString(err.Error()))
return 2
}
if table.RawGetString("mode").String() == "link" {
if path, err := filepath.EvalSymlinks(fp); err == nil {
table.RawSetString("target", lua.LString(path))
}
}
if L.GetTop() > 1 {
requestName := L.CheckString(2)
L.Push(table.RawGetString(requestName))
return 1
}
L.Push(table)
return 1
}
func dirItr(L *lua.LState) int {
ud := L.CheckUserData(1)
f, ok := ud.Value.(*os.File)
if !ok {
return 0
}
names, err := f.Readdirnames(1)
if err != nil {
return 0
}
L.Push(lua.LString(names[0]))
return 1
}