Compile returns a compiled bytecode with given filename.
(filePath string, opts ...EvalOption)
| 1137 | |
| 1138 | // Compile returns a compiled bytecode with given filename. |
| 1139 | func (ctx *Context) CompileFile(filePath string, opts ...EvalOption) ([]byte, error) { |
| 1140 | b, err := os.ReadFile(filePath) |
| 1141 | if err != nil { |
| 1142 | return nil, err |
| 1143 | } |
| 1144 | |
| 1145 | options := EvalOptions{} |
| 1146 | for _, fn := range opts { |
| 1147 | fn(&options) |
| 1148 | } |
| 1149 | if options.filename == "" { |
| 1150 | opts = append(opts, EvalFileName(filePath)) |
| 1151 | } |
| 1152 | |
| 1153 | return ctx.Compile(string(b), opts...) |
| 1154 | } |
| 1155 | |
| 1156 | // Global returns a context's global object. |
| 1157 | func (ctx *Context) Globals() *Value { |