Skip to content

Commit

Permalink
Merge pull request #1584 from visualfc/fntype
Browse files Browse the repository at this point in the history
cl: fnType support TyTemplateRecvMethod overload funcs
  • Loading branch information
xushiwei committed Dec 21, 2023
2 parents d95b6e2 + b687dab commit d7480a4
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 51 deletions.
101 changes: 101 additions & 0 deletions cl/compile_spx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,3 +792,104 @@ func (this *Kai) onMsg(msg string) {
}
`, "Game.tgmx", "Kai.tspx")
}

func TestSpxOverload(t *testing.T) {
gopSpxTestEx(t, `
var (
Kai Kai
)
func onInit() {
Kai.onKey "hello", key => {
}
}
`, `
var (
a int
)
type Mesh struct {
}
func (p *Mesh) Name() string {
return "hello"
}
var (
m1 = &Mesh{}
m2 = &Mesh{}
)
onKey "hello", => {
}
onKey "hello", key => {
}
onKey ["1"], => {
}
onKey ["2"], key => {
}
onKey [m1, m2], => {
}
onKey [m1, m2], key => {
}
onKey ["a"], ["b"], key => {
}
onKey ["a"], [m1, m2], key => {
}
onKey ["a"], nil, key => {
}
onKey 100, 200
onKey2 "hello", key => {
}
`, `package main
import "github.com/goplus/gop/cl/internal/spx"
type Mesh struct {
}
type Kai struct {
spx.Sprite
*Game
a int
}
type Game struct {
*spx.MyGame
Kai Kai
}
func (this *Game) onInit() {
spx.Gopt_Sprite_OnKey__1(this.Kai, "hello", func(key string) {
})
}
func (p *Mesh) Name() string {
return "hello"
}
var m1 = &Mesh{}
var m2 = &Mesh{}
func (this *Kai) Main() {
spx.Gopt_Sprite_OnKey__0(this, "hello", func() {
})
spx.Gopt_Sprite_OnKey__1(this, "hello", func(key string) {
})
spx.Gopt_Sprite_OnKey__2(this, []string{"1"}, func() {
})
spx.Gopt_Sprite_OnKey__3(this, []string{"2"}, func(key string) {
})
spx.Gopt_Sprite_OnKey__4(this, []spx.Mesher{m1, m2}, func() {
})
spx.Gopt_Sprite_OnKey__5(this, []spx.Mesher{m1, m2}, func(key spx.Mesher) {
})
spx.Gopt_Sprite_OnKey__6(this, []string{"a"}, []string{"b"}, func(key string) {
})
spx.Gopt_Sprite_OnKey__7(this, []string{"a"}, []spx.Mesher{m1, m2}, func(key string) {
})
spx.Gopt_Sprite_OnKey__6(this, []string{"a"}, nil, func(key string) {
})
spx.Gopt_Sprite_OnKey__8(this, 100, 200)
spx.Gopt_Sprite_OnKey2(this, "hello", func(key string) {
})
}
`, "Game.tgmx", "Kai.tspx")
}
67 changes: 51 additions & 16 deletions cl/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4476,16 +4476,18 @@ foo.onKey ["1"], => {
}
foo.onKey ["2"], key => {
}
foo.onKey [m1,m2], => {
foo.onKey [m1, m2], => {
}
foo.onKey [m1,m2], key => {
foo.onKey [m1, m2], key => {
}
foo.onKey ["a"], ["b"], key => {
}
foo.onKey ["a"], [m1,m2], key => {
foo.onKey ["a"], [m1, m2], key => {
}
foo.onKey ["a"],nil,key => {
foo.onKey ["a"], nil, key => {
}
foo.onKey 100, 200
n := &foo.N{}
n.onKey "hello", => {
}
Expand All @@ -4495,16 +4497,17 @@ n.onKey ["1"], => {
}
n.onKey ["2"], key => {
}
n.onKey [m1,m2], => {
n.onKey [m1, m2], => {
}
n.onKey [m1,m2], key => {
n.onKey [m1, m2], key => {
}
n.onKey ["a"], ["b"], key => {
}
n.onKey ["a"], [m1,m2], key => {
n.onKey ["a"], [m1, m2], key => {
}
n.onKey ["a"],nil,key => {
n.onKey ["a"], nil, key => {
}
n.onKey 100, 200
`, `package main
import "github.com/goplus/gop/cl/internal/overload/foo"
Expand Down Expand Up @@ -4538,6 +4541,7 @@ func main() {
})
foo.OnKey__6([]string{"a"}, nil, func(key string) {
})
foo.OnKey__8(100, 200)
n := &foo.N{}
n.OnKey__0("hello", func() {
})
Expand All @@ -4557,6 +4561,7 @@ func main() {
})
n.OnKey__6([]string{"a"}, nil, func(key string) {
})
n.OnKey__8(100, 200)
}
`)
}
Expand Down Expand Up @@ -4750,6 +4755,10 @@ func (m *N) OnKey__6(a []string, b []string, fn func(key string)) {
func (m *N) OnKey__7(a []string, b []Mesher, fn func(key string)) {
}
func (m *N) OnKey__8(x int, y int) {
}
func OnKey__0(a string, fn func()) {
}
Expand All @@ -4773,6 +4782,15 @@ func OnKey__6(a []string, b []string, fn func(key string)) {
func OnKey__7(a []string, b []Mesher, fn func(key string)) {
}
func OnKey__8(x int, y int) {
}
func OnKey__9(a, b string, fn ...func(x int) int) {
}
func OnKey__a(a, b string, v ...int) {
}
`, `
type Mesh struct {
}
Expand All @@ -4794,16 +4812,23 @@ OnKey ["1"], => {
}
OnKey ["2"], key => {
}
OnKey [m1,m2], => {
OnKey [m1, m2], => {
}
OnKey [m1,m2], key => {
OnKey [m1, m2], key => {
}
OnKey ["a"], ["b"], key => {
}
OnKey ["a"], [m1,m2], key => {
OnKey ["a"], [m1, m2], key => {
}
OnKey ["a"], nil, key => {
}
OnKey ["a"],nil,key => {
OnKey 100, 200
OnKey "a", "b", x => x * x, x => {
return x * 2
}
OnKey "a", "b", 1, 2, 3
OnKey("a", "b", [1, 2, 3]...)
n := &N{}
n.onKey "hello", => {
}
Expand All @@ -4813,16 +4838,17 @@ n.onKey ["1"], => {
}
n.onKey ["2"], key => {
}
n.onKey [m1,m2], => {
n.onKey [m1, m2], => {
}
n.onKey [m1,m2], key => {
n.onKey [m1, m2], key => {
}
n.onKey ["a"], ["b"], key => {
}
n.onKey ["a"], [m1,m2], key => {
n.onKey ["a"], [m1, m2], key => {
}
n.onKey ["a"],nil,key => {
n.onKey ["a"], nil, key => {
}
n.onKey 100, 200
`, `package main
type Mesh struct {
Expand Down Expand Up @@ -4854,6 +4880,14 @@ func main() {
})
OnKey__6([]string{"a"}, nil, func(key string) {
})
OnKey__8(100, 200)
OnKey__9("a", "b", func(x int) int {
return x * x
}, func(x int) int {
return x * 2
})
OnKey__a("a", "b", 1, 2, 3)
OnKey__a("a", "b", []int{1, 2, 3}...)
n := &N{}
n.OnKey__0("hello", func() {
})
Expand All @@ -4873,6 +4907,7 @@ func main() {
})
n.OnKey__6([]string{"a"}, nil, func(key string) {
})
n.OnKey__8(100, 200)
}
`)
}
Expand Down
Loading

0 comments on commit d7480a4

Please sign in to comment.