-
Notifications
You must be signed in to change notification settings - Fork 1
/
object.go
65 lines (51 loc) · 1 KB
/
object.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
package mruby
import "fmt"
type RBasic interface {
Class() RClass
Flags() uint32
}
type RObject interface {
RBasic
ivPut(Symbol, Value)
ivGet(Symbol) Value
}
var _ RBasic = &Object{}
var _ RObject = &Object{}
type Object struct {
class RClass
flags uint32
iv
}
func (obj *Object) Class() RClass {
return obj.class
}
func (obj *Object) Flags() uint32 {
return obj.flags
}
func (obj *Object) ivPut(sym Symbol, val Value) {
if obj.iv == nil {
obj.iv = make(iv)
}
obj.iv.Put(sym, val)
}
func (obj *Object) ivGet(sym Symbol) Value {
if obj.iv == nil {
return nil
}
return obj.iv.Get(sym)
}
func anyToString(mrb *State, obj Value) Value {
className := mrb.ObjectClassName(obj)
return fmt.Sprintf("#<%s:%p>", className, obj)
}
func initObject(mrb *State) (err error) {
mrb.FalseClass, err = mrb.DefineClassId(_FalseClass(mrb), mrb.ObjectClass)
if err != nil {
return err
}
mrb.TrueClass, err = mrb.DefineClassId(_TrueClass(mrb), mrb.ObjectClass)
if err != nil {
return err
}
return nil
}