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)
| 91 | // Lib creates an EnvOption out of a Library, allowing libraries to be provided as functional args, |
| 92 | // and to be linked to each other. |
| 93 | func Lib(l Library) EnvOption { |
| 94 | singleton, isSingleton := l.(SingletonLibrary) |
| 95 | return func(e *Env) (*Env, error) { |
| 96 | if isSingleton { |
| 97 | if e.HasLibrary(singleton.LibraryName()) { |
| 98 | return e, nil |
| 99 | } |
| 100 | e.libraries[singleton.LibraryName()] = singleton |
| 101 | } |
| 102 | var err error |
| 103 | for _, opt := range l.CompileOptions() { |
| 104 | e, err = opt(e) |
| 105 | if err != nil { |
| 106 | return nil, err |
| 107 | } |
| 108 | } |
| 109 | e.progOpts = append(e.progOpts, l.ProgramOptions()...) |
| 110 | return e, nil |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | // StdLibOption specifies a functional option for configuring the standard CEL library. |
| 115 | type StdLibOption func(*stdLibrary) *stdLibrary |