# lua

```[vagrant@localhost lua]\$ lua -v
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
[vagrant@localhost lua]\$ lua hello.lua
hello world
```

luaは多重代入も可能です。

```x, y = 10, 15
x, y = y, x
print(x)
print(y)
```

```s = "h'e'llo"
print(s)
```

```a = {23, 234, "hello"}
print(a[2])
print(#a)
```

```score = 75
if score > 60 and score < 80 then
print("ok")
else
print("ng!")
end
```

ループ

```i = 0
while i < 10 do
print(i)
i = i + 1
end
```

for文

```for i = 0, 9, 2 do
print(i)
end
```

```a = {12, 24, "hey"}
b = {name = "nari", score= 120}

for i, value in ipairs(a) do
print(i, value)
end
```

```function greet(name)
print("hello, I am "..name)
end

greet("clinton")
```

```function sum(...)
local a = {...}
local total = 0
for i = 1, #a do
total = total + a[i]
end
end
print(sum(2, 7, 23141, 131))
```

```math.max(2, 222, 14)
math.ceil(2.3)
math.floor(2.3)
math.random()
math.random(n) -- 1からnまでの整数値
```

```s = string.len("google")
```

テーブルの命令文

```a = {2, 25, 42, 1}
table.sort(a)

for i, v in inpairs(a) do
print(v)
end
```

```x = os.time()
x = os.date()
print(x)
```