Rename the language from Dino to Rex
Files use .rex, the command is rex, and the crate, runtime prefixes, docs, editor files and examples all use the new name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2f44f09b6a
commit
7cf9727bcd
94 files changed
+858
-858
No files matched your search
@@ -0,0 +1,69 @@
|
||||
struct Texture {
|
||||
name: string
|
||||
uses: int
|
||||
|
||||
func touch() { uses += 1 }
|
||||
}
|
||||
|
||||
struct Sprite {
|
||||
tex: shared Texture
|
||||
x: int
|
||||
}
|
||||
|
||||
struct Window {
|
||||
title: string
|
||||
buttons: []shared Button
|
||||
|
||||
func add(b: shared Button) { buttons.push(b) }
|
||||
}
|
||||
|
||||
struct Button {
|
||||
label: string
|
||||
window: weak Window?
|
||||
clicks: int
|
||||
|
||||
func click() {
|
||||
clicks += 1
|
||||
if window != nil {
|
||||
print(label, "clicked in", window.title)
|
||||
} else {
|
||||
print(label, "clicked, window is gone")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func use_texture(t: shared Texture) {
|
||||
t.touch()
|
||||
}
|
||||
|
||||
func main() {
|
||||
// several owners of one value: a change through one is seen by all
|
||||
var tex = shared Texture{"grass", 0}
|
||||
var a = Sprite{tex, 1}
|
||||
var b = Sprite{tex, 2}
|
||||
a.tex.touch()
|
||||
b.tex.touch()
|
||||
use_texture(tex)
|
||||
print(tex.name, tex.uses, a.tex.uses, b.tex.uses)
|
||||
print(a)
|
||||
|
||||
// a window and its buttons point at each other: the button's side is weak
|
||||
var win = shared Window{"Main", []}
|
||||
var ok = shared Button{"OK", weak win, 0}
|
||||
win.add(ok)
|
||||
ok.click()
|
||||
win.buttons[0].click()
|
||||
print(ok.clicks)
|
||||
|
||||
var cancel = shared Button{label: "Cancel"}
|
||||
print(cancel.window == nil)
|
||||
cancel.window = weak win
|
||||
print(cancel.window == nil)
|
||||
cancel.click()
|
||||
|
||||
// once the window is gone, the weak pointers know
|
||||
var saved = ok
|
||||
win = shared Window{"Other", []}
|
||||
saved.click()
|
||||
cancel.click()
|
||||
}
|
||||
Reference in new issue
Block a user