TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Why Lua?

232 点作者 tlowrimore超过 13 年前

23 条评论

alanfalcon超过 13 年前
I took some Visual Basic programming courses in high school, some PASCAL courses in college, and then didn't program anything other than basic HTML/CSS for the next eight years. Last year I programmed an iPhone game in Lua (using the Corona SDK) and it was easy as Tau. Sure a better programmer would have finished the programming aspects in a quarter the time it took me, but I started by looking at Objective-C and I'm not sure I ever would have picked it up without some kind of formal training. Contrast with Corona/Lua, where I watched a few eight minute videos on YouTube and could turn around and make simple but complete programs, and more importantly completely understand what was going on within them. Reading the Lua documentation was a revelation, reading Apple's was a headache.<p>Why Lua? <a href="http://itunes.apple.com/us/app/beat-boxes/id460798042" rel="nofollow">http://itunes.apple.com/us/app/beat-boxes/id460798042</a>
评论 #3536584 未加载
haberman超过 13 年前
The more I learn about Lua's design and implementation, the more impressed I am. It's very rare to see software that does so much with so little code. The design is extremely clean and the code is extremely fast.<p>The C API is easy to use and gives good performance, and yet encapsulates enough of the VM's implementation that C modules are source <i>and binary</i> compatible with both Lua and LuaJIT, two very different implementations of Lua. Note that the C API was designed before LuaJIT was even written, so this API was designed without the benefit of seeing how different implementations of Lua might vary.<p>The source is very readable for the most part; my only stumbling block is that their naming of types and variables is extremely terse at the cost of readability sometimes, and the extensive use of macros can sometimes can require a lot of jumping around. But Lua is an impressive achievement that I frequently refer to for design inspiration.
评论 #3535867 未加载
评论 #3537420 未加载
chubot超过 13 年前
Why isn't Lua more widely used? One reason is a consequence of it being an embedded language. Lua has had 5 major versions which are <i>very</i> incompatible with each other. You're just supposed to stick with the previous version until you upgrade your code.<p>I read all the Lua papers, and they are quite fond of "getting it right" (which is refreshing). They will break things to get it right, whereas other languages stick with all their old design warts in the name of compatibility. I like this approach, but it comes at the expense of popularity.<p>Compare Lua with Python, which has had basically 1 major version for 20 years Python 1.x are all compatible with 2.x -- that was a license change; and Python 3 is having adoption troubles which proves the same point. Python 3 was the chance to "get things right", or fix old design warts, but you can see what a big impact it's having on adoption, fragmentation of libraries, etc.<p>The other reason is that embedding a language isn't as common a use case as a scripting language. I've tried to write stuff in Lua rather than Python, but really Python's "batteries included" philosophy just kills any advantage Lua has.<p>The main reason I would like Lua is so you can distribute stable (small) executables... but when you're starting out Python is a lot easier. You don't want to download LuaSocket or whatever and mess with the build system.
评论 #3535923 未加载
评论 #3535978 未加载
评论 #3538141 未加载
评论 #3535893 未加载
groovy2shoes超过 13 年前
Good article, but one nitpick: not <i>everything</i> in Lua is a table. Tables are a versatile data structure that can be used as arrays, dictionaries, objects, etc. However, Lua provides many types besides tables: numbers, booleans, closures (functions), strings (which are interned), coroutines, and something called userdata (which are typically pointers to something implemented in C).<p>Another cool thing about Lua, which was mentioned only briefly in the article, is proper tail-call optimization (TCO) like you'd find in Scheme. TCO makes expressing recursive algorithms nicer because you don't have to worry about blowing your stack.<p>Lua's design philosophy -- giving the programmer a handful of basic yet powerful features -- makes it somewhat Schemy. I suspect that Lua is about as close as you can get to a ball of mud before becoming Lisp.
评论 #3535910 未加载
评论 #3535938 未加载
评论 #3536282 未加载
gregholmberg超过 13 年前
<i>Speed&#38; Simplicity</i><p><i>LuaJIT speeds can rival code written in C. And if you are still not getting the speed you want, see my 1st point above (Integration with C and C++ for that matter).</i><p>The simplicity of Lua is, I think, really underrated.<p>It is a good learning exercise to write some small benchmark / utility / tool in Lua so you can get an idea of how quickly you can develop, and how fast the resulting code will be.<p>Then read through the Lua source [0] to see just how little code is required to give you that platform for your ideas.<p>[0] <a href="http://www.lua.org/source/5.1/lua.c.html" rel="nofollow">http://www.lua.org/source/5.1/lua.c.html</a>
评论 #3535711 未加载
whatajoke超过 13 年前
Not criicizing lua, but worth comparing to guile.<p>&#62; Integration with C (and C++ for that matter)<p>Guile does it better. You can use shared memory threads in guile without any penalty. Atmost you have to allow for the garbage collector to run when inside FFI functions. But that is a small price to pay in case you need to use multiple parallel-concurrent threads with a single heap.<p>Guile was built with FFI in mind and has an impressive history. Just take a look at guile gnome bindings.<p>&#62; Speed and Simplicity<p>Guile 2 is extremely fast. Not as fast as LuaJIT, but it no reason it won't get there. As for simplicity, take a look at the partial evaluator in trunk of guile 2.<p>&#62; Education<p>Guile is good old scheme.<p>&#62; Functional<p>Can't get more functional than scheme :)<p>&#62; Everything is a Table<p>Well, almost everything is a pair in guile. Vectors and hash-tables are trivially available. Though I recommend to sticking to functional programming in scheme style.<p>&#62; Consistent<p>As before, can't get more consistent than scheme.<p>&#62; Portable<p>Guile is available on n900. So there.<p>To continue, guile has continuations (delimited or otherwise), and macros (hygienic or otherwise), both of which are effectively missing in lua.<p>And guile offers all of this while supporting native threading with a single heap. Sweeet.
评论 #3536103 未加载
评论 #3536372 未加载
评论 #3536152 未加载
评论 #3536517 未加载
评论 #3536611 未加载
评论 #3536175 未加载
评论 #3536886 未加载
marshray超过 13 年前
To echo chubot: Why isn't Lua more widely used?<p>* It lacks an easy-to-use symbolic debugger.<p>* It lacks a first-rate IDE.<p>* It lacks a standard way for people coming from OO/Java to define objects and interfaces.<p>* It lacks a GUI toolkit.<p>* It has a great set of manuals. It lacks an O'Reilly book with a woodcut animal on the cover.<p>* Arrays indexes start at 1.<p>Except for the last item, these are all relatively small things that are simply waiting for someone to come along and do them. This is a testament to the great design of the language.<p>And many of these things do exist, it's just the Lua style seems to be to understate the achievements to the point that folks can't tell the big new stuff from the abandoned projects.
评论 #3535792 未加载
评论 #3535730 未加载
评论 #3535944 未加载
评论 #3535911 未加载
评论 #3536525 未加载
评论 #3536193 未加载
ammmir超过 13 年前
lua (the language and core libraries) is stable and small. many developers are attracted to node.js or rails due to the community ("look, everyone else is doing it!"), ecosystem (abundance of modules/gems to choose from), and rapid release cycles.<p>lua seems to have more of a relaxed, niche community among game developers and scripting language embedders.<p>i've been using lua for about a week so far, for a music player i'm building (<a href="http://cloudplay.fm/" rel="nofollow">http://cloudplay.fm/</a>) and i'm writing the song search/ranking system in lua. it's wonderful to be able to prototype it outside the application and not have to deal with the integration until you need to.<p>i would consider using lua on the server-side (see <a href="http://luvit.io/" rel="nofollow">http://luvit.io/</a> for a node.js-style interpretation, although i'd prefer coroutines instead of callbacks) but there needs to be more work on the library front.<p>to help lua grow, i'd fix these things:<p>- add unicode support<p>- bring the CLI up to par with node.js (i use node as a calculator, too)<p>- build a modern distribution that includes frequently used luarocks
评论 #3535514 未加载
评论 #3535606 未加载
leafo超过 13 年前
Lua is a great platform, but I think there are a lot of areas where it can be made more programmer friendly. That's why I wrote <a href="http://moonscript.org/" rel="nofollow">http://moonscript.org/</a>
评论 #3536256 未加载
评论 #3536161 未加载
评论 #3537150 未加载
评论 #3537174 未加载
hythloday超过 13 年前
I love Lua, but when I read statements like this:<p>&#62;&#62;&#62; In Python, you might __import__('...')' some module and then the variables of the return value would be accessed like vars(module)<p>it makes me wonder if the author is just unfamiliar with Python (and by extension, any language other than Lua) or if they're deliberately misrepresenting other languages to make Lua look good (which it definitely doesn't need).
评论 #3536311 未加载
timmaxw超过 13 年前
I've used Lua for a couple of personal projects. My main objection to it is that accessing an undefined variable or member returns nil rather than throwing an exception. If you make a typo, you don't find out until you try to call or perform arithmetic on your nil value. Since inserting nil into a table just deletes that key of the table, the use site might be several steps away from the typo.<p>Other than that, I agree with the other posters here. It's an impressively lightweight and elegant language. It's especially good for embedding: its C integration is next to none, it's easy to sandbox if you want to run untrusted code, and the interpreter doesn't use any global variables.
评论 #3535958 未加载
评论 #3535966 未加载
JoshTriplett超过 13 年前
For a different perspective, take a look at <a href="http://julien.danjou.info/blog/2011/why-not-lua" rel="nofollow">http://julien.danjou.info/blog/2011/why-not-lua</a> (submitted to HN as <a href="http://news.ycombinator.com/item?id=3536131" rel="nofollow">http://news.ycombinator.com/item?id=3536131</a> ).
ww520超过 13 年前
Does anyone know how good is Lua's support for async IO? Especially the handling of large amount of connections and the memory footprint for each connection?
评论 #3536594 未加载
评论 #3536342 未加载
评论 #3536479 未加载
gregholmberg超过 13 年前
Why Lua?<p>Because the Wikimedia Foundation has decided to use it?<p>"Wikipedia chooses Lua as its new template/macro language" <a href="http://news.ycombinator.com/item?id=3534649" rel="nofollow">http://news.ycombinator.com/item?id=3534649</a><p>"Lua chosen as new template scripting language" <a href="http://en.wikipedia.org/wiki/Wikipedia:Wikipedia_Signpost/2012-01-30/Technology_report" rel="nofollow">http://en.wikipedia.org/wiki/Wikipedia:Wikipedia_Signpost/20...</a>
simon超过 13 年前
The article seemed a little short for me, but then I am actively trying to select between Lua and TCL for some personal scripting projects. There are many fine features with each language and few downsides, so the selection process is hard. Of course, that's a nice problem to have.<p>TCL is ahead by a nose at this point with Unicode support baked in (vs. using a library) and file system handling built in (again vs. using a library).
评论 #3535447 未加载
评论 #3536389 未加载
评论 #3537427 未加载
评论 #3536760 未加载
bitcracker超过 13 年前
I was first disappointed ... then amazed!<p>Disapointed because the author's link to the benchmark website lead me to the wrong impression that Lua would be almost 30 times slower than Java 7. Then I googled around and discovered the awesome LuaJit which seems to be able to compete even with C++ in performance.<p>What I really like is Lua's code density (see samples in the Shootout's benchmarks). Very impressive!<p><a href="http://shootout.alioth.debian.org/u32/benchmark.php?test=all&#38;lang=lua&#38;lang2=java" rel="nofollow">http://shootout.alioth.debian.org/u32/benchmark.php?test=all...</a><p>As an old LISPer and Schemer I would like to know if Lua Macros are really as expressive and powerful as Lisp macros. Some people claim this but I am not convinced (I would like to be convinced). The expressive power may be theoretically equivalent but this is also true for C and Assembler :-) The question is: Are Lua macros as easy to handle as Lisp and Scheme macros?<p><a href="http://stackoverflow.com/questions/323346/what-can-lisp-do-that-lua-cant" rel="nofollow">http://stackoverflow.com/questions/323346/what-can-lisp-do-t...</a>
pheon超过 13 年前
The reason its not so popular? IMHO because we live in a society that favors 1sec landing pages, customized per individual options, complexity that rivals air skyscrapers and shrinked wrapped ready-to-go solutions. This is not LUA.<p>LUA is just one tool in the tool box - its not the tool box.
Hexx超过 13 年前
On the integration front, one thing I will also add is that in .NET integrating Lua with your program feels pretty close to being a first-class citizen. Very nice.
meric超过 13 年前
In lua, the <i>metatable</i> is the killer feature that python doesn't have.
评论 #3535505 未加载
评论 #3535667 未加载
forrestthewoods超过 13 年前
If you want fast Lua I'd recommend checking out Havok Script (<a href="http://havok.com/products/script" rel="nofollow">http://havok.com/products/script</a>). Technically it's not Lua, but rather an extremely fast virtual machine that is compatible with Lua. I worked with it when it was Kore prior to Havok's acquisition, but it was substantially faster than the base Lua. It has some excellent debugging functionality as well.<p>No idea what it costs these days, but if you're writing Lua code and it's need to be fast I'd recommend checking it out.
Angostura超过 13 年前
For anyone with an iPad who wants to tinker with Lua, there's there really rather nice Codea. <a href="http://twolivesleft.com/Codea/" rel="nofollow">http://twolivesleft.com/Codea/</a>
johnx123-up超过 13 年前
Ask HN: 4-Lua JVM implementations, which is best? <a href="http://news.ycombinator.com/item?id=3536996" rel="nofollow">http://news.ycombinator.com/item?id=3536996</a>
munchor超过 13 年前
The worst problem with Lua is that arrays start at 1. That is way too bad for me to use it. I only use it to configure Awesome WM, but it sucks for everything else IMO because of "tables" starting at 1.
评论 #3535698 未加载
评论 #3535589 未加载
评论 #3535925 未加载