github.com/emcfarlane/larking@v0.0.0-20220605172417-1704b45ee6c3/starlib/starlarkstruct/module.go (about)

     1  // Copyright 2017 The Bazel Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package starlarkstruct
     6  
     7  import (
     8  	"go.starlark.net/starlark"
     9  	"go.starlark.net/starlarkstruct"
    10  )
    11  
    12  // Module is an alias of "go.starlark.net/starlarkstruct.Module"
    13  type Module = starlarkstruct.Module
    14  
    15  // MakeModule may be used as the implementation of a Starlark built-in
    16  // function, module(name, **kwargs). It returns a new module with the
    17  // specified name and members.
    18  func MakeModule(_ *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
    19  	var name string
    20  	if err := starlark.UnpackPositionalArgs(b.Name(), args, nil, 1, &name); err != nil {
    21  		return nil, err
    22  	}
    23  	members := make(starlark.StringDict, len(kwargs))
    24  	for _, kwarg := range kwargs {
    25  		k := string(kwarg[0].(starlark.String))
    26  		members[k] = kwarg[1]
    27  	}
    28  	return &Module{Name: name, Members: members}, nil
    29  }