views:

214

answers:

2

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

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

Thanks

+2  A: 

You have loadfileand dofile, more info here

Don
+4  A: 
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.

Doug Currie
require"header" is the correct form for the default path because require use module names not file names.
lhf
Thanks, Luiz. I've edited my answer accordingly.
Doug Currie