(ctx context.Context, name string)
| 383 | } |
| 384 | |
| 385 | func (h *shellCallHandler) StateLookup(ctx context.Context, name string) (*ShellState, error) { |
| 386 | if h.Debug() { |
| 387 | shellDebug(ctx, "StateLookup", name) |
| 388 | } |
| 389 | |
| 390 | def := h.GetDef(nil) |
| 391 | |
| 392 | // 1. Function in current context (module or core) |
| 393 | if def.HasMainFunction(name) { |
| 394 | st := h.NewState() |
| 395 | return &st, nil |
| 396 | } |
| 397 | |
| 398 | // Module-specific lookups |
| 399 | if def.HasModule() { |
| 400 | // 2. Is it the current module's name (or ".")? |
| 401 | // Treat as the module's named constructor function on Query. |
| 402 | if def.Name == name || name == "." { |
| 403 | st := h.NewState() |
| 404 | return &st, nil |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | // 4. Path to local or remote module source |
| 409 | def, _, err := h.maybeLoadModule(ctx, name) |
| 410 | if err != nil { |
| 411 | return nil, err |
| 412 | } |
| 413 | if def != nil { |
| 414 | st := h.newModState(def.SourceDigest) |
| 415 | return &st, nil |
| 416 | } |
| 417 | |
| 418 | return nil, fmt.Errorf("function or module %q not found", name) |
| 419 | } |
| 420 | |
| 421 | func (h *shellCallHandler) constructorCall(ctx context.Context, md *moduleDef, st *ShellState, args []string) (*ShellState, error) { |
| 422 | fn := md.ModuleConstructor() |
no test coverage detected