forked from cloudflare/loom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.lua
78 lines (68 loc) · 1.1 KB
/
sample.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
local Sm = {}
function Sm.lulu()
for i = 1, 1000 do
for j = 1, 1000 do
end
end
end
function Sm.motivating_example_1()
local x, z = 0, nil
for i=1,100 do
local t = {i}
if i == 90 then
z = t
end
x = x + t[1]
end
print(x, z[1])
end
function Sm.motivating_example_2()
local x, z = 0, nil
for i=1,100 do
if i == 90 then
local t = {i}
z = t
end
x = x + i
end
print(x, z[1])
end
function Sm.resinking()
local z = nil
for i=1,200 do
local t = {i}
if i > 100 then
if i == 190 then z = t end
end
end
print(z[1])
end
function Sm.pointadds()
local point
point = {
new = function(self, x, y)
return setmetatable({x=x, y=y}, self)
end,
__add = function(a, b)
return point:new(a.x + b.x, a.y + b.y)
end,
}
point.__index = point
local a, b = point:new(1.5, 2.5), point:new(3.25, 4.75)
for i=1,100000000 do
a = (a + b) + b
end
print(a.x, a.y)
end
function Sm.tdup(x)
return { foo=1, bar=2, 1,2,x,4 }
end
function Sm.miltdup(x)
for i=1,1000 do Sm.tdup(i) end
end
function Sm.call_some()
print ("one")
Sm.motivating_example_1()
print ("end")
end
return Sm