-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue.go
75 lines (58 loc) · 1.1 KB
/
value.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
package lua
import "github.com/tsatke/lua/internal/engine/value"
type Value interface {
_val()
}
type nilType uint8
func (nilType) _val() {}
type boolType uint8
func (boolType) _val() {}
type Number float64
func (Number) _val() {}
type String string
func (String) _val() {}
var (
Nil = nilType(0)
False = boolType(0)
True = boolType(1)
)
type Values []Value
func (v Values) Count() int {
return len(v)
}
func (v Values) Get(index int) Value {
if index > len(v) {
return Nil
}
return v[index]
}
func valuesFromInternal(vs ...value.Value) Values {
var vals Values
for _, v := range vs {
var val Value
switch v.Type() {
case value.TypeNil:
val = Nil
case value.TypeBoolean:
if !v.(value.Boolean) {
val = False
} else {
val = True
}
case value.TypeNumber:
val = Number(v.(value.Number))
case value.TypeString:
val = String(v.(value.String))
case value.TypeFunction:
fallthrough
case value.TypeUserdata:
fallthrough
case value.TypeThread:
fallthrough
case value.TypeTable:
panic("unsupported")
}
vals = append(vals, val)
}
return vals
}