Repository: goplus/gop
Pull request #1462 (2023-10-09 13:38:16)

update github.com/goplus/gox for TestSpxClone


Patch:
diff --git a/cl/internal/spx/sprite.go b/cl/internal/spx/sprite.go
index bcd4c2cd..9bbd27fd 100644
--- a/cl/internal/spx/sprite.go
+++ b/cl/internal/spx/sprite.go
@@ -19,12 +19,14 @@ package spx
 type Sprite struct {
 }
 
-func (p *Sprite) Clone(data ...interface{}) *Sprite {
-	panic("todo")
-}
-
 func (p *Sprite) SetCostume(costume interface{}) {
 }
 
 func (p *Sprite) Say(msg string, secs ...float64) {
 }
+
+func Gopt_Sprite_Clone__0(sprite interface{}) {
+}
+
+func Gopt_Sprite_Clone__1(sprite interface{}, data interface{}) {
+}
diff --git a/go.mod b/go.mod
index d6fb4be4..353e1b3f 100644
--- a/go.mod
+++ b/go.mod
@@ -5,7 +5,7 @@ go 1.17
 require (
 	github.com/fsnotify/fsnotify v1.6.0
 	github.com/goplus/c2go v0.7.16
-	github.com/goplus/gox v1.12.2-0.20231007151349-6d42b99b0eed
+	github.com/goplus/gox v1.12.2-0.20231009123136-d678b292c455
 	github.com/goplus/mod v0.11.6
 	github.com/qiniu/x v1.13.1-0.20231008134417-ad2120b8fcd4
 	golang.org/x/tools v0.14.0
diff --git a/go.sum b/go.sum
index b7de14af..f3ed1c4a 100644
--- a/go.sum
+++ b/go.sum
@@ -7,8 +7,8 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
 github.com/goplus/c2go v0.7.16 h1:B9jRNNytoq7yDBQOZSm2qENQhRQMfNhgOea5XHWNUnI=
 github.com/goplus/c2go v0.7.16/go.mod h1:XODEFX2PeEEJXNLLdykWeZgMSaKJ51fVm+C9IM3FxNQ=
 github.com/goplus/gox v1.12.1/go.mod h1:wymoQJ7ydd42cTlaXb4wNbvn4LlKjR+j8PZehI7v1zQ=
-github.com/goplus/gox v1.12.2-0.20231007151349-6d42b99b0eed h1:BtqCB9Rpv1ak8qCwQKFv/ajO+Hyk3LsJvR7WRotGYCw=
-github.com/goplus/gox v1.12.2-0.20231007151349-6d42b99b0eed/go.mod h1:ferIrvJSoXae8gABk5Z4olEzfAxZpUy4hD91Vm5E/qs=
+github.com/goplus/gox v1.12.2-0.20231009123136-d678b292c455 h1:Nt1pEEPeCWdWHHufOXPx8U1OEh+c3uFEzD8dE8fzRko=
+github.com/goplus/gox v1.12.2-0.20231009123136-d678b292c455/go.mod h1:ferIrvJSoXae8gABk5Z4olEzfAxZpUy4hD91Vm5E/qs=
 github.com/goplus/mod v0.11.5/go.mod h1:NDC5E+XOT8vcJCMjqKhLDJHTHX7lyVN4Vbfi2U7dBhs=
 github.com/goplus/mod v0.11.6 h1:3H8ddFtdxIbSuBrmYmIZJxgGu4YjyvuFYNTbit+J0Xg=
 github.com/goplus/mod v0.11.6/go.mod h1:gExaEMWgU6pgmJ2Dd6jhDxhw8YGd9AOjCcnsRB3KG5w=


Test patch:
diff --git a/cl/compile_spx_test.go b/cl/compile_spx_test.go
index e0722723..0451c301 100644
--- a/cl/compile_spx_test.go
+++ b/cl/compile_spx_test.go
@@ -313,7 +313,7 @@ type Kai struct {
 }
 
 func (this *Game) onInit() {
-	this.Kai.Clone()
+	spx.Gopt_Sprite_Clone__0(this.Kai)
 	this.Broadcast__0("msg1")
 }
 func (this *Kai) onInit() {
@@ -590,3 +590,67 @@ func (this *Kai) onMsg(msg string) {
 }
 `, "Game.tgmx.gox", "Kai.tspx.gox")
 }
+
+func TestSpxClone(t *testing.T) {
+	gopSpxTestEx(t, `
+var (
+	Kai Kai
+)
+
+func onInit() {
+	Kai.clone()
+	broadcast("msg1")
+}
+`, `
+var (
+	a int
+)
+
+type info struct {
+	x int
+	y int
+}
+
+func onInit() {
+	a = 1
+	clone
+	clone info{1,2}
+	clone &info{1,2}
+}
+
+func onCloned() {
+	say("Hi")
+}
+`, `package main
+
+import spx "github.com/goplus/gop/cl/internal/spx"
+
+type info struct {
+	x int
+	y int
+}
+type Game struct {
+	*spx.MyGame
+	Kai Kai
+}
+type Kai struct {
+	spx.Sprite
+	*Game
+	a int
+}
+
+func (this *Game) onInit() {
+	spx.Gopt_Sprite_Clone__0(this.Kai)
+	this.Broadcast__0("msg1")
+}
+func (this *Kai) onInit() {
+	this.a = 1
+	spx.Gopt_Sprite_Clone__0(this)
+	spx.Gopt_Sprite_Clone__1(this, info{1, 2})
+	spx.Gopt_Sprite_Clone__1(this, &info{1, 2})
+}
+func (this *Kai) onCloned() {
+	this.Say("Hi")
+}
+`, "Game.tgmx", "Kai.tspx")
+}
diff --git a/cl/outline/cl/compile_spx_test.go b/cl/outline/cl/compile_spx_test.go
index cb7925f4..e730234f 100644
--- a/cl/outline/cl/compile_spx_test.go
+++ b/cl/outline/cl/compile_spx_test.go
@@ -313,7 +313,7 @@ type Kai struct {
 }
 
 func (this *Game) onInit() {
-	this.Kai.Clone()
+	spx.Gopt_Sprite_Clone__0(this.Kai)
 	this.Broadcast__0("msg1")
 }
 func (this *Kai) onInit() {
@@ -586,3 +586,67 @@ func (this *Kai) onMsg(msg string) {
 }
 `, "Game.tgmx.gox", "Kai.tspx.gox")
 }
+
+func TestSpxClone(t *testing.T) {
+	gopSpxTestEx(t, `
+var (
+	Kai Kai
+)
+
+func onInit() {
+	Kai.clone()
+	broadcast("msg1")
+}
+`, `
+var (
+	a int
+)
+
+type info struct {
+	x int
+	y int
+}
+
+func onInit() {
+	a = 1
+	clone
+	clone info{1,2}
+	clone &info{1,2}
+}
+
+func onCloned() {
+	say("Hi")
+}
+`, `package main
+
+import spx "github.com/goplus/gop/cl/internal/spx"
+
+type Game struct {
+	*spx.MyGame
+	Kai Kai
+}
+type Kai struct {
+	spx.Sprite
+	*Game
+	a int
+}
+type info struct {
+	x int
+	y int
+}
+
+func (this *Game) onInit() {
+	spx.Gopt_Sprite_Clone__0(this.Kai)
+	this.Broadcast__0("msg1")
+}
+func (this *Kai) onInit() {
+	this.a = 1
+	spx.Gopt_Sprite_Clone__0(this)
+	spx.Gopt_Sprite_Clone__1(this, info{1, 2})
+	spx.Gopt_Sprite_Clone__1(this, &info{1, 2})
+}
+func (this *Kai) onCloned() {
+	this.Say("Hi")
+}
+`, "Game.tgmx", "Kai.tspx")
+}