How to create include files in Lua language?

十年热恋 提交于 2019-12-05 09:19:05

问题


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?


回答1:


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.




回答2:


You have loadfileand dofile, more info here




回答3:


require "codelibrary/variables";

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



来源:https://stackoverflow.com/questions/2932172/how-to-create-include-files-in-lua-language

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!