Lua Primer

While the Lua reference manual is indispensable, here are the most important parts of Lua you'll need to get started. This is meant to give a very brief overview and let you know where in the manual to look for further details, not to teach Lua.

Important functions

Note that tostring on tables will give unsatisfactory results; you will want to use fennelview or another pretty-printer for debugging and development.

Important modules

You can explore a module with (each [k v (pairs math)] (print k v)) in the repl to see all the functions and values it contains.

In particular table.insert and table.remove are intended for sequential tables; they will shift over the indices of every element after the specified index. To remove something from a non-sequential table simply set the field to nil.

Note that Lua does not implement regular expressions but its own more limited pattern language for string.find, string.match, etc.


Lua loading

These are used for loading Lua code. The load* functions return a "chunk" function which must be called before the code gets run, but dofile executes immediately.


source for this site