TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Learn Lua in 15 Minutes

357 pointsby tylerneylonalmost 12 years ago

31 comments

karpathyalmost 12 years ago
This is awesome. I will take [a single huge list of self-explanatory example snippets (with a few short comments here and there) for 95% of use cases] over [detailed walls-of-text docs pages spread across a hierarchy of topics] any day.
评论 #5937367 未加载
评论 #5937178 未加载
评论 #5936693 未加载
评论 #5937767 未加载
评论 #5937764 未加载
评论 #5937345 未加载
dave1010ukalmost 12 years ago
Along the same lines is <a href="http://hyperpolyglot.org/" rel="nofollow">http:&#x2F;&#x2F;hyperpolyglot.org&#x2F;</a> (which has been posted here a few times). This is useful both for learning a new language and for a quick reference for languages you&#x27;re not so hot on. It&#x27;s also very interesting to compare similarities and how languages have influenced each other.<p>It seems (from the comments here and my own experience) that many people really like this style of learning. It would be great to see it applied in more areas.
评论 #5937365 未加载
评论 #5936155 未加载
silentbicyclealmost 12 years ago
This is a good start, but there&#x27;s also some deeper ideas in Lua. It has a good implementation of coroutines, for example; if you&#x27;re familiar with continuations from Scheme, they fit most of the same uses. (They&#x27;re like generators from Python or fibers from Ruby, but with less edge cases.)<p>The C interop is also a Big Deal. Lua seems like a cute little language, like a cleaner Javascript, but it&#x27;s a LOT more useful if you&#x27;re also proficient in C. Also, Lua will run anywhere you have an ANSI C compiler and a modest amount of space.
评论 #5938367 未加载
sharkbotalmost 12 years ago
I&#x27;m going to be &quot;that guy&quot;:<p><pre><code> -- These are the same: -- ...snip... local function g(x) return math.sin(x) end local g = function (x) return math.sin(x) end </code></pre> According to the Lua Reference Manual [1], this example isn&#x27;t correct. Rather, this is the correct translation:<p><pre><code> local function g(x) return math.sin(x) end local g; g = function (x) return math.sin(x) end </code></pre> From the manual: &quot;This only makes a difference when the body of the function contains references to f.&quot;<p>[1] <a href="http://www.lua.org/manual/5.2/manual.html#3.4.10" rel="nofollow">http:&#x2F;&#x2F;www.lua.org&#x2F;manual&#x2F;5.2&#x2F;manual.html#3.4.10</a>
评论 #5936305 未加载
评论 #5936362 未加载
outworlderalmost 12 years ago
This is awesome.<p>On that note, I don&#x27;t understand all the javascript craze. Lua has been around for quite some time, and it&#x27;s small, with well-defined semantics, a nice set of features, the interpreter is small and very fast, you can get even faster with LuaJIT, etc. Browsers should have adopted that ages ago.
评论 #5935830 未加载
评论 #5935924 未加载
评论 #5935968 未加载
评论 #5936284 未加载
alecdbrooksalmost 12 years ago
A logical next step might be to do do the Lua Missions (read: koans): <a href="https://github.com/kikito/lua_missions" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;kikito&#x2F;lua_missions</a>.<p>(Disclaimer: The missions look good, but I haven&#x27;t personally tried them.)
评论 #5938294 未加载
daenzalmost 12 years ago
Lua can be great. I&#x27;ve worked with it extensively on a personal project, where I&#x27;ve embedded it in a C++ app. However, there are some things that you will hate:<p><pre><code> * Trying to correctly do &quot;inheritance&quot; * Having to write all of your batteries for common ops * Array indices begin at 1! * Poor debugging support </code></pre> Aside from those thing, Lua is great. It&#x27;s crazy fast and easy to embed.
agscalaalmost 12 years ago
I prefer learning this way also, so I wrote something sort of similar for Vimscript a while back. The # of people that ever need to use vimscript is low, but it&#x27;s out there for people to get their feet wet.<p><a href="http://andrewscala.com/vimscript/" rel="nofollow">http:&#x2F;&#x2F;andrewscala.com&#x2F;vimscript&#x2F;</a>
programminggeekalmost 12 years ago
I would like to say that the easiest way for me to learn lua really fast was to build games with Corona using lua.<p>Having a great tool that gives great feedback right away makes learning a language more fun IMO.
评论 #5935650 未加载
评论 #5938514 未加载
评论 #5935889 未加载
hanjosalmost 12 years ago
Nice work!<p>One nitpick: local function declarations, like<p><pre><code> local function g(x) return g(x) end </code></pre> are actually the same as writing<p><pre><code> local g; g = function (x) return g(x) end </code></pre> . Without that first local g; statement, local functions wouldn&#x27;t be able to call themselves recursively.
评论 #5936383 未加载
piqufohalmost 12 years ago
I love this - if every language could have something like this written up it would be amazing. It just about fits into my attention span!
评论 #5935762 未加载
znowialmost 12 years ago
This is great! I wish every language had an intro like that :)<p>It was interesting to find resemblance of Lua&#x27;s classes to Perl&#x27;s blessing. Always meant to look into the language and this tutorial made me do it.<p>I also learned about the LÖVE game engine, which I&#x27;m going to play with this week. Thank you!<p><a href="http://love2d.org/" rel="nofollow">http:&#x2F;&#x2F;love2d.org&#x2F;</a>
评论 #5939069 未加载
thyrsusalmost 12 years ago
First, that was very useful; bookmarked.<p>That took me 30 minutes to read. I think I might feel like I&#x27;ve learned the language after spending 8 hours working the examples a la &quot;Learn Python the Hard Way&quot;. Luckily, I&#x27;m not competing with the folks here that learned it within 15 minutes ;-).
评论 #5936380 未加载
lukefreileralmost 12 years ago
I love this. I&#x27;d like&#x2F;pay to have a consistent library of exactly this for other languages.
评论 #5935595 未加载
评论 #5937926 未加载
Dylan16807almost 12 years ago
This is a neat little reference but I can&#x27;t waste the opportunity.<p>I&#x27;ve seen people say they&#x27;ve never seen complaints about fonts being too big? Well here I am, complaining that the fonts are so big this page is hard for me to read without zooming out.
spacecowboyalmost 12 years ago
That was a pretty cool crash course on Lua Tyler! Thanks for putting that together and sharing it. After having had worked with numerous languages over the years such as Fortran, Pascal, Ada, C, Java, C++, C#, Python and Objective-C, I must say that working with Lua is my favorite. I&#x27;m thankful to a buddy of mine for introducing it to me. My own personal experience has shown me that working with Lua really allows you to focus on solving the problem versus getting wrapped around the axle at the programming language level. Thanks again
nathasalmost 12 years ago
That was lovely. I always had a hard time wrapping my head around the exact behavior of metatables when I messed with Lua a few years back. Thanks!
noonespecialalmost 12 years ago
I learned to love lua when writing basic sysadmin scripts for OpenWRT based systems. I had previously used perl for sysadmin stuff, but perl (even microperl) took too much space on OpenWRT boxes with 4MB flash drives. Lua to the rescue. Now I chafe when I have to go pack to perl.<p>I do wish someone had handed me this on the first day I realized I needed lua.
ErikRognebyalmost 12 years ago
Maybe for the next Ludnum Dare...<p>nice write up comparison of lua based game engines: <a href="http://www.gamefromscratch.com/post/2012/09/21/Battle-of-the-Lua-Game-Engines-Corona-vs-Gideros-vs-Love-vs-Moai.aspx" rel="nofollow">http:&#x2F;&#x2F;www.gamefromscratch.com&#x2F;post&#x2F;2012&#x2F;09&#x2F;21&#x2F;Battle-of-the...</a>
digitalsushialmost 12 years ago
Thanks! Lua is used all over the place in wireshark user scripts. This is super useful.
mnearyalmost 12 years ago
Anyone else catch the Gauss reference[1] in the for loop section?<p>[1] <a href="http://en.wikipedia.org/wiki/Carl_Friedrich_Gauss#Anecdotes" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Carl_Friedrich_Gauss#Anecdotes</a>
评论 #5937930 未加载
评论 #5938096 未加载
评论 #5937909 未加载
landharalmost 12 years ago
This is very cool, the only way I can see this could be improved upon is by adding unit tests somehow (so that you can catch behavior changes when upgrading to a newer version of lua).
评论 #5937298 未加载
daGrevisalmost 12 years ago
Lua is weird mix between JavaScript and Python. I kind of like it.
johnchristopheralmost 12 years ago
Bonus point for Cloud Atlas reference :)
vishal0123almost 12 years ago
Just awesome. I wonder whether this type of example-based snippet exist for other languages.
ufoalmost 12 years ago
This would look much better with syntax highlighting.
jeltzalmost 12 years ago
Having a font size of 25.33pt makes the website impossible to read without zooming out 3 steps. I would be happy if people stopped using tiny and huge default font sizes.
评论 #5937143 未加载
评论 #5939049 未加载
chiialmost 12 years ago
very comprehensive and interesting! i wish theres one for other languages too.
dakimovalmost 12 years ago
Great sheet.<p><pre><code> -- Variables are global by default. thisIsGlobal = 5 -- Camel case is common. </code></pre> -- Undefined variables return nil. -- This is not an error: foo = anUnknownVariable -- Now foo = nil.<p>-- Only nil and false are falsy; 0 and &#x27;&#x27; are true!<p>Didn&#x27;t read further. Bad language design. Must die.
评论 #5938509 未加载
评论 #5941212 未加载
评论 #5938243 未加载
J_Darnleyalmost 12 years ago
That page could do with a little syntax highlighting, at least for the comments. -- does not stand out.
评论 #5939551 未加载
nbouscalalmost 12 years ago
Obligatory: Teach Yourself Programming in Ten Years — <a href="http://norvig.com/21-days.html" rel="nofollow">http:&#x2F;&#x2F;norvig.com&#x2F;21-days.html</a>