-
Notifications
You must be signed in to change notification settings - Fork 0
/
dx_lua.go
79 lines (64 loc) · 1.56 KB
/
dx_lua.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package tail
import (
"fmt"
cond "github.com/vela-ssoc/vela-cond"
"github.com/vela-ssoc/vela-kit/lua"
"time"
)
func (dx *Dx) String() string { return fmt.Sprintf("%p", &dx) }
func (dx *Dx) Type() lua.LValueType { return lua.LTObject }
func (dx *Dx) AssertFloat64() (float64, bool) { return 0, false }
func (dx *Dx) AssertString() (string, bool) { return "", false }
func (dx *Dx) AssertFunction() (*lua.LFunction, bool) { return nil, false }
func (dx *Dx) Peek() lua.LValue { return dx }
func (dx *Dx) inotifyL(L *lua.LState) int {
xEnv.Spawn(0, dx.inotify)
return 0
}
func (dx *Dx) pollL(L *lua.LState) int {
n := L.IsInt(1)
td := time.Second * 30
if n > 0 {
td = time.Second * time.Duration(n)
}
xEnv.Spawn(0, func() {
dx.poll(td)
})
return 0
}
func (dx *Dx) onL(L *lua.LState) int {
dx.on.Check(L, 1)
dx.co = xEnv.Clone(L)
return 0
}
func (dx *Dx) runL(L *lua.LState) int {
e := dx.readDir()
if e != nil {
L.RaiseError("%s/%s run fail %v", dx.dir, dx.base, e)
}
return 0
}
func (dx *Dx) filterL(L *lua.LState) int {
if dx.cnd == nil {
dx.cnd = cond.CheckMany(L)
} else {
cnd := cond.CheckMany(L)
dx.cnd.Merge(cnd)
}
return 0
}
func (dx *Dx) Index(L *lua.LState, key string) lua.LValue {
switch key {
case "inotify":
return L.NewFunction(dx.inotifyL)
case "poll":
return L.NewFunction(dx.pollL)
case "filter":
return L.NewFunction(dx.filterL)
case "on":
return L.NewFunction(dx.onL)
case "run":
return L.NewFunction(dx.runL)
}
return lua.LNil
}