开发者

Lua: Include file in the same directory

开发者 https://www.devze.com 2023-03-04 05:54 出处:网络
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

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.


Add the path to package.path.

Something like this (not tested):

package.path = package.path .. ";" .. os.getenv("HOME") .. "/.imapfilter/?.lua"
0

精彩评论

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