How to get number of entries in a Lua table?

You already have the solution in the question — the only way is to iterate the whole table with pairs(..). Also, notice that the “#” operator’s definition is a bit more complicated than that. Let me illustrate that by taking this table: According to the manual, any of 3, 5 and 9 are valid results for #t. The only … Read more

What is a good game engine that uses Lua?

Game engines that use Lua Free unless noted Agen (2D Lua; Windows) Amulet (2D Lua; Window, Linux, Mac, HTML5, iOS) Cafu 3D (3D C++/Lua) Cocos2d-x (2D C++/Lua/JS; Windows, Linux, Mac, iOS, Android, BlackBerry) Codea (2D&3D Lua; iOS (Editor is iOs app); $14.99 USD) Cryengine by Crytek (3D C++/Lua; Windows, Mac) Defold (2D Lua; Windows, Linux, Mac, iOS, Android, Web, Switch) gengine (2D Lua; Windows, Linux, HTML5) Irrlicht (3D C++/.NET/Lua; Windows, Linux, Mac) Leadwerks (3D C++/C#/Delphi/BlitzMax/Lua; Windows; $199.95 … Read more

How to remove a lua table entry by its key?

No, setting the key’s value to nil is the accepted way of removing an item in the hashmap portion of a table. What you’re doing is standard. However, I’d recommend not overriding table.remove() – for the array portion of a table, the default table.remove() functionality includes renumbering the indices, which your override would not do. If you do want … Read more

Concatenation of strings in Lua

As other answers have said, the string concatenation operator in Lua is two dots. Your simple example would be written like this: However, there is a caveat to be aware of. Since strings in Lua are immutable, each concatenation creates a new string object and copies the data from the source strings to it. That … Read more