-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/dev/jae/boundmethodrealm' into d…
…ev/moul/grc20reg
- Loading branch information
Showing
5 changed files
with
106 additions
and
3 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
examples/gno.land/p/demo/tests/p_crossrealm/p_crossrealm.gno
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package p_crossrealm | ||
|
||
type Stringer interface { | ||
String() string | ||
} | ||
|
||
type Container struct { | ||
A int | ||
B Stringer | ||
} | ||
|
||
func (c *Container) Touch() *Container { | ||
c.A += 1 | ||
return c | ||
} | ||
|
||
func (c *Container) Print() { | ||
println("A:", c.A) | ||
if c.B == nil { | ||
println("B: undefined") | ||
} else { | ||
println("B:", c.B.String()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package crossrealm | ||
|
||
import ( | ||
"gno.land/p/demo/tests/p_crossrealm" | ||
"gno.land/p/demo/ufmt" | ||
) | ||
|
||
type LocalStruct struct { | ||
A int | ||
} | ||
|
||
func (ls *LocalStruct) String() string { | ||
return ufmt.Sprintf("LocalStruct{%d}", ls.A) | ||
} | ||
|
||
// local is saved locally in this realm | ||
var local *LocalStruct | ||
|
||
func init() { | ||
local = &LocalStruct{A: 123} | ||
} | ||
|
||
// Make1 returns a local object wrapped by a p struct | ||
func Make1() *p_crossrealm.Container { | ||
return &p_crossrealm.Container{ | ||
A: 1, | ||
B: local, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// PKGPATH: gno.land/r/crossrealm_test | ||
package crossrealm_test | ||
|
||
import ( | ||
crossrealm "gno.land/r/demo/tests/crossrealm" | ||
) | ||
|
||
func main() { | ||
// even though we are running within a realm, | ||
// we aren't storing the result of crossrealm.Make1(), | ||
// so this should print fine. | ||
crossrealm.Make1().Touch().Print() | ||
} | ||
|
||
// Output: | ||
// A: 2 | ||
// B: LocalStruct{123} |