1 // Copyright 2021 CUE Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package cuecontext 16 17 import ( 18 "cuelang.org/go/cue" 19 "cuelang.org/go/internal/core/runtime" 20 21 _ "cuelang.org/go/pkg" 22 ) 23 24 // Option controls a build context. 25 type Option struct { 26 apply func(r *runtime.Runtime) 27 } 28 29 // New creates a new Context. 30 func New(options ...Option) *cue.Context { 31 r := runtime.New() 32 for _, o := range options { 33 o.apply(r) 34 } 35 return (*cue.Context)(r) 36 } 37 38 // An ExternInterpreter creates a compiler that can produce implementations of 39 // functions written in a language other than CUE. It is currently for internal 40 // use only. 41 type ExternInterpreter = runtime.Interpreter 42 43 // Interpreter associates an interpreter for external code with this context. 44 func Interpreter(i ExternInterpreter) Option { 45 return Option{func(r *runtime.Runtime) { 46 r.SetInterpreter(i) 47 }} 48 } 49