File: ronly.go

package info (click to toggle)
mumax3 3.10-9
  • links: PTS, VCS
  • area: contrib
  • in suites: trixie
  • size: 7,596 kB
  • sloc: makefile: 181; ansic: 155; sh: 77
file content (21 lines) | stat: -rw-r--r-- 631 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package script

import "reflect"

// read-only value (from script, but mutable from outside)
type reflectROnly struct {
	elem reflect.Value
}

func newReflectROnly(addr interface{}) *reflectROnly {
	elem := reflect.ValueOf(addr)
	if elem.Kind() == 0 {
		panic("variable/constant needs to be passed as pointer to addressable value")
	}
	return &reflectROnly{elem}
}

func (l *reflectROnly) Eval() interface{}  { return l.elem.Interface() }
func (l *reflectROnly) Type() reflect.Type { return l.elem.Type() }
func (l *reflectROnly) Child() []Expr      { return nil }
func (l *reflectROnly) Fix() Expr          { return NewConst(l) }