Lua Code Snippets
Below are some useful Lua code snippets for use in everyday projects.
If a piece of code is repeated in a number of different scripts, it can be moved into a script on its own and then included where needed in other scripts. This can be done using relative or absolute paths to the script to be included. Note that double back slashes are required in the file paths because the first is used to escape the second, so that it is taken literally and included in the path.
-- Include another script using a relative path. dofile(".\\includes\\demo-include.lua") -- Include another script using an absolute path. dofile("c:\\demo\\includes\\demo-include.lua")