-
Notifications
You must be signed in to change notification settings - Fork 0
/
nullobj.go
136 lines (112 loc) · 2.37 KB
/
nullobj.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package internal
import (
"fmt"
G "github.com/ionous/sashimi/game" // iobject
"github.com/ionous/sashimi/util/ident"
"log" // because we can be constructed globally
"runtime"
)
// FIX? generate the implemenation via "go generate"
type _Null struct {
path PropertyPath
pc uintptr
}
func NullObject(name string) G.IObject {
path := RawPath(name)
return NullObjectSource(path, 1)
}
func NullObjectSource(path PropertyPath, skip int) G.IObject {
pc := []uintptr{0}
runtime.Callers(skip+1, pc) // 0 is callers itself, 1 is this code
return _Null{path, pc[0]}
}
func (null _Null) println(args ...interface{}) {
log.Println(append([]interface{}{null.String()}, args...))
}
func (null _Null) ParentRelation() (G.IObject, string) {
return null, ""
}
//
func (null _Null) String() string {
var str string
f := runtime.FuncForPC(null.pc - 1)
if f != nil {
file, line := f.FileLine(null.pc - 1)
str = fmt.Sprintf("(%s:%d)", file, line)
}
return "<NullObject " + null.path.String() + str + ">"
}
//
func (null _Null) Id() ident.Id {
return ident.Empty()
}
//
func (null _Null) Exists() bool {
return false
}
//
func (null _Null) FromClass(cls string) bool {
return false
}
//
func (null _Null) Is(c string) (ret bool) {
null.println("Is", c)
return
}
//
func (null _Null) IsNow(c string) {
null.println("IsNow", c)
}
func (null _Null) Equals(r G.IObject) bool {
return false
}
//
func (null _Null) Get(p string) G.IValue {
null.println("Get", p)
return nullValue(null.path.Add(p))
}
func (null _Null) List(p string) G.IList {
null.println("List", p)
return nullList(null.path.Add(p))
}
//
func (null _Null) Num(p string) (ret float64) {
null.println("Num", p)
return
}
//
func (null _Null) SetNum(p string, v float64) {
null.println("SetNum", p, v)
}
//
func (null _Null) Object(c string) G.IObject {
null.println("Object", c)
return null
}
//
func (null _Null) ObjectList(c string) (ret []G.IObject) {
null.println("ObjectList", c)
return
}
//
func (null _Null) Set(c string, _ G.IObject) {
null.println("Set", c)
}
//
func (null _Null) Text(p string) (ret string) {
null.println("Text", p)
return
}
//
func (null _Null) SetText(p string, v string) {
null.println("SetText", p, v)
}
//
func (null _Null) Go(s string, _ ...G.IObject) G.IPromise {
null.println("Go", s)
return NewPendingChain(nil, nil)
}
//
func (null _Null) Says(s string) {
null.println("Says", s)
}