Lua Semicolon Conventions

Semi-colons in Lua are generally only required when writing multiple statements on a line. So for example: Alternatively written as: Off the top of my head, I can’t remember any other time in Lua where I had to use a semi-colon. Edit: looking in the lua 5.2 reference I see one other common place where … Read more

Lua: Rounding numbers and then truncate

Which is the best efficient way to round up a number and then truncate it (remove decimal places after rounding up)? for example if decimal is above 0.5 (that is, 0.6, 0.7, and so on), I want to round up and then truncate (case 1). Otherwise, I would like to truncate (case 2)

Lua – Number to string behaviour

In Lua 5.2 or earlier, both tostring(10) and tostring(10.0) result as the string “10”. In Lua 5.3, this has changed: That’s because Lua 5.3 introduced the integer subtype. From Changes in the Language: The conversion of a float to a string now adds a .0 suffix to the result if it looks like an integer. (For instance, the float 2.0 will be printed as 2.0, not … Read more

How to dump a table to console?

Feel free to browse the Lua Wiki on table serialization. It lists several ways on how to dump a table to the console. You just have to choose which one suits you best. There are many ways to do it, but I usually end up using the one from Penlight: