Lua - 将包路径指向父目录中的另一个文件夹

Lua - direct package path to another folder in parent director

我有一个目录:

-parent
    -target
    -current
        -firstChild
            -secondChild

我正在尝试将我的 package.path 从 "secondChild" 内部指向 "target" 以检索藏在那里的其他 .lua 文件夹。我目前有这个设置

package.path = package.path .. ';../?.lua;../?.lua;../?.lua;target/?.lua'

这没有找到我要找的东西,我确信我的部分问题是我不理解所有语法。 “;../?.lua”对我说,我要回到 "firstChild" 并检查是否有 lua 个文件?

我在这里错过了什么?

鉴于您的(更新的)目录结构,您需要在 package.path 中包含 ../../../target/?.lua 以引用 secondChildtarget 文件夹中的模块。 ?.lua 将在 secondChild 中搜索,../?.lua 将在 [=17= 中搜索],../../?.lua 将在 [=19= 中搜索],../../../?.lua 将在中搜索parent../../../target/?.lua 将在 target 中搜索(假设当您启动脚本时您的当前目录是 secondChild 并且还假设 - 不是该目录的一部分姓名)。 ../?.lua 只会使搜索发生在 secondChild 的父级中,而 target/?.lua 会使搜索发生在 secondChild/target/ 文件夹中,该文件夹不存在。

当您尝试 "require" 模块时收到的错误消息包括搜索已检查的所有路径,这通常会提供有关应如何修改搜索路径的线索。