Lua: language for the Web?
This is a modal window.
The media could not be loaded, either because the server or network failed or because the format is not supported.
Formal Metadata
Title |
| |
Alternative Title |
| |
Title of Series | ||
Part Number | 101 | |
Number of Parts | 110 | |
Author | ||
License | CC Attribution 2.0 Belgium: You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor. | |
Identifiers | 10.5446/31015 (DOI) | |
Publisher | ||
Release Date | ||
Language |
Content Metadata
Subject Area | |
Genre |
FOSDEM 2016101 / 110
4
6
10
11
13
15
17
19
20
23
25
27
30
32
36
38
39
41
42
43
44
45
46
47
48
50
52
54
58
61
62
69
71
72
75
76
78
79
80
82
87
88
91
93
94
95
96
97
101
103
104
106
107
110
00:00
AlgebraFile viewerCompilerMereologyGoodness of fitProcess (computing)Table (information)Object (grammar)Scripting languageSoftware developerWindowInversion (music)Projective planeCategory of beingTheoryCommitment schemeCASE <Informatik>PlanningReading (process)FamilyElectric generatorForm (programming)Operator (mathematics)Point (geometry)Multiplication signCuboidBlock (periodic table)Web browserProxy serverRevision controlSimilarity (geometry)Event horizonMoment (mathematics)Semiconductor memoryDigitizingTranslation (relic)Mathematical analysisBitWeb pageSeries (mathematics)Run time (program lifecycle phase)Different (Kate Ryan album)Student's t-testFunctional (mathematics)Pattern matchingGame theoryPhysical lawLibrary (computing)Integrated development environmentVideo gameType theoryCase moddingCodePlug-in (computing)BytecodeMultiplicationGreatest elementInheritance (object-oriented programming)Just-in-Time-CompilerStandard deviationZoom lensMeta elementNumberStructural loadHookingXMLLecture/Conference
07:34
Matching (graph theory)Game theoryProgram slicingPhysical lawMusical ensembleWindowMultiplication signLevel (video gaming)Stress (mechanics)Web pageMessage passingScripting languageArithmetic meanPoint (geometry)WordPower (physics)File systemReading (process)Electric generatorSoftware testingFormal languageProcess (computing)Web browserCartesian coordinate systemSoftware developerLibrary (computing)Table (information)Physical systemSource codeContext awarenessDebuggerWorld Wide Web ConsortiumCASE <Informatik>Event horizonTask (computing)Data managementPressureOrder (biology)MereologyNetwork topologyPlug-in (computing)QuicksortLine (geometry)IntegerNumberLattice (order)Sign (mathematics)Group actionImplementationCodeComputer fileError messageFunctional (mathematics)CoroutineMappingWeb-DesignerBitNamespaceAttribute grammarVirtual machineNP-hardDirectory serviceElectronic mailing listBytecodeLecture/Conference
15:04
Computer animation
Transcript: English(auto-generated)
00:11
Hello everyone, my name is Paul, I'm a front-end developer so I usually write JavaScript but I used to work for a gaming company and they use Lua a lot so I picked it up there
00:25
and absolutely loved it and I wanted to use it every day. So the more ways they can run Lua in the browser the better.
00:42
So I'll try and speak up. Okay so you may know me from another project which is Moonshine. I'm not going to talk about it today but it's a VM that runs Lua bytecode in the browser. So you have to take your Lua code, compile it, process that compiled bytecode to JSON and then
01:07
run it in the browser. And that has limitations, you can't run arbitrary Lua code in the browser and because it interprets the bytecode at runtime it's not benefiting from the
01:22
the JIT of the browser. So today I'm going to talk about my new project which is Starlight, which is a translator from Lua to Lua code to Lua to JavaScript or more specifically
01:45
ES6 or ES2015 as it's called now. So first of all the story of Starlight started six months ago but it really started like two years ago when I came across ES6 for the first time and noticed
02:01
there's some similarities here between what I use every day and what I would want to be using every day. And first of all generators obviously it's cooperative multitasking, it's very similar to something we know already which is k-routines and the syntax is very similar.
02:22
There's the spread operator that takes an array and unpacks it into its individual parts very much like table.unpack. Table.unpack was released with Lua 5.0 in 2003.
02:47
So that's 13 years it's been in Lua and it's only just got to the browser which is great. To put that into context, in 2003 I had a state-of-the-art mobile phone that I loved for the time. It was an orange SPV, it ran Windows, there was no such thing as iPhones
03:05
back then but it had a camera which was extremely advanced but you had to carry it around with you and plug it into the bottom. So that's 2003. So other features, there's the rest
03:29
in 1996 when we were playing Mario 64. Other features are proxies where you can define an
03:40
object with certain properties and handler functions, then apply that object to another and hook into the events on that object very much like meta tables or fallbacks as they were first introduced in 2.1 and that was back in 1995 when we had Usual Suspects on the screens,
04:05
Toy Story and of course Sailor Moon Super S, the movie. Lastly destruction assignments, obviously familiar with these multiple return values and block scoping via the let keyword.
04:26
So yeah, they all came out with the initial version of Lua, there's a new version number on there but it's 1994, the year that England didn't qualify for the World Cup unfortunately.
04:45
So yeah, good year for Brazil 1994, Lua and the World Cup. So yeah, let's fast forward 21 years now, so it's a whole Justin Bieber and we have the ability to do these things in the browser.
05:07
Yeah, it's taken a while though because I was busy when ES6 first came out so I saw these things and I thought someone else is going to see these similarities, there'll be a translator, someone will write one, it's going to be great and I waited a year and a half and no one made
05:24
and so I was like okay, go on then. But yeah, I had the free time and so I created Starlight. Obviously the name comes from moonshine to starlight. What does it look like? Well,
05:40
this is going to be a problem, can everyone see that? Okay. Yeah, zoom doesn't work. Okay, well you've got your Lua code here in the script tag with a Lua type. You include the starlight library which will take the tags with the mark Lua and
06:09
execute them on page load if you've got the switch. It does translate it to ES6 which some browsers don't, well a lot of browsers don't handle all of ES6 just yet, so you need
06:24
for now include Babel browser plugin. And that's pretty weighty, that's over 800k and it's a little bit slow, but fortunately it's not going to be around forever, browsers will take on the support natively and we can get rid of that.
06:46
So how do you use, or how to configure it? You can configure how the standard out is directed, but also this is probably more important, you can import your JavaScript code
07:03
or your JavaScript functions into the Lua environment and then just run them in the Lua. In Saylor, they've benefited from having modules, so we've got this top code block,
07:24
it's got the module, mod name, greeting, so it's pre-loaded, it's not run straight away and then it can be referenced using require from other script tags. It also has a DOM API, obviously you can get away from JavaScript but you can't get away from the DOM in the browser.
07:44
So this uses the same API as moonshine, everything's packaged into the window namespace, so you prefix everything with window, but there's also a window.extract which will
08:03
extract all of those functions out into the global namespace if that's what you want to do, and then it looks a bit more normal, like timeout. Although you will have to use the colon syntax to keep the context for each function cool. Obviously that's great, but I didn't code front
08:23
end, I didn't script my applications in script tags in the page. I use Grunt or Gulp or Webpack, so you can do the same with this and have all your Lua scripts
08:41
in directory structure, then at build time just package them all together. It's pretty simple, it's got a source, a destination, again we need to use Babel to translate that ES6 to something we can use today, but eventually get rid of that. It's only six months old,
09:06
and it's still in development, so we've got a bit of a road map. Source mapping would be good at the moment, you get error messages, but you don't get line numbers or any context which is a bit hard going.
09:24
Gulp task, use the source attribute on script tags, it doesn't support that at the moment, so that'll be a biggie. A plugin system is desirable, because things like coroutines and generators, they aren't a one-to-one match, and there are some issues,
09:45
and you'd need to restrict how you use coroutines in order to get it to translate. I'd rather not support that natively and have it in a plugin where you sign up to this knowledge.
10:02
That's kind of it really. What I'd love you to do is to use it and report any issues you find. With Moonshine I had a whole team of Lua developers available that would tell me where I was going wrong all the time. I don't have that anymore, so I need feedback
10:22
and tell me where my documentation is lacking, because I know it is. And that's it really, it was just an introduction.
11:16
I should have been more clear with that. Starlight takes the script tags
11:25
with Lua in them and then just translates that. It uses Lua pars and has a code generator to take the AST tree and just create some JavaScript, some ES6 code that runs.
11:50
So it is running JavaScript. So it's actually translating the word to JavaScript? Yes, yes. Do the functions defined in Lua, are they JavaScript functions as well,
12:01
and could you put them in the old clicker head? Yes. Could you explain how do you want to benefit from using coroutines for plugins, and why not to use simple functions? Well, coroutines, they have a lot of benefits, especially back in gaming, in animation,
12:26
you can kind of time slice things. So yeah, there's a lot of benefits to using coroutines there. Unfortunately, yeah, it doesn't map to generators, but I've forgotten what the other part of your question was.
12:43
Why do you think coroutines are useful for plugins? Sorry, I probably didn't make that clear. The coroutines weren't for the plugins. I want to put the coroutines namespace in a plugin. So I need to create a plugin system for that.
13:02
So is there anything else apart from coroutines that you can't implement in CX? Is that the only thing? Possibly. Obviously, there's the debug library that is very implementation specific, so that's not going to translate, and things like OS and the file system,
13:26
but you can mock the files. There's no other language features you can have issues with. Not that I know of, no. So it's mainly using Strelite? Yes, it is using Strelite and other virtual machines.
13:41
I initially used Strelite, it didn't exist. So we started off with low-fi 1GS, and then as I started searching around, I found Moonshine, and then I decorated it with Moonshine, and then I ran into a problem, because Moonshine takes bytecode,
14:03
and then runs it on a virtual machine, and there was a problem with whether you were running Sailor Overlord yet, because the bytecode generated is completely different. So we were unable to do that, and so I contacted Paul because he was working on Moonshine,
14:24
and then he told me, Oh, I actually have this other thing, which is called Strelite, and any other questions? Does Strelite generate source notes?
14:40
No, no, that's on the to-do list. Yeah, that's what we needed. I was convinced that Lua is a great language for web development.