Lib creates an EnvOption out of a Library, allowing libraries to be provided as functional args, and to be linked to each other.
(l Library)
| 101 | // Lib creates an EnvOption out of a Library, allowing libraries to be provided as functional args, |
| 102 | // and to be linked to each other. |
| 103 | func Lib(l Library) EnvOption { |
| 104 | singleton, isSingleton := l.(SingletonLibrary) |
| 105 | return func(e *Env) (*Env, error) { |
| 106 | if isSingleton { |
| 107 | if e.HasLibrary(singleton.LibraryName()) { |
| 108 | return e, nil |
| 109 | } |
| 110 | e.ensureMutableLibraries() |
| 111 | e.libraries[singleton.LibraryName()] = singleton |
| 112 | } |
| 113 | var err error |
| 114 | for _, opt := range l.CompileOptions() { |
| 115 | e, err = opt(e) |
| 116 | if err != nil { |
| 117 | return nil, err |
| 118 | } |
| 119 | } |
| 120 | e.progOpts = append(e.progOpts, l.ProgramOptions()...) |
| 121 | return e, nil |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | // StdLibOption specifies a functional option for configuring the standard CEL library. |
| 126 | type StdLibOption func(*stdLibrary) *stdLibrary |