lspace.lua
· 1.5 KiB · Lua
Bruto
Playground
local Space = require("lspace")
local enemies = {}
local r, f, l, box, tuples, rules = Space()
local function p(...)
local args = {...}
return function() print(table.unpack(args)) end
end
function espawn(vars)
print("Spawning "..vars.enemy.." at "..vars.x..", "..vars.y)
table.insert(enemies, {t=vars.enemy, x=vars.x,y=vars.y})
end
f('play level 1')
r('play level 1').so(
p"Started Level 1!",
'spawn a flyer at 60 10',
'spawn a flyer at 60 20',
'spawn a flyer at 60 30',
'playing level 1'
)
r('spawn a $enemy at $x $y').so(espawn)
r('spawn an $enemy at $x $y').so(espawn)
r('playing level 1', 'all enemies are dead').so(p'LEVEL 2', 'play level 2')
r('there are $some enemies').so(
function(v)
-- print("some", v.some, type(v.some))
if v.some == "0" then f('all enemies are dead') end
end
)
r('an enemy died').so(
function(_) print('ded') f('there are '.. #enemies..' enemies') end
)
r('a','b','c').so(p'a,b&c')
f('a')
f('b')
f('letters '..l('a', 'b', 'c'))
f('c')
r('a', 'b').so(p'a&b',"a and b")
r('MYVARR $vals').so(function(vars) print(table.unpack(vars.vals)) end)
box('MYVARR', {1,2,3,4})
print("***************************")
for _, t in ipairs(tuples) do
print(t, table.unpack(t))
end
print("***************************")
function kill()
table.remove(enemies, 1)
f('an enemy died')
end
kill()
kill()
kill()
print("***************************")
for _, t in ipairs(tuples) do
print(table.unpack(t))
end
1 | local Space = require("lspace") |
2 | local enemies = {} |
3 | local r, f, l, box, tuples, rules = Space() |
4 | |
5 | local function p(...) |
6 | local args = {...} |
7 | return function() print(table.unpack(args)) end |
8 | end |
9 | |
10 | function espawn(vars) |
11 | print("Spawning "..vars.enemy.." at "..vars.x..", "..vars.y) |
12 | table.insert(enemies, {t=vars.enemy, x=vars.x,y=vars.y}) |
13 | end |
14 | |
15 | f('play level 1') |
16 | r('play level 1').so( |
17 | p"Started Level 1!", |
18 | 'spawn a flyer at 60 10', |
19 | 'spawn a flyer at 60 20', |
20 | 'spawn a flyer at 60 30', |
21 | 'playing level 1' |
22 | ) |
23 | r('spawn a $enemy at $x $y').so(espawn) |
24 | r('spawn an $enemy at $x $y').so(espawn) |
25 | r('playing level 1', 'all enemies are dead').so(p'LEVEL 2', 'play level 2') |
26 | r('there are $some enemies').so( |
27 | function(v) |
28 | -- print("some", v.some, type(v.some)) |
29 | if v.some == "0" then f('all enemies are dead') end |
30 | end |
31 | ) |
32 | r('an enemy died').so( |
33 | function(_) print('ded') f('there are '.. #enemies..' enemies') end |
34 | ) |
35 | |
36 | r('a','b','c').so(p'a,b&c') |
37 | f('a') |
38 | f('b') |
39 | f('letters '..l('a', 'b', 'c')) |
40 | f('c') |
41 | r('a', 'b').so(p'a&b',"a and b") |
42 | r('MYVARR $vals').so(function(vars) print(table.unpack(vars.vals)) end) |
43 | box('MYVARR', {1,2,3,4}) |
44 | |
45 | print("***************************") |
46 | for _, t in ipairs(tuples) do |
47 | print(t, table.unpack(t)) |
48 | end |
49 | |
50 | print("***************************") |
51 | function kill() |
52 | table.remove(enemies, 1) |
53 | f('an enemy died') |
54 | end |
55 | |
56 | kill() |
57 | kill() |
58 | kill() |
59 | |
60 | print("***************************") |
61 | |
62 | for _, t in ipairs(tuples) do |
63 | print(table.unpack(t)) |
64 | end |
65 |