Lua:将文件包含在同一目录中 [英] Lua: Include file in the same directory
问题描述
我正在使用 IMAPFilter ,我想将全局配置保留在公共存储库,同时将本地(和秘密)配置保留在单独的文件中.因此,我从某个目录运行imapfilter
,它包含〜/.imapfilter/config.lua,而那个应该包含./config_local.lua,其中.".是 config.lua 的目录,不是 shell $PWD
的目录或imapfilter
的位置.到目前为止,这是我尝试过的事情:
I'm using IMAPFilter, and I'd like to keep my global configuration in a public repository, while keeping the local (and secret) configuration in a separate file. So I'm running imapfilter
from some directory, it includes ~/.imapfilter/config.lua, and that should include ./config_local.lua, where "." is the directory of config.lua, not the shell $PWD
or the location of imapfilter
. Here's what I've tried so far:
require "config_local"
require "./config_local"
绝对路径有效:
dofile(os.getenv("HOME") .. "/.imapfilter/config_local.lua")
不太优雅,但至少与cron
兼容.
Not very elegant, but at least it's compatible with cron
.
推荐答案
将路径添加到package.path
.
类似这样的东西(未经测试):
Something like this (not tested):
package.path = package.path .. ";" .. os.getenv("HOME") .. "/.imapfilter/?.lua"
这篇关于Lua:将文件包含在同一目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!