New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mismatched types gioui.org/ui.pc and .
when importing Gio package
#320
Comments
Thanks for the report. Importing the same package multiple times is not well handled and may cause undefined behaviour, in addition to the initial import |
@theclapp I'm trying to reproduce, but gioui.org/ui does not seem to exist anymore, and the links you provided are 404s now. Could you please provide a valid (and complete this time) sample for reproduction? |
Sorry about that, and thanks for checking in on this bug. A permalink to the current Gio hello.go example is here. The full-text is // SPDX-License-Identifier: Unlicense OR MIT
package main
// A simple Gio program. See https://gioui.org for more information.
import (
"image/color"
"log"
"os"
"gioui.org/app"
"gioui.org/io/system"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/text"
"gioui.org/widget/material"
"gioui.org/font/gofont"
)
func main() {
go func() {
w := app.NewWindow()
if err := loop(w); err != nil {
log.Fatal(err)
}
os.Exit(0)
}()
app.Main()
}
func loop(w *app.Window) error {
th := material.NewTheme(gofont.Collection())
var ops op.Ops
for {
e := <-w.Events()
switch e := e.(type) {
case system.DestroyEvent:
return e.Err
case system.FrameEvent:
gtx := layout.NewContext(&ops, e)
l := material.H1(th, "Hello, Gio")
maroon := color.RGBA{127, 0, 0, 255}
l.Color = maroon
l.Alignment = text.Middle
l.Layout(gtx)
e.Frame(gtx.Ops)
}
}
} But it might be moot at this point. Does yaegi support yaegi hello.go
unable to find source related to: "unsafe" So if y'all don't support The specific line I cited in Again though, since Gio uses |
Yes, by default unsafe is disabled in yaegi. |
@theclapp btw, support for unsafe has been introduced now, notably through the use of the |
Not as such, in that it's not crashing on that problem any more. Yaegi still cannot run the Gio "hello" program directly:
|
I did figure out how to get Yaegi to call already-compiled Gio code, and I think that's good enough. // SPDX-License-Identifier: Unlicense OR MIT
package main
// A simple Gio program. See https://gioui.org for more information.
import (
"fmt"
"image/color"
"os"
"reflect"
"time"
"github.com/traefik/yaegi/interp"
"github.com/traefik/yaegi/stdlib"
"github.com/traefik/yaegi/stdlib/unrestricted"
"gioui.org/app"
"gioui.org/font/gofont"
"gioui.org/io/system"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/text"
"gioui.org/widget/material"
)
func main() {
i := interp.New(interp.Options{})
i.Use(stdlib.Symbols)
i.Use(unrestricted.Symbols)
i.Use(map[string]map[string]reflect.Value{
"gioui.org/app": {
"NewWindow": reflect.ValueOf(app.NewWindow),
"Main": reflect.ValueOf(app.Main),
},
"ext": {
"loop": reflect.ValueOf(loop),
},
})
fmt.Println("Starting yaegi code")
_, err := i.Eval(`
package main
import (
"fmt"
"log"
"os"
"ext" // see i.Use() above
"gioui.org/app"
)
var invalidate func()
var s = "Hello, Gio!"
func Start() {
fmt.Println("In yaegi code")
go func() {
fmt.Println("main func starting")
w := app.NewWindow()
invalidate = func() { w.Invalidate() }
if err := ext.loop(w, func() string { return s }); err != nil {
log.Fatal(err)
}
os.Exit(0)
}()
app.Main()
}
`)
if err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}
// Reassign an interpreted variable while the GUI is running.
go func() {
time.Sleep(2 * time.Second)
fmt.Println("redefining s")
_, err := i.Eval(`
s = "hey look this changed"
invalidate()
`)
if err != nil {
fmt.Printf("Error: %v\n", err)
}
fmt.Println("done redefining s")
}()
_, err = i.Eval("Start()")
if err != nil {
fmt.Printf("Error: %v\n", err)
}
fmt.Println("Yaegi code returned")
}
func loop(w *app.Window, f func() string) error {
fmt.Println("loop func starting")
th := material.NewTheme(gofont.Collection())
var ops op.Ops
for {
e := <-w.Events()
switch e := e.(type) {
case system.DestroyEvent:
return e.Err
case system.FrameEvent:
gtx := layout.NewContext(&ops, e)
// l := material.H1(th, "Hello, Gio")
l := material.H1(th, f())
maroon := color.NRGBA{R: 127, G: 0, B: 0, A: 255}
l.Color = maroon
l.Alignment = text.Middle
l.Layout(gtx)
e.Frame(gtx.Ops)
}
}
} |
@whereswaldon beat me to it, by a long shot (in terms of functionality; he posted this yesterday): demo.mp4Code here. |
Very nice integration of yaegi with a pre-compiled package, here gio (where there is no other choice, due to the C binding). Congrats! A playground for graphic UI makes also a lot of sense 👍 |
What a cool demo! |
Thanks! I plan to extend that demo to be a playground for gio a la play.golang.org. Yaegi works just fine when compiled to WASM, which enables some really cool applications! Thanks to everyone who built it! |
Possibly related to #90 or #308.
I am trying to run the Gio "hello, world" program from within Yaegi. (Toplevel here.) Yaegi throws an error on this line:
As indicated, the error is
mismatched types gioui.org/ui.pc and .
.So first of all, the error message appears to be truncated. And second of all,
r.pc
andb.endPC
are the same type.If I try to import the package multiple times, it fails twice, then succeeds, and then panics:
The text was updated successfully, but these errors were encountered: