开发者

How to create include files in Lua language?

开发者 https://www.devze.com 2023-01-02 00:53 出处:网络
I want to create a header file in Lua (header.lua), then execute the require function to lo开发者_如何学Goad it.

I want to create a header file in Lua (header.lua), then execute the require function to lo开发者_如何学Goad it.

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


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.


require "codelibrary.variables";

Here require will look for a variables.lua file inside codelibrary directory. The . is a cross-platform path separator.


For neovim

Also the config directory can be named differently in different distos:

In my Ubuntu 20.04 it is at $XDG_CONFIG_HOME/nvim in other systems it might be $XDG_CONFIG_HOME/neovim. To the see the correct directory name, open nvim and write :h rtp

0

精彩评论

暂无评论...
验证码 换一张
取 消