Skip to content

Commit ed81a47

Browse files
committed
cue: allow getting Runtime from Instance
Needed for goc Codec and probably useful across the board. Change-Id: Ib3e2c0b514a09815375f77d3d05d33e0411d20c2 Reviewed-on: https://cue-review.googlesource.com/c/cue/+/2710 Reviewed-by: Marcel van Lohuizen <[email protected]>
1 parent 48d8732 commit ed81a47

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

cue/build.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"cuelang.org/go/cue/errors"
2828
"cuelang.org/go/cue/format"
2929
"cuelang.org/go/cue/token"
30+
"cuelang.org/go/internal"
3031
)
3132

3233
// A Runtime is used for creating CUE interpretations.
@@ -38,6 +39,12 @@ type Runtime struct {
3839
idx *index
3940
}
4041

42+
func init() {
43+
internal.GetRuntime = func(instance interface{}) interface{} {
44+
return &Runtime{idx: instance.(*Instance).index}
45+
}
46+
}
47+
4148
func dummyLoad(token.Pos, string) *build.Instance { return nil }
4249

4350
func (r *Runtime) index() *index {

internal/internal.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,6 @@ var DropOptional bool
5353

5454
// UnifyBuiltin returns the given Value unified with the given builtin template.
5555
var UnifyBuiltin func(v interface{}, kind string) interface{}
56+
57+
// GetRuntime reports the runtime for an Instance.
58+
var GetRuntime func(instance interface{}) interface{}

0 commit comments

Comments
 (0)