google / starlark-go

Starlark in Go: the Starlark configuration language, implemented in Go
BSD 3-Clause "New" or "Revised" License
2.26k stars 204 forks source link

Passing starlark.Dict arguments in starlark.Call #523

Closed mohamed--abdel-maksoud closed 5 months ago

mohamed--abdel-maksoud commented 5 months ago

script.star

def f(dict1, dict2):
    ....

from go, something like this

// arg1 and arg2 are starlark.Dict
starlark.Call(thread, globals["f"], starlark.Tuple{arg1, arg2}, nil))

fails with

./main.go:30:86: cannot use arg1 (variable of type starlark.Dict) 
as type starlark.Value in array or slice literal:
    starlark.Dict does not implement starlark.Value
      (Freeze method has pointer receiver)

Any help is appreciated. Thanks!

adonovan commented 5 months ago

starlark.Dict does not implement starlark.Value (Freeze method has pointer receiver)

The error message is trying to tell you that you need to pass the address of a string.Dict (&d, of type *string.Dict) to the Call function, because Dict itself does not satisfy the Value interface.