Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create include files in Lua language?

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?

like image 308
Fernando Pinheiro Avatar asked May 28 '10 20:05

Fernando Pinheiro


People also ask

How do I include a file in Lua?

The file "header. lua" must be somewhere in Lua's search path. This wiki page describes ways of creating modules to load with require . require"header" is the correct form for the default path because require use module names not file names.

Can Lua read files?

I/O library is used for reading and manipulating files in Lua. There are two kinds of file operations in Lua namely implicit file descriptors and explicit file descriptors.

What do I do with Lua files?

Lua is used for various purposes, including scripting in applications or on the web, programming games, and adding extensions to databases. Some examples of real-world use of Lua include the customization of World of Warcraft and Dawn of War video games and the programming of the Adobe Lightroom app user interface.


2 Answers

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.

like image 111
Doug Currie Avatar answered Sep 28 '22 01:09

Doug Currie


require "codelibrary/variables"; 

Here require is the method who look variables.lua file inside codelibrary directory

like image 43
Dhiraj Avatar answered Sep 28 '22 00:09

Dhiraj