-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlua-tricks.html
197 lines (190 loc) · 5.57 KB
/
lua-tricks.html
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title> tricks - quick Lua cheat sheet </title>
<script src="jquery.js"></script>
<script src="jquery-cookie.js"></script>
<script src="jquery-tablesorter.js"></script>
<script src="strftime.js"></script>
<script src="mustache.js"></script>
<script src="config.js"></script>
<script src="main.js"></script>
<link rel="stylesheet" type="text/css" href="templates/reset.css" />
<link rel="stylesheet" type="text/css" href="templates/hack.css" />
<link rel="stylesheet" type="text/css" id="lights_css" />
<script>
var DOCNAME = 'lua-tricks'
var PROJECT = ''
//set the lights before rendering starts
set_lights()
</script>
</head>
<body>
<header>
<div class="container">
<div class="btn-container btn-lights-container">
<a href="#" class="btn btn-lights" id="lights">lights</a>
</div>
<div class="btn-container btn-home-container">
<a href="/" class="btn btn-home">luapower</a>
</div>
<table id="header_table">
<tr>
<td style="vertical-align: middle;" width="100%">
<h1> tricks </h1>
<h2> quick Lua cheat sheet </h2>
</td>
<td style="vertical-align: middle;" align="right" style="height: 150px">
</td>
</tr>
</table>
</div>
</header>
<div class="bg-container">
<div class="bg-center-container">
<div class="bg bg-lua-tricks" style="background-image: url('bg/lua-tricks.png');"></div>
</div>
</div>
<div class="under-header">
<div class="container">
<div id="toc_container" class="toc_container doc"></div>
<button id=tab1_button class="tab_button hidden">Documentation</button>
<button id=tab2_button class="tab_button hidden">Package Info</button>
<div id="tabs_cointainer">
<div id="tab1_container">
<section class="doc">
<span id="module_info"></span>
<blockquote>
<p>Or, unreadable code that you should really turn into helper functions whenever you can.</p>
</blockquote>
<table>
<tbody>
<tr class="odd">
<td align="left"><strong>logic</strong></td>
<td align="left"></td>
</tr>
<tr class="even">
<td align="left"><code>not a == not b</code></td>
<td align="left">both or none</td>
</tr>
<tr class="odd">
<td align="left"><strong>numbers</strong></td>
<td align="left"></td>
</tr>
<tr class="even">
<td align="left">math.min(math.max(x, min), max)</td>
<td align="left">clamp x (upper limit takes precedence)</td>
</tr>
<tr class="odd">
<td align="left"><code>x ~= x</code></td>
<td align="left">number is NaN</td>
</tr>
<tr class="even">
<td align="left"><code>1/0</code></td>
<td align="left">inf</td>
</tr>
<tr class="odd">
<td align="left"><code>-1/0</code></td>
<td align="left">-inf</td>
</tr>
<tr class="even">
<td align="left"><code>math.huge == math.huge-1</code></td>
<td align="left">check if inf is available without dividing by zero</td>
</tr>
<tr class="odd">
<td align="left"><code>x % 1</code></td>
<td align="left">fractional part (always positive)</td>
</tr>
<tr class="even">
<td align="left"><code>x % 1 == 0</code></td>
<td align="left">number is integer; <code>math.floor(x) == x</code></td>
</tr>
<tr class="odd">
<td align="left"><code>x - x % 1</code></td>
<td align="left">integer part; but better use <code>math.floor(x)</code></td>
</tr>
<tr class="even">
<td align="left"><code>x - x % 0.01</code></td>
<td align="left">x floored to two decimal digits</td>
</tr>
<tr class="odd">
<td align="left"><code>x - x % n</code></td>
<td align="left">closest to <code>x</code> smaller than <code>x</code> multiple of <code>n</code></td>
</tr>
<tr class="even">
<td align="left"><code>math.modf(x)</code></td>
<td align="left">integer part and fractional part</td>
</tr>
<tr class="odd">
<td align="left"><code>math.floor(x+.5)</code></td>
<td align="left">round</td>
</tr>
<tr class="even">
<td align="left"><code>(x >= 0 and 1 or -1)</code></td>
<td align="left">sign</td>
</tr>
<tr class="odd">
<td align="left"><code>y0 + (x-x0) * ((y1-y0) / (x1 - x0))</code></td>
<td align="left">linear interpolation</td>
</tr>
<tr class="even">
<td align="left"><code>math.fmod(angle, 2*math.pi)</code></td>
<td align="left">normalize an angle</td>
</tr>
<tr class="odd">
<td align="left"><strong>tables</strong></td>
<td align="left"></td>
</tr>
<tr class="even">
<td align="left"><code>next(t) == nil</code></td>
<td align="left">table is empty</td>
</tr>
<tr class="odd">
<td align="left"><strong>strings</strong></td>
<td align="left"></td>
</tr>
<tr class="even">
<td align="left"><code>s:match'^something'</code></td>
<td align="left">starts with</td>
</tr>
<tr class="odd">
<td align="left"><code>s:match'something$'</code></td>
<td align="left">ends with</td>
</tr>
<tr class="even">
<td align="left"><code>s:match'["\'](.-)%1'</code></td>
<td align="left">match pairs of single or double quotes</td>
</tr>
<tr class="odd">
<td align="left"><strong>i/o</strong></td>
<td align="left"></td>
</tr>
<tr class="even">
<td align="left"><code>f:read(4096, '*l')</code></td>
<td align="left">read lines efficiently</td>
</tr>
</tbody>
</table>
</section>
</div>
<div id="tab2_container" class="doc"></div>
</div>
</div>
<div class="container">
<footer>
<div id="disqus_thread"></div>
<div class="faint">[email protected] | <a href="http://unlicense.org/">public domain</a></div>
</footer>
</div>
</div>
<script type="text/x-mustache" id=info_tab_template>
<h3>Modules</h3>
<ul>
{{#module_array}}
<li>{{name}}</li>
{{/module_array}}
</ul>
</script>
</body>
</html>