Skip to content

Question on custom types #35

@pgundlach

Description

@pgundlach

Not sure if this is the correct place to ask.

This is my code:

package main

import (
	"fmt"
	"log"

	"github.com/1set/starlight"
)

type T func(string) string

func A(in string) string {
	return "Hello " + in
}

func B(m T) {
	fmt.Println(m("World"))
}

var src = `B(A)`

func dothings() error {
	globals := map[string]interface{}{
		"A": A,
		"B": B,
	}
	_, err := starlight.Eval([]byte(src), globals, nil)
	return err
}

func main() {
	if err := dothings(); err != nil {
		log.Fatal(err)
	}
}

The result I get is:

2025/04/06 19:50:43 arg 0: expected type main.T got *starlark.Builtin
exit status 1

What would be a strategy to get this working? In my real application, I cannot change the signature of function B (I can write a wrapper around it).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions