问题
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"
Edit: An absolute path works:
dofile(os.getenv("HOME") .. "/.imapfilter/config_local.lua")
Not very elegant, but at least it's compatible with cron
.
回答1:
Add the path to package.path
.
Something like this (not tested):
package.path = package.path .. ";" .. os.getenv("HOME") .. "/.imapfilter/?.lua"
来源:https://stackoverflow.com/questions/5961650/lua-include-file-in-the-same-directory