-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.lua
116 lines (84 loc) · 2.05 KB
/
test.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
a = _VERSION
print(a)
print( select( '#', 1, 2, 3,4 , 5) )
print( select( 2, 1, 2, 3, 4, 5) )
print( select( -2, 1,2, 3, 4, 5 ) )
print( select( 10, 1,2, 3, 4, 5) )
print( string.byte(a, 1, 5) )
print( string.rep( a, 3, "::" ) )
lowered = string.lower(a)
uppered = string.upper(lowered)
print( lowered )
print( uppered )
print(math.pi)
print( math.abs( -math.pi ) )
print( math.abs( "3.5" ) )
print( math.abs( "-13.2" ) )
math.randomseed( )
print( math.random(10) )
print( math.random() )
print( math.random( 5, 10 ) )
print( math.deg(math.atan( 1 )) )
print( math.modf( 3.14 ) )
print( math.modf( 5 ) )
a = { 1, 2, 3, 4, 5, 6 }
print( a )
print( a[1], a[2], a[3] )
print( #a )
print( table.concat( a, ", ", 3, 5 ) )
table.insert( a, 3, 100 )
print( table.concat( a, ", ", 1, 7 ) )
a = table.pack( 'a', 'b', 'c', 'd', 'e' )
print( table.concat(a, ", ") )
a[10] = "ten"
print( table.unpack( a, 7, 9 ) )
print( "removed: "..tostring(table.remove( a )) )
print( table.unpack( a ) )
print( "removed: "..tostring(table.remove( a, 2 )) )
print( table.unpack( a ) )
a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
b = { 'a', 'b', 'c' }
table.move( a, 5, 9, 3, b )
print( table.unpack( a ) )
print( table.unpack( b ) )
print( 'generic-for loop with pairs' )
for k, v in pairs(a) do
print( k, v )
end
print( 'generic-for loop with ipairs' )
for k, v in ipairs(a) do
print( k, v )
end
print( 'sorting' )
a = { 3, 5, 1, 4, 2 }
table.sort( a )
print( table.unpack( a ) )
print( 'coroutine.running()' )
print( coroutine.running() )
print( 'coroutine.status()' )
print( coroutine.status( coroutine.running() ) )
print( 'pcall success' )
print( pcall( math.sqrt, 3.0 ) )
print( 'pcall failure' )
print( pcall( rawget, nil, 2 ) )
function func()
return 1, 2
end
local a, b, c, d = 4,5, 6, 7
print( a, b, c, d )
a, b, c, d = func()
print( a, b, c, d )
function factorial( n )
if n == 0 then
return 1;
else
return n * factorial(n - 1);
end
end
for i = 1, 10, 2 do
print( "Factorial of "..i.." is: ".. factorial(i) );
end
do
return 0;
end
print(10);