main.go 831 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. The zygomys command line REPL is known as `zygo`.
  3. */
  4. package main
  5. // START OMIT
  6. import (
  7. ...
  8. zygo "github.com/glycerine/zygomys/repl"
  9. )
  10. func main() {
  11. // (1) configure it
  12. // See library configuration convention: https://github.com/glycerine/configs-in-golang
  13. cfg := zygo.NewGlispConfig("zygo")
  14. // (2) register your Go structs; give them a nickname
  15. // here we register snoopy as a handle to Go struct &Snoopy{}
  16. zygo.GoStructRegistry.RegisterUserdef("snoopy",
  17. &zygo.RegisteredType{GenDefMap: true,
  18. Factory: func(env *zygo.Glisp) (interface{}, error) {
  19. return &Snoopy{}, nil
  20. }}, true)
  21. // (3) run the zygo repl
  22. // -- the library does all the heavy lifting.
  23. zygo.ReplMain(cfg)
  24. }
  25. // END OMIT
  26. func usage(myflags *flag.FlagSet) {
  27. fmt.Printf("zygo command line help:\n")
  28. myflags.PrintDefaults()
  29. os.Exit(1)
  30. }