Wikipedia:Guide to Scribbling/Programmers' Quick start Guide to Lua

Here are some short points about Lua, for those who already know other computer programming languages and how to program. They focus mainly upon what you might find different in Lua.


 * Lua is dynamically typed. There's no static typing at all.
 * From a syntactic point of view, think BASIC (or even COMAL) without line numbers and colons rather than C/C++/Java, Lisp/Scheme, or Forth.
 * There's no, but most control structures have an
 * needs a  and   needs a.
 * denote a table (expression), not a block of code.
 * Indentation, extra whitespace, and (with one exception) newlines don't change syntax or semantics.
 * Almost everything is a table. If it isn't a table, it's a string, a number, a boolean, a function, or a.
 * Libraries are tables.   is the   entry in the table named by the global variable.
 * Arguments that you receive from MediaWiki are tables. But they're a bit special.
 * Arrays are tables that follow a specific convention. The numerical fields in the array start at one, and run contiguously with no "holes" with   values in the middle of the array.
 * is syntactic sugar for.
 * is syntactic sugar for.
 * builds a function. It doesn't declare it.  Functions are first-class objects and can be assigned to variables, placed in tables, serialized into strings, and deserialized back out again.  Think interpreted, not compiled.
 * Functions and tables start off anonymous, as  and , and gain names when assigned to variables.
 * You can create anonymous functions and tables on the fly in the middle of an expression.
 * You can return (anonymous) functions and tables using.
 * Local variables are cheap. Tables are expensive.    may look like two simple member references as in other languages.  It isn't.
 * This isn't C.   takes the   branch.  Only   and   are false.  Even   is true.
 * Tables can have both numeric and string entries. The two don't overlap.    is distinct from.
 * Uninitialized variables and nonexistent fields in tables are.
 * and  both have shortcut evaluation.
 * is assignment,  is equality comparison.
 * is boolean negation, but  is inequality comparison.
 * creates a string literal. To avoid visual confusion, use   or   for strings containing wikitext.
 * Combined with,   creates a multiline comment.  Think of it as.
 * Putting  between the brackets &mdash; e.g.   &mdash; makes these so-called long brackets longer.
 * Functions and tables are passed by reference, not by value.
 * String operations trade space for time. Don't repeatedly concatenate onto the end of a string.  Build up its individual parts in a table and use.
 * by the reciprocal is faster than.
 * and  can only occur at the end of a block.
 * There's no.
 * There's no.
 * is a global variable, not a keyword. By default, it references a function &mdash; first class objects, remember. &mdash; that does iteration over a table.
 * expects the array convention. If your table isn't adhering to that convention, you'll get funny results.
 * Use  to check for a table being empty.
 * When  fails, it returns.
 * This isn't C. We have an exponentiation operator, and it is.