Question: I saw power of LuaLaTeX through several examples on the TeX Stack Exchange site. Could you suggest some books or other resources to learn Lua programming? I want to learn about variables, loops, conditionals, string operations, writing functions etc. in Lua which then I can use in LaTeX.

Answer: 
There are three canonical resources to learn Lua programming.

1. **“Programming in Lua” by Roberto Ierusalimschy**

<https://www.lua.org/pil/>

You can read the first edition online for free but since that was written for Lua 5.0 and the current version of Lua is 5.3, the usefulness of the online version is somewhat limited. The latest edition is available as a paperback and always covers the latest version of Lua. It is a really good book and I recommend you read it.
2. **“Lua Programming Gems” edited by L. H. de Figueiredo, W. Celes, R. Ierusalimschy**

<https://www.lua.org/gems/>

This book presents implementations of various computational problems and algorithms in Lua. It also gives advice on how to write fast and efficient Lua code. However, it requires a good understanding of the Lua language already.
3. **Lua Reference Manual**

<https://www.lua.org/manual/>

The reference manual is not really something you read cover to cover, but it lists all the functions and constructs known to the Lua interpreter, together with their parameters and occasional usage examples.

Since you are asking in the context of LuaTeX, there are some other resources to consider.

4. **The LuaTeX manual**

`texdoc luatex` or <http://mirrors.ctan.org/systems/doc/luatex/luatex.pdf>

The LuaTeX manual is a reference manual and does not attempt to teach how to use the Lua extensions of TeX. However, it lists all the available callbacks and methods. To learn about how to use them, I recommend the two articles

> 
> 
> 	* P. Isambert. Three things you can do with LuaTeX that would be extremely painful otherwise. TUGboat, 31(3):184–190, 2010. <https://tug.org/TUGboat/tb31-3/tb99isambert.pdf>
> 	* P. Isambert. LuaTeX: What it takes to make a paragraph TUGboat, 32(1):68–76, 2011. <https://tug.org/TUGboat/tb32-1/tb100isambert.pdf>
> 

Because these two articles are also a little dated, some of the functionality presented therein has been removed meanwhile, most notably the `token_filter` callback. Of course there are many more articles in [TUGboat](https://tug.org/tugboat/) dealing with LuaTeX.
5. **Further LuaTeX online resources**

	* <http://www.luatex.org/documentation.html>

	LuaTeX project website with some older presentations.
	* <http://wiki.luatex.org/index.php/Main_Page> 

	LuaTeX Wiki with examples for callbacks and nodes.
	* <https://wiki.contextgarden.net/Lua>

	ConTeXt Wiki page about Lua. The packages `luaotfload` and `lualibs` (the latter being loaded by the former) are actually extracted from ConTeXt to work with Lua(La)TeX. Therefore some of the ConTeXt extensions to the Lua language are available in Lua(La)TeX as well.
I can strongly recommend becoming familiar with the [luacode](https://ctan.org/tex-archive/macros/luatex/latex/luacode) package, which provides various tools to make it more straightforward to get Lua code up and running inside a LuaLaTeX document.

* The package complements the basic `\directlua` instruction with four additional interfaces -- the macros `\luadirect` and `\luaexec`, and the environments `luacode` and `luacode*`. These interfaces differ in the way TeX-special characters such as `%` and `\` can (or, rather, *must*) be entered and passed back and forth between the LaTeX and Lua sides of things.
* The package also provides the user-level macros `\luastring`, `\luastringN`, and `\luastringO`. These can be extremely useful for passing strings of various degrees of complexity from LaTeX to Lua.
* The package's [user guide](http://mirrors.ctan.org/macros/luatex/latex/luacode/luacode.pdf) is very clear and nicely written.