Lua: Include file in the same directory

瘦欲@ 提交于 2020-06-14 07:50:27

问题


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

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