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
79
|
dofile("util.lua")
ice_cream_scoops = {
"vanilla",
"chocolate";
sprinkles = true
}
greek_numbers = {
ena = "one",
dyo = "two",
tria = "three"
}
mt = {
__tostring = table_to_string
}
setmetatable(greek_numbers, mt)
Villain = {
health = 100,
new = function(self, name)
obj = {
name = name,
health = self.health
}
setmetatable(obj, self)
self.__index = self
return obj
end,
take_hit = function(self)
self.health = self.health - 10
end
}
dietrich = Villain:new("Dietrich")
SuperVillain = Villain:new()
function SuperVillain:take_hit()
self.health = self.health - 5
end
joker = SuperVillain:new("Joker")
function fibonacci()
local m = 1
local n = 1
while true do
coroutine.yield(m)
m, n = n, m+n
end
end
generator = coroutine.create(fibonacci)
-- Easy
function concatenate(a1, a2)
local new = {}
for i = 1, #a1 do
new[#new+1] = a1[i]
end
for i = 1, #a2 do
new[#new+1] = a2[i]
end
return new
end
l1 = {1,2,3}
l2 = {4,5,6,7,8}
-- Medium -- ????????????????????????????
-- function _G.__add(self, v)
-- return concatenate(self, v)
-- end
|