Skip to content
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

Fix spx getWidget #767

Merged
merged 4 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions tools/ispx/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/goplus/builder/ispx
go 1.21

require (
github.com/goplus/igop v0.24.0
github.com/goplus/igop v0.27.0
github.com/goplus/reflectx v1.2.2
github.com/goplus/spx v1.0.1-0.20240815092545-3df776b555a0
github.com/hajimehoshi/ebiten/v2 v2.7.8
Expand All @@ -19,9 +19,9 @@ require (
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect
github.com/goplus/canvas v0.1.0 // indirect
github.com/goplus/gogen v1.15.1 // indirect
github.com/goplus/gop v1.2.5 // indirect
github.com/goplus/mod v0.13.9 // indirect
github.com/goplus/gogen v1.15.2 // indirect
github.com/goplus/gop v1.2.6 // indirect
github.com/goplus/mod v0.13.10 // indirect
github.com/hajimehoshi/go-mp3 v0.3.4 // indirect
github.com/jezek/xgb v1.1.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand All @@ -45,6 +45,7 @@ require (
)

replace (
github.com/goplus/spx => ../../../spx
nighca marked this conversation as resolved.
Show resolved Hide resolved
github.com/hajimehoshi/oto => github.com/hajimehoshi/oto v1.0.1
github.com/srwiley/oksvg => github.com/qiniu/oksvg v0.2.0-no-charset
golang.org/x/image => golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d
Expand Down
22 changes: 9 additions & 13 deletions tools/ispx/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,19 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
github.com/gopherjs/gopherjs v0.0.0-20180708170036-38b413be4187/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 h1:l5lAOZEym3oK3SQ2HBHWsJUfbNBiTXJDeW2QDxw9AQ0=
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/goplus/c2go v0.7.25/go.mod h1:e9oe4jDVhGFMJLEGmPSrVkLuXbLZAEmAu0/uD6fSz5E=
github.com/goplus/c2go v0.7.26/go.mod h1:ePAStubV/ls8mmdPGQo6VfADTVd46rKuBemE4zzBDnA=
github.com/goplus/canvas v0.1.0 h1:Vx3f2+U8UANvWf5/01YsQYKNbZDm1GZCjhlEBFrQkeU=
github.com/goplus/canvas v0.1.0/go.mod h1:Rhcvo5qkpD9WuXFnvnXtrBSY97l6h7sXQuofrmiLNdM=
github.com/goplus/gogen v1.15.0/go.mod h1:92qEzVgv7y8JEFICWG9GvYI5IzfEkxYdsA1DbmnTkqk=
github.com/goplus/gogen v1.15.1 h1:iz/fFpOeldjwmnjLzEdNsZF2mCf+sOHJavbAvV3o7sY=
github.com/goplus/gogen v1.15.1/go.mod h1:92qEzVgv7y8JEFICWG9GvYI5IzfEkxYdsA1DbmnTkqk=
github.com/goplus/gop v1.2.5 h1:kBCcvJ7ONt3IqTUTNGb+n9JO1nwTp5STg1UUSEfvz/k=
github.com/goplus/gop v1.2.5/go.mod h1:5rLlryvlZhWLIBw1Rok8s0uvyO54vcYw/7sFLhqtNTc=
github.com/goplus/igop v0.24.0 h1:xyk344nspra5REuRxEx/9zSntmYeCp2PIlKeEBAED2Y=
github.com/goplus/igop v0.24.0/go.mod h1:YF1Xt/aVB2xWoPYqJr+mJPqUxoEXMcaUB30v7YMHUn0=
github.com/goplus/mod v0.13.9 h1:B9zZoHi2AzMltTSOFqZNVjqGlSMlhhNTWwEzVqhTQzg=
github.com/goplus/mod v0.13.9/go.mod h1:MibsLSftGmxaQq78YzUzNviyFwB9RtpMaoscufvEKH4=
github.com/goplus/gogen v1.15.2 h1:Q6XaSx/Zi5tWnjfAziYsQI6Jv6MgODRpFtOYqNkiiqM=
github.com/goplus/gogen v1.15.2/go.mod h1:92qEzVgv7y8JEFICWG9GvYI5IzfEkxYdsA1DbmnTkqk=
github.com/goplus/gop v1.2.6 h1:kog3c5Js+8EopqmI4+CwueXsqibnBwYVt5q5N7juRVY=
github.com/goplus/gop v1.2.6/go.mod h1:uREWbR1MrFaviZ4Mbx4ZCcAYDoqzO0iv1Qo6Np0Xx4E=
github.com/goplus/igop v0.27.0 h1:4Wk5CIdm3FI1w6d0Y8GO2IC9sgs4wwYdpizCgRdcfYs=
github.com/goplus/igop v0.27.0/go.mod h1:V8Kf/b4nrw0OPPodwnOYZPCpXvU+hqzuhSAXIToT0ME=
github.com/goplus/mod v0.13.10 h1:5Om6KOvo31daN7N30kWU1vC5zhsJPM+uPbcEN/FnlzE=
github.com/goplus/mod v0.13.10/go.mod h1:HDuPZgpWiaTp3PUolFgsiX+Q77cbUWB/mikVHfYND3c=
github.com/goplus/reflectx v1.2.2 h1:T1p20OIH/HcnAvQQNnDLwl6AZOjU34icsfc6migD6L8=
github.com/goplus/reflectx v1.2.2/go.mod h1:wHOS9ilbB4zrecI0W1dMmkW9JMcpXV7VjALVbNU9xfM=
github.com/goplus/spx v1.0.1-0.20240815092545-3df776b555a0 h1:lBl1gTGmG5Mabz4n6F5CUCBhrBVj2fzRCipPwPQDZl4=
github.com/goplus/spx v1.0.1-0.20240815092545-3df776b555a0/go.mod h1:UNZub8iRpxDvLpjJYYpiM7r36GqweTn2SNSKN49kG90=
github.com/hajimehoshi/ebiten/v2 v2.7.8 h1:QrlvF2byCzMuDsbxFReJkOCbM3O2z1H/NKQaGcA8PKk=
github.com/hajimehoshi/ebiten/v2 v2.7.8/go.mod h1:Ulbq5xDmdx47P24EJ+Mb31Zps7vQq+guieG9mghQUaA=
github.com/hajimehoshi/go-mp3 v0.3.2/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM=
Expand All @@ -64,7 +61,6 @@ github.com/qiniu/audio v0.2.1/go.mod h1:APMJRPaS4toviejZnDzzZ8wVyr12jqZhd3xfKr/q
github.com/qiniu/oksvg v0.2.0-no-charset h1:KKQg81v52pd5VyaxrF891igoOO50epKfFWkryYgntnE=
github.com/qiniu/oksvg v0.2.0-no-charset/go.mod h1:YCAOS1HFo2kMxfcFCjrJMeo93KGFYaBAKl7LvrAkltQ=
github.com/qiniu/x v1.11.5/go.mod h1:03Ni9tj+N2h2aKnAz+6N0Xfl8FwMEDRC2PAlxekASDs=
github.com/qiniu/x v1.13.9/go.mod h1:INZ2TSWSJVWO/RuELQROERcslBwVgFG7MkTfEdaQz9E=
github.com/qiniu/x v1.13.10 h1:J4Z3XugYzAq85SlyAfqlKVrbf05glMbAOh+QncsDQpE=
github.com/qiniu/x v1.13.10/go.mod h1:INZ2TSWSJVWO/RuELQROERcslBwVgFG7MkTfEdaQz9E=
github.com/srwiley/rasterx v0.0.0-20200120212402-85cb7272f5e9/go.mod h1:mvWM0+15UqyrFKqdRjY6LuAVJR0HOVhJlEgZ5JWtSWU=
Expand Down
17 changes: 16 additions & 1 deletion tools/ispx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ func main() {

var mode igop.Mode
ctx := igop.NewContext(mode)
gopbuild.RegisterPackagePatch(ctx, "github.com/goplus/spx", `
Copy link
Member

@visualfc visualfc Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RegisterPackagePatch 可以检查返回值 error ,判断是否存在语法错误。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done bfe2780

package spx

import (
. "github.com/goplus/spx"
)

func Gopt_Game_Gopx_GetWidget[T any](sg ShapeGetter, name string) *T {
widget := GetWidget_(sg, name)
if result, ok := widget.(interface{}).(*T); ok {
return result
} else {
panic("GetWidget: type mismatch")
}
}
`)
source, err := gopbuild.BuildFSDir(ctx, fs, "")
if err != nil {
log.Fatalln("Failed to build Go+ source:", err)
Expand All @@ -57,7 +73,6 @@ func main() {
// otherwise, it produces: "fatal error: unreachable method called. linker bug?"
type Gamer interface {
initGame(sprites []spx.Spriter) *spx.Game
getGame() *spx.Game
}
gameRun := func(game spx.Gamer, resource interface{}, gameConf ...*spx.Config) {
path := resource.(string)
Expand Down
10 changes: 6 additions & 4 deletions tools/ispx/pkg/github.com/goplus/spx/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ func init() {
"unsafe": "unsafe",
},
Interfaces: map[string]reflect.Type{
"Gamer": reflect.TypeOf((*q.Gamer)(nil)).Elem(),
"Shape": reflect.TypeOf((*q.Shape)(nil)).Elem(),
"Spriter": reflect.TypeOf((*q.Spriter)(nil)).Elem(),
"Widget": reflect.TypeOf((*q.Widget)(nil)).Elem(),
"Gamer": reflect.TypeOf((*q.Gamer)(nil)).Elem(),
"Shape": reflect.TypeOf((*q.Shape)(nil)).Elem(),
"ShapeGetter": reflect.TypeOf((*q.ShapeGetter)(nil)).Elem(),
"Spriter": reflect.TypeOf((*q.Spriter)(nil)).Elem(),
"Widget": reflect.TypeOf((*q.Widget)(nil)).Elem(),
},
NamedTypes: map[string]reflect.Type{
"Camera": reflect.TypeOf((*q.Camera)(nil)).Elem(),
Expand Down Expand Up @@ -95,6 +96,7 @@ func init() {
Funcs: map[string]reflect.Value{
"Exit__0": reflect.ValueOf(q.Exit__0),
"Exit__1": reflect.ValueOf(q.Exit__1),
"GetWidget_": reflect.ValueOf(q.GetWidget_),
"Gopt_Game_Main": reflect.ValueOf(q.Gopt_Game_Main),
"Gopt_Game_Reload": reflect.ValueOf(q.Gopt_Game_Reload),
"Gopt_Game_Run": reflect.ValueOf(q.Gopt_Game_Run),
Expand Down
Loading