lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tuesday 25 January 2011 02:24:34 Alexander Gladysh wrote:
 
> Maybe we should even enter newbie questions (along with answers) there
> ourselves. 

Excellent idea. Let me start it out, and we can keep adding to it.

Q: Why no continue?
A: It interferes with repeat/until, but there are many ways to get along 
without it.

Q: Why doesn't #tablename give the number of entries?
A: Implementation detail, but no matter what number you want there's a way to 
easily get it.

Q: How do you capitalize Lua?
A: Lua. Never LUA or lua.

Q: Why do my tables keep changing by themselves?
A: Tables are always passed and assigned by reference, so changing a table 
within a function changes that same table in the function's caller.

Q: Why no arrays?
A: You can use tables for arrays by making the keys successive integers, and 
Lua tables are optimized so that's pretty efficient.

Q: How do you do OOP in Lua?
A: Technically Lua doesn't have OOP, but you can simulate OOP to your hearts 
content and it's every bit as good as the OOP they give you in other 
languages. Three of many possible ways are 1) Tables, 2) Closures and 3) 
Metatables.

Q: Is Lua fast?
A: You'd better believe it. Very fast for an interpreter.

Q: What's LuaJIT?
A: It's a pretty much drop-in compatible Lua interpreter, except it has no 
interactive mode and it's much faster.

Q: How do I get Lua add-ons?
A: Either from your Linux distribution's package manager, or from Lua's 
package manager LuaRocks, or ./configure;make/make install.

Q: LuaRocks search doesn't find a package I know is there. Why not?
A: The package is probably at a URL not known to LuaRocks. Use a search engine 
to find the package URL and then put that URL in LuaRocks' --from= option. If 
you typically find your using that URL a lot, add it to the rock_servers table 
in your config.lua LuaRocks config file, probably in directory /etc/luarocks.

Q: How do I do database stuff with Lua?
A: The most common way is to use the LuaSQL addon. There are plenty of other 
packages, depending on what you need.

Q: Why do my for loops do weird stuff?
A: Check to see if you're changing loop variables within the loop. That 
creates undefined situations. Check to see whether you're doing adds or 
deletions within your loop. That creates undefined situations.

Q: I don't understand iterators.
A: See http://www.lua.org/pil/6.1.html for the very beginning basics of 
iterators.

Well, that's all for tonight -- you guys add some stuff to it.

Thanks

SteveT

Steve Litt
Recession Relief Package
http://www.recession-relief.US
Twitter: http://www.twitter.com/stevelitt