lorca_gui.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // package lorca_gui -- тип десктопного приложения для lorca
  2. package lorca_gui
  3. import (
  4. "fmt"
  5. "github.com/zserge/lorca"
  6. )
  7. // ЛоркаГуи -- тип десктопного приложения для lorca
  8. type ЛоркаГуи struct{}
  9. // НовЛоркаГуи -- создание нового типа десктопного приложения для lorca
  10. func НовЛоркаГуи() (*ЛоркаГуи, error) {
  11. ui, _ := lorca.New("", "", 480, 320)
  12. defer ui.Close()
  13. // Bind Go function to be available in JS. Go function may be long-running and
  14. // blocking - in JS it's represented with a Promise.
  15. ош := ui.Bind("add", func(a, b int) int { return a + b })
  16. if ош != nil {
  17. return nil, fmt.Errorf("НовЛоркаГуи(): ош=\n\t%w", ош)
  18. }
  19. // Call JS function from Go. Functions may be asynchronous, i.e. return promises
  20. n := ui.Eval(`Math.random()`).Float()
  21. fmt.Println(n)
  22. // Call JS that calls Go and so on and so on...
  23. m := ui.Eval(`add(2, 3)`).Int()
  24. fmt.Println(m)
  25. // Wait for the browser window to be closed
  26. <-ui.Done()
  27. return &ЛоркаГуи{}, nil
  28. }