How to create include files in Lua language?

2019-04-18 01:54发布

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?

3条回答
Emotional °昔
2楼-- · 2019-04-18 02:34
require "codelibrary/variables";

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

查看更多
一夜七次
3楼-- · 2019-04-18 02:45
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.

查看更多
看我几分像从前
4楼-- · 2019-04-18 02:47

You have loadfileand dofile, more info here

查看更多
登录 后发表回答