compile starlark source file(and the modules it depends on) to a single file OR execute compile file in REPL
Sometimes you want a single starlark file to run in your host program, you can use it
- compile a module to a single file :
starc2one -file main.star -output main.sbin
- compile src dir to a single file :
starc2one -file src -output main.sbin -suffix .star
- execute compile file in REPL (You can access all modules via module2exports) :
starc2one -file main.sbin
- load it in your golang program :
file, err := os.OpenFile(*argFile, os.O_RDONLY, 0600)
check(err)
defer file.Close()
program, err := starlark.CompiledProgram(file)
check(err)
thread := &starlark.Thread{Name: "exec " + *argFile}
globals, err := program.Init(thread, nil)
check(err)
globals.Freeze()
- There is a predeclared "globalThis" in starc2one. :
predeclared["globalThis"] = &starlarkstruct.Module{Name: "testModule", Members: starlark.StringDict{"test": starlark.String("hello")}}
globals, err := program.Init(thread, predeclared)
def test():
print(globalThis.test)
- more help :
starc2one -help
go install github.com/lockval/starc2one@latest