How to create include files in Lua language?

Fernando Pinheiro picture Fernando Pinheiro · May 28, 2010 · Viewed 68.8k times · Source

I want to create a header file in Lua (header.lua), then execute the require function to load it.

How do I execute require to a file that I have created?

Answer

Doug Currie picture Doug Currie · May 28, 2010
require "header"

See the require entry in the Lua Reference manual. The file "header.lua" must be somewhere in Lua's search path.

You can see (and modify) the path at

package.path

See the package.path entry in the the Lua Reference Manual

This wiki page describes ways of creating modules to load with require.