func Serve(args []string) { if len(args) < 1 { displayServeError("missing broker url", nil) } pwd, _ := os.Getwd() pd := file.ProjDirFrom(pwd) if pd == "" { displayServeError("must be called within social machines project", nil) } scope := rt.NewScope(nil) _, err := LoadProjectDir(pd, scope) if err != nil { displayServeError("failed to load project directory", err) } ln, port := rt.StartListening(10810) rt.RT.Port = port pname := filepath.Base(pd) body := encodeProject(pname, port) postErr := postProjectToBroker(args[0], pname, body) if postErr != nil { displayServeError("failed to post project to broker", err) } log.Printf("Serving '%s' on %d => %s\n", pname, port, args[0]) log.Fatal(http.Serve(ln, nil)) }
func NewBlock(b *Block, s *rt.Scope) rt.Value { base := rt.NewScope(nil) for _, arg := range b.Args { base.Insert(arg, 0) } scope := base.AppendScope(s) obj := rt.CreateObject(b, scope, 0) return obj }
func StartConsole(ver string) { scope := rt.NewScope(nil) pwd, _ := os.Getwd() pd := file.ProjDirFrom(pwd) if pd == "" { fmt.Printf("Social Machines (v%s). Type ':exit' to exit.\n", ver) startREPL(scope) } else { ps, err := LoadProjectDir(pd, scope) if err != nil { displayConsoleError("failed to load project directory", err) } fmt.Printf("%s // Social Machines (v%s). Type ':exit' to exit.\n", filepath.Base(pd), ver) startREPL(ps) } }