-
Notifications
You must be signed in to change notification settings - Fork 1
/
variable.go
39 lines (30 loc) · 957 Bytes
/
variable.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
package mruby
type ivTable map[Symbol]Value
type iv = ivTable
func (iv ivTable) Get(sym Symbol) Value {
return iv[sym]
}
func (iv ivTable) Put(sym Symbol, val Value) {
iv[sym] = val
}
func (mrb *State) ObjectInstanceVariableSetForce(obj RObject, name Symbol, val Value) {
obj.ivPut(name, val)
}
func (mrb *State) ObjectInstanceVariableGet(obj RObject, name Symbol) Value {
return obj.ivGet(name)
}
func (mrb *State) ObjectInstanceVariableDefined(obj RObject, name Symbol) bool {
return obj.ivGet(name) != nil
}
func (mrb *State) DefineConstById(klass RClass, name Symbol, val Value) {
mrb.ObjectInstanceVariableSetForce(klass, name, val)
}
func (mrb *State) VmGetConst(sym Symbol) Value {
klass := mrb.ObjectClass
return mrb.ObjectInstanceVariableGet(klass, sym)
}
func (mrb *State) VmSetConst(sym Symbol, val Value) {
// NOTE: Find class in current context
klass := mrb.ObjectClass
mrb.ObjectInstanceVariableSetForce(klass, sym, val)
}