-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsummary_lua.go
42 lines (34 loc) · 1.02 KB
/
summary_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
package disk
import (
"fmt"
"github.com/vela-ssoc/vela-kit/lua"
"strings"
)
func (sum *summary) String() string { return fmt.Sprintf("%p", sum) }
func (sum *summary) Type() lua.LValueType { return lua.LTObject }
func (sum *summary) AssertFloat64() (float64, bool) { return 0, false }
func (sum *summary) AssertString() (string, bool) { return "", false }
func (sum *summary) AssertFunction() (*lua.LFunction, bool) { return nil, false }
func (sum *summary) Peek() lua.LValue { return sum }
func (sum *summary) check(L *lua.LState) {
sum.Update()
err := sum.fail.Wrap()
if err != nil {
L.RaiseError("disk info got fail %v", err)
return
}
}
func (sum *summary) Index(L *lua.LState, key string) lua.LValue {
sum.check(L)
if strings.HasPrefix(key, "dev_") {
return sum.devL(key[4:])
}
return lua.LNil
}
func (sum *summary) devL(name string) lua.LValue {
dev := sum.LookupDevice(name)
if dev == nil {
return lua.LNil
}
return dev
}