summaryrefslogtreecommitdiff
path: root/pkg/config/lib/fossil/fossil.go
blob: bf49882aaf93a9b7d060df3c6a22d8b1e603eb26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package fossil

import (
	_ "embed"
	"go.nc0.fr/svgu/pkg/config"
	"go.starlark.net/starlark"
	"go.starlark.net/starlarkstruct"
	"sync"
)

var (
	once   = sync.Once{}
	fossil = starlark.StringDict{}
	//go:embed fossil.star
	fossilFile string
	fossilErr  error
)

// LoadFossilModule loads the Fossil module.
func LoadFossilModule(t *starlark.Thread) (starlark.StringDict, error) {
	once.Do(func() {
		env := starlark.StringDict{
			"module": starlark.NewBuiltin("module",
				config.InternModule),
			"make_module": starlark.NewBuiltin("mod",
				starlarkstruct.MakeModule),
		}
		fossil, fossilErr = starlark.ExecFile(t, "fossil.star", fossilFile, env)
	})

	return fossil, fossilErr
}