love.wul
· 1.1 KiB · Text
原始文件
Playground
@love event $name { }
@love event $name $a { }
@love event $name $a $b { }
@love event $name $a $b $c { }
@love event $name $a $b $c $d { }
@love event $name $a $b $c $d $e { }
@love event $name $a $b $c $d $e $f { }
@ initialize LOVE event handlers {
@code [
function love.run()
-- if love.load then love.load(love.arg.parseGameArguments(arg), arg) end
if love.timer then love.timer.step() end
local dt = 0
return function()
if love.event then
love.event.pump()
for name, a,b,c,d,e,f in love.event.poll() do
self:fact("@love", "event", name, a, b, c, d, e, f)
self:run()
if name == "quit" and not self:take("@keep running") then
return a or 0
end
end
end
if love.timer then dt = love.timer.step() end
self:fact("@love", "event", "update", dt) self:run()
if love.graphics and love.graphics.isActive() then
love.graphics.origin()
love.graphics.clear(love.graphics.getBackgroundColor())
self:fact("@love", "event", "draw")
self:run()
love.graphics.present()
end
if love.timer then love.timer.sleep(0.001) end
end
end
]
}
| 1 | @love event $name { } |
| 2 | @love event $name $a { } |
| 3 | @love event $name $a $b { } |
| 4 | @love event $name $a $b $c { } |
| 5 | @love event $name $a $b $c $d { } |
| 6 | @love event $name $a $b $c $d $e { } |
| 7 | @love event $name $a $b $c $d $e $f { } |
| 8 | |
| 9 | @ initialize LOVE event handlers { |
| 10 | @code [ |
| 11 | function love.run() |
| 12 | -- if love.load then love.load(love.arg.parseGameArguments(arg), arg) end |
| 13 | if love.timer then love.timer.step() end |
| 14 | local dt = 0 |
| 15 | return function() |
| 16 | if love.event then |
| 17 | love.event.pump() |
| 18 | for name, a,b,c,d,e,f in love.event.poll() do |
| 19 | self:fact("@love", "event", name, a, b, c, d, e, f) |
| 20 | self:run() |
| 21 | if name == "quit" and not self:take("@keep running") then |
| 22 | return a or 0 |
| 23 | end |
| 24 | end |
| 25 | end |
| 26 | if love.timer then dt = love.timer.step() end |
| 27 | self:fact("@love", "event", "update", dt) self:run() |
| 28 | if love.graphics and love.graphics.isActive() then |
| 29 | love.graphics.origin() |
| 30 | love.graphics.clear(love.graphics.getBackgroundColor()) |
| 31 | self:fact("@love", "event", "draw") |
| 32 | self:run() |
| 33 | love.graphics.present() |
| 34 | end |
| 35 | if love.timer then love.timer.sleep(0.001) end |
| 36 | end |
| 37 | end |
| 38 | ] |
| 39 | } |
main.wul
· 3.1 KiB · Text
原始文件
Playground
{ @code [
local objects = {}
local id = 0
] }
{ @ initialize LOVE event handlers
, spawn 1000 circles
}
@love event draw {
@ ( draw circles . ) , draw fps
}
@love event update $dt {
dt $dt ; @ ( update circles . )
}
@ ( draw circles . ) ; circles $id {
circles.stash $id ;
@ (
$id draw circle with radius 10 .
draw circles .
)
}
@ ( draw circles . ) {
@ ( circles.stash move to circles . )
}
@ ( update circles . ) ; circles $id ; dt $dt {
circles.stash $id ; dt $dt ; @ (
self := $id .
self t := self t + $dt .
self x := self t cos * self speed + self cx .
self y := self t sin * self speed + self cy .
self drop .
update circles .
)
}
@ ( update circles . ) ; dt $dt {
@ ( circles.stash move to circles . )
}
@ spawn n circles ; n := $n {
@ spawn $n circles
}
@ spawn 0 circles { }
@ spawn $n circles {
@ ( n := $n - 1 . )
, spawn a circle
, spawn n circles
}
@ spawn a circle {
@ (
self := object new .
self x := 100 random upto 500 .
self y := 100 random upto 500 .
self speed := 1 random upto 100 .
self cx := self x .
self cy := self y .
self t := 1 random upto 360 .
circles <- self .
)
}
@ ( $name := ) {
slot $name
}
@ ( $name $field := ) {
slot $name $field
}
@ ( self drop . ) ; self := $id { }
@ ( self $field ) ; self := $id {
self := $id ;
@ $value ;
@code [$value = objects[$id][$field]]
}
@ ( $number cos ) {
@ $cos ; @code [$cos = math.cos(tonumber($number))]
}
@ ( $number sin ) {
@ $sin ; @code [$sin = math.sin(tonumber($number))]
}
@ ( $x + self $field ) ; self := $self {
self := $self ;
@ $z ; @code [$z = tostring($x + objects[$self][$field])]
}
@ ( $x * self $field ) ; self := $self {
self := $self ;
@ $z ; @code [$z = tostring($x * objects[$self][$field])]
}
@ ( $x + $y ) {
@ $z ; @code [$z = tostring($x + $y)]
}
@ ( $x * $y ) {
@ $z ; @code [$z = tostring($x * $y)]
}
@ ( $x - $y ) {
@ $z ; @code [$z = tostring($x - $y)]
}
@ ( object new ) {
@ $id ;
@code [
id = id + 1
local object = { id = id }
objects[object.id] = object
$id = id
]
}
@ ( $lower random upto $upper ) {
@ $n ; @code [$n = tostring(love.math.random(tonumber($lower), tonumber($upper)))]
}
@ ( $value . ) ; slot self {
self := $value
}
@ ( $value . ) ; slot n {
n := $value
}
@ ( $value . ) ; slot self $field ; self := $id {
self := $id ;
@code [objects[$id][$field] = $value]
}
@ ( self <- $value . ) {
self := $value
}
@ ( circles <- self . ) ; self := $id {
circles $id
}
@ ( circles.stash move to circles . ) ; circles.stash $id {
circles $id ; @ ( circles.stash move to circles . )
}
@ ( circles.stash move to circles . ) { }
@ ( $id draw circle with radius $r . ) {
@code [love.graphics.circle("fill", objects[$id].x, objects[$id].y, $r)]
}
@ draw fps {
@code [love.graphics.print(tostring(love.timer.getFPS( )) .. " - circles: " .. tostring(#objects), 0, 0)]
}
| 1 | { @code [ |
| 2 | local objects = {} |
| 3 | local id = 0 |
| 4 | ] } |
| 5 | |
| 6 | { @ initialize LOVE event handlers |
| 7 | , spawn 1000 circles |
| 8 | } |
| 9 | |
| 10 | |
| 11 | @love event draw { |
| 12 | @ ( draw circles . ) , draw fps |
| 13 | } |
| 14 | |
| 15 | @love event update $dt { |
| 16 | dt $dt ; @ ( update circles . ) |
| 17 | } |
| 18 | |
| 19 | |
| 20 | @ ( draw circles . ) ; circles $id { |
| 21 | circles.stash $id ; |
| 22 | @ ( |
| 23 | $id draw circle with radius 10 . |
| 24 | draw circles . |
| 25 | ) |
| 26 | } |
| 27 | |
| 28 | @ ( draw circles . ) { |
| 29 | @ ( circles.stash move to circles . ) |
| 30 | } |
| 31 | |
| 32 | @ ( update circles . ) ; circles $id ; dt $dt { |
| 33 | circles.stash $id ; dt $dt ; @ ( |
| 34 | self := $id . |
| 35 | self t := self t + $dt . |
| 36 | self x := self t cos * self speed + self cx . |
| 37 | self y := self t sin * self speed + self cy . |
| 38 | self drop . |
| 39 | update circles . |
| 40 | ) |
| 41 | } |
| 42 | |
| 43 | @ ( update circles . ) ; dt $dt { |
| 44 | @ ( circles.stash move to circles . ) |
| 45 | } |
| 46 | |
| 47 | @ spawn n circles ; n := $n { |
| 48 | @ spawn $n circles |
| 49 | } |
| 50 | |
| 51 | @ spawn 0 circles { } |
| 52 | |
| 53 | @ spawn $n circles { |
| 54 | @ ( n := $n - 1 . ) |
| 55 | , spawn a circle |
| 56 | , spawn n circles |
| 57 | } |
| 58 | |
| 59 | @ spawn a circle { |
| 60 | @ ( |
| 61 | self := object new . |
| 62 | self x := 100 random upto 500 . |
| 63 | self y := 100 random upto 500 . |
| 64 | self speed := 1 random upto 100 . |
| 65 | self cx := self x . |
| 66 | self cy := self y . |
| 67 | self t := 1 random upto 360 . |
| 68 | circles <- self . |
| 69 | ) |
| 70 | } |
| 71 | |
| 72 | @ ( $name := ) { |
| 73 | slot $name |
| 74 | } |
| 75 | |
| 76 | @ ( $name $field := ) { |
| 77 | slot $name $field |
| 78 | } |
| 79 | |
| 80 | @ ( self drop . ) ; self := $id { } |
| 81 | |
| 82 | @ ( self $field ) ; self := $id { |
| 83 | self := $id ; |
| 84 | @ $value ; |
| 85 | @code [$value = objects[$id][$field]] |
| 86 | } |
| 87 | |
| 88 | @ ( $number cos ) { |
| 89 | @ $cos ; @code [$cos = math.cos(tonumber($number))] |
| 90 | } |
| 91 | |
| 92 | @ ( $number sin ) { |
| 93 | @ $sin ; @code [$sin = math.sin(tonumber($number))] |
| 94 | } |
| 95 | |
| 96 | @ ( $x + self $field ) ; self := $self { |
| 97 | self := $self ; |
| 98 | @ $z ; @code [$z = tostring($x + objects[$self][$field])] |
| 99 | } |
| 100 | |
| 101 | @ ( $x * self $field ) ; self := $self { |
| 102 | self := $self ; |
| 103 | @ $z ; @code [$z = tostring($x * objects[$self][$field])] |
| 104 | } |
| 105 | |
| 106 | @ ( $x + $y ) { |
| 107 | @ $z ; @code [$z = tostring($x + $y)] |
| 108 | } |
| 109 | |
| 110 | @ ( $x * $y ) { |
| 111 | @ $z ; @code [$z = tostring($x * $y)] |
| 112 | } |
| 113 | |
| 114 | @ ( $x - $y ) { |
| 115 | @ $z ; @code [$z = tostring($x - $y)] |
| 116 | } |
| 117 | |
| 118 | @ ( object new ) { |
| 119 | @ $id ; |
| 120 | @code [ |
| 121 | id = id + 1 |
| 122 | local object = { id = id } |
| 123 | objects[object.id] = object |
| 124 | $id = id |
| 125 | ] |
| 126 | } |
| 127 | |
| 128 | @ ( $lower random upto $upper ) { |
| 129 | @ $n ; @code [$n = tostring(love.math.random(tonumber($lower), tonumber($upper)))] |
| 130 | } |
| 131 | |
| 132 | @ ( $value . ) ; slot self { |
| 133 | self := $value |
| 134 | } |
| 135 | |
| 136 | @ ( $value . ) ; slot n { |
| 137 | n := $value |
| 138 | } |
| 139 | |
| 140 | @ ( $value . ) ; slot self $field ; self := $id { |
| 141 | self := $id ; |
| 142 | @code [objects[$id][$field] = $value] |
| 143 | } |
| 144 | |
| 145 | @ ( self <- $value . ) { |
| 146 | self := $value |
| 147 | } |
| 148 | |
| 149 | @ ( circles <- self . ) ; self := $id { |
| 150 | circles $id |
| 151 | } |
| 152 | |
| 153 | @ ( circles.stash move to circles . ) ; circles.stash $id { |
| 154 | circles $id ; @ ( circles.stash move to circles . ) |
| 155 | } |
| 156 | |
| 157 | @ ( circles.stash move to circles . ) { } |
| 158 | |
| 159 | @ ( $id draw circle with radius $r . ) { |
| 160 | @code [love.graphics.circle("fill", objects[$id].x, objects[$id].y, $r)] |
| 161 | } |
| 162 | |
| 163 | @ draw fps { |
| 164 | @code [love.graphics.print(tostring(love.timer.getFPS( )) .. " - circles: " .. tostring(#objects), 0, 0)] |
| 165 | } |