/
index.html
executable file
·435 lines (394 loc) · 10.2 KB
/
index.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Lua in Wikipedia</title>
<meta charset="utf-8">
<meta name="viewport" content="width=792, user-scalable=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<link rel="stylesheet" href="shower/themes/ribbon/styles/screen.css">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
-- use prettify to make code look nice
<link href="prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="prettify.js"></script>
<!--
To apply styles to the certain slides
set slide ID to get needed elements
-->
<style>
#Cover h2 {
margin:30px 0 0 350px;
color:#FFF;
text-align:center;
font-size:70px;
}
section#Cover p {
margin:10px 0 0 350px;
text-align:center;
color:#FFF;
font-style:italic;
font-size:20px;
}
#Cover p a {
color:#FFF;
}
#Picture h2 {
color:#FFF;
}
#SeeMore h2 {
font-size:100px
}
#SeeMore img {
width:0.72em;
height:0.72em;
}
a.image {
text-decoration: none;
border: 0;
color: fff;
}
</style>
</head>
<body class="list" onload="prettyPrint()">
<header class="caption">
<h1>Lua in Wikipedia</h1>
<p>Justin Cormack</p>
</header>
<section class="slide cover" id="Cover"><div>
<h2>Lua in Wikipedia</h2>
<p>Justin Cormack <a href="https://twitter.com/justincormack">@justincormack</a></p>
<p>London Lua <a href="http://www.londonlua.org/">http://www.londonlua.org/</a></p>
<img src="pictures/london-lua512.png" alt="">
</div></section>
<section class="slide"><div>
<h2>What is Lua?</h2>
<ol>
<li>Created in 1993 (between Ruby and Python)</li>
<li>From Rio de Janeiro</li>
<li>Designed to be simple, small, portable, fast, and easily embedded into applications (like Wikipedia)</li>
</ol>
<a href="https://commons.wikimedia.org/wiki/File:Panorama_from_Rio_de_Janeiro.jpg" class="image"><img src="pictures/800px-Panorama_from_Rio_de_Janeiro.jpg" alt="Rio de Janeiro"></a>
</div></section>
<section class="slide shout"><div>
<h2>Intro to Lua</h2>
</div></section>
<section class="slide"><div>
<h2>What does it look like?</h2>
<pre class="prettyprint">
-- defines factorial
function fact (n)
if n == 0 then
return 1
else
return n * fact(n - 1)
end
end
</pre>
</div></section>
<section class="slide"><div>
<h2>Types</h2>
<pre class="prettyprint">
a = "a string"; type(a) --> "string"
a = 2 ; type(a) --> "number"
a = fact ; type(a) --> "function"
a = nil ; type(a) --> "nil"
a = true ; type(a) --> "boolean"
a = {1, 2, 3} ; type(a) --> "table"
a = {name = 1}; type(a) --> "table"
</pre>
</div></section>
<section class="slide"><div>
<h2>Numbers</h2>
<p>Only one kind of number whether integer or floating point.
<pre class="prettyprint">
a = 2 * 4
b = tonumber("65")
c = math.abs(-1)
d = 3.2 * math.sqrt(42)
</pre>
</div></section>
<section class="slide"><div>
<h2>Strings</h2>
<p>Strings are treated as binary bytes, not zero terminated. Need a library for UTF8 operations.
<pre class="prettyprint">
a = "test " .. "appending"
b = "append a number " .. tostring("65")
c = "append a number " .. 65
utf = "รีโอเดจาเนโร"
#utf --> 36 -- length in bytes, not characters
</pre>
</div></section>
<section class="slide"><div>
<h2>Variables</h2>
<p>These must have ASCII names, plus underscore, or numbers after the first character. Default is global, local in a block (eg function, do .. end)
<pre class="prettyprint">
test1 = 3 -- global
do
local test1 = "not the global"
end
test1 = 4 -- global
</pre>
</div></section>
<section class="slide"><div>
<h2>Functions</h2>
<p>First class functions, tail recursion supported
<pre class="prettyprint">
function double(a)
return a * 2
end
double = function(a) return a * 2 end
</pre>
</div></section>
<section class="slide"><div>
<h2>Multiple values</h2>
<pre class="prettyprint">
function double_both(a, b)
return a * 2, b * 2
end
print(double_both(1, 2))
x, y = double_both(6, 7)
print(x, y)
x, y = y, x
print(x, y)
</pre>
</div></section>
<section class="slide"><div>
<h2>if then else</h2>
<p>Any value that is not false or nil is truthy (<b>including 0</b>)
<pre class="prettyprint">
function is2(a)
if a == 2 then return true
else return false
end
end
function is2(a) if a == 2 then return true else return false end end
</pre>
</div></section>
<section class="slide"><div>
<h2>booleans</h2>
<p>You can use boolean and, or, not.
<pre class="prettyprint">
function is2or3(a)
return a == 2 or a == 3
end
b = nil
c = b or "b was nil"
c --> "b was nil"
</pre>
</div></section>
<section class="slide"><div>
<h2>for loop (numeric)</h2>
<pre class="prettyprint">
local sum = 0
for i = 1, 10 do
sum = sum + i
end
-- i no longer defined here, local to loop
</pre>
</div></section>
<section class="slide"><div>
<h2>Tables as arrays</h2>
<pre class="prettyprint">
a = {1, 2, 3} -- standard dense 1-based array
a[1] --> 1
#a --> 3
a[#a + 1] = 4 -- extend array
#a --> 4
table.concat(a, ", ") --> "1, 2, 3"
</pre>
</div></section>
<section class="slide"><div>
<h2>Tables as sparse arrays</h2>
<pre class="prettyprint">
b = {[4] = 3, [10] = 4}
b[10] --> 4
b[1] --> nil
b[4] = 6
-- #b not usefully defined if sparse
</pre>
</div></section>
<section class="slide"><div>
<h2>Iterate over arrays</h2>
<pre class="prettyprint">
a = {10, 11, 12, 13}
for i = 1, #a do print(i, a[i]) end
for k, v in ipairs(a) do print(k, v) end
</pre>
</div></section>
<section class="slide"><div>
<h2>Tables as hashes</h2>
<pre class="prettyprint">
a = {name = "Lua", age = 19, f = function(x) return x + 2 end}
a.name --> "Lua"
a["name"] --> "Lua"
a.f(1) --> 3
index = "age"
a[index] --> 19
a.extra = 55
</pre>
</div></section>
<section class="slide"><div>
<h2>Iterate over hashes</h2>
<pre class="prettyprint">
a = {name = "Lua", age = 19, f = function(x) return x + 2 end}
for k, v in pairs(a) do
print(k, v)
end
</pre>
</div></section>
<section class="slide"><div>
<h2>Tables as mixtures</h2>
<pre class="prettyprint">
a = {1, 2, 3, 4, name = "Lua", age = 19, f = function(x) return x + 2 end}
for k, v in pairs(a) do
print(k, v)
end
for i = 1, #a do print(i, a[i]) end
</pre>
</div></section>
<section class="slide"><div>
<h2>Simplified function calls</h2>
<pre class="prettyprint">
print "test"
function f(tab)
for k, v in pairs(tab) do print(k, v) end
end
f{name = "Roberto", location = "Rio"}
</pre>
</div></section>
<section class="slide"><div>
<h2>Tables as objects</h2>
<pre class="prettyprint">
p = {}
function p:setname(name) self.myname = name end
function p:name(name) return self.myname end
p:setname("Justin")
print(p:name())
print(p.name(p)) -- this is all that : means
</pre>
</div></section>
<section class="slide"><div>
<h2>Tables as modules</h2>
<pre class="prettyprint">
p = {}
function p:setname(name) self.myname = name end
function p:name(name) return self.myname end
return p
</pre>
Then call with
<pre class="prettyprint">
tab = require "module name"
tab:setname("Justin")
</pre>
</div></section>
<section class="slide shout"><div>
<h2>Wiki templates</h2>
</div></section>
<section class="slide"><div>
<h2>Wiki templates</h2>
<p>In a Wikipedia page you have text and then you have templates to do all the formatting, complex functionality.
<pre class="prettyprint">
{{Infobox musical artist
| name = Nyusha Shurochkina
| image =
| years_active = 2007–present
| background = solo_singer
...
}}
</pre>
</div></section>
<section class="slide"><div>
<h2>Wiki templates</h2>
<p>This will render out the infobox</p>
<img src="pictures/infobox.png">
</div></section>
<section class="slide"><div>
<h2>Wiki templates</h2>
<pre class="tiny">
{{{2|}}}{{
#ifeq: {{{1|}}} | {{padleft:{{{1|}}}| {{{2|}}}4 }}
| {{#ifeq: {{{1|}}} | {{padleft:{{{1|}}}| {{{2|}}}6 }}
| {{#ifeq: {{{1|}}} | {{padleft:{{{1|}}}| {{{2|}}}8 }}
| {{#ifeq: {{{1|}}} | {{padleft:{{{1|}}}| {{{2|}}}9 }}
| 9
| 8
}}
| {{#ifeq: {{{1|}}} | {{padleft:{{{1|}}}| {{{2|}}}7 }}
| 7
| 6
}}
}}
| {{#ifeq: {{{1|}}} | {{padleft:{{{1|}}}| {{{2|}}}5 }}
| 5
| 4
}}
}}
| {{#ifeq: {{{1|}}} | {{padleft:{{{1|}}}| {{{2|}}}2 }}
| {{#ifeq: {{{1|}}} | {{padleft:{{{1|}}}| {{{2|}}}3 }}
| 3
| 2
}}
| {{#ifeq: {{{1|}}} | {{padleft:{{{1|}}}| {{{2|}}}1 }}
| 1
| 0
}}
}}
}}
</pre>
</div></section>
<section class="slide"><div>
<h2>Scribunto Lua templates</h2>
<p>Call with #invoke or wrap in a standard template
<pre class="prettyprint">
{{#invoke:MyLuaTemplate|function|name=Justin|url=http://en.wikipedia.org/}}
</pre>
</div></section>
<section class="slide"><div>
<h2>A template is a Lua module</h2>
<pre class="prettyprint">
local m = {
function1 = function(frame)
name = frame.args.name or "unknown"
return "Hello from Lua " .. name
end,
}
return m
</pre>
</div></section>
<section class="slide shout"><div>
<h2>Resources</h2>
</div></section>
<section class="slide"><div>
<h2>Helpful resources</h2>
<ol>
<li><a href="https://meta.wikimedia.org/wiki/Lua">Mediawiki Lua links<a/>
<li><a href="https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual">Lua reference for Scribunto</a>
<li><a href="https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Scribunto_libraries">Special functions available on Scribunto</a> - useful!
<li><a href="https://en.wikipedia.org/wiki/Wikipedia:Lua_requests">Wikipedia Lua help requests</a>
<li><a href="https://en.wikipedia.org/wiki/Special:PrefixIndex/Module:">List of existing modules</a>
</ol>
</div></section>
<section class="slide shout"><div>
<h2>Getting started</h2>
</div></section>
<section class="slide"><div>
<h2>Getting started</h2>
<ol>
<li>Create a Wikipedia account if you do not have one.
<li>Create a test Lua module at Module:Sandbox/Username/Modulename
<li>Try it out in your user sandbox
</ol>
<p>From now we are going to go live...
</div></section>
<section class="slide shout" id="SeeMore"><div>
<h2><a href="https://github.com/justincormack/luawikitalk/">Slides on GitHub</a></h2>
</div></section>
<p class="badge"><a href="https://github.com/justincormack/luawikitalk">Fork me on Github</a></p>
<!--
To hide progress bar from entire presentation
just remove “progress” element.
-->
<div class="progress"><div></div></div>
<script src="shower/shower.min.js"></script>
<!-- Copyright © 2013 Yours Truly, Famous Inc. -->
</body>
</html>