-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlearn.lua
More file actions
45 lines (33 loc) · 861 Bytes
/
Copy pathlearn.lua
File metadata and controls
45 lines (33 loc) · 861 Bytes
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
-- commenting in lua is done with --
--[[
multi line comments is done in Lua with
]]
print("Hello " .. "World") -- .. is the concatenation operator
local name ="Hi" -- setting a variable
print(name)
function helloname(name) -- creating a function
print("Hello " .. name) -- concatenation operator
end
helloname("neji")
-- assigning a function to a variable
myname = function(name)
print(name)
end
myname("neji")
myname("Jin")
function average(...)
result = 0
local arg = {...}
for i,v in ipairs(arg) do
result = result + v
end
return result/#arg -- # is the length operator
end
print("The average is",average(10,5))
function numbers(...) -- function with varibale argument
local arg = {...}
for i,v in ipairs(arg) do -- ipairs is an iterator
print(i,v)
end
end
numbers(10,5,3,2,1)