Skip to content

lockval/starc2one

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

starlark compile to a single file

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages