starc2one

command module
v0.0.0-...-a4a7816 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 14 Imported by: 0

README

starc2one (starlark compile to a single file)

compile starlark source file(and the modules it depends on) to a single file OR execute compile file in REPL

WHY


Sometimes you want a single starlark file to run in your host program, you can use it

HOW


  • 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

INSTALLATION


go install github.com/lockval/starc2one@latest

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL