需要从LUA的另一条路径上的文件

发布于 2025-01-29 22:13:52 字数 404 浏览 3 评论 0原文

问题在于我找不到要使用的LUA文件。

文件系统看起来像这样:

`|-- plugin
    '|-- functions 
        ' -- helpers.lua
 |-- tests
    '|-- integration
    '|-- unit 
        ' -- unittest.lua
`

在UnitTest.lua中,我想使用helpers.lua

package.path = package.path .. ';functions/?.lua'
require('helpers')

,但总会出现错误'no file'。我认为包裹是错误的。如何在unittest.lua脚本中使用helpers.lua脚本?

The problem is that i cant find the lua file to use.

the filesystem looks like this:

`|-- plugin
    '|-- functions 
        ' -- helpers.lua
 |-- tests
    '|-- integration
    '|-- unit 
        ' -- unittest.lua
`

in unittest.lua i want to use the helpers.lua like this

package.path = package.path .. ';functions/?.lua'
require('helpers')

but there comes always an error 'no file'. I think the package.path is wrong. How can i use the helpers.lua script inside the unittest.lua script?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幻梦 2025-02-05 22:13:52

通常,我在与其他两个文件夹所在的同一文件夹中有一个主文件。

首先制作一个名为mainfile.lua的文件(您不必命名),

然后尝试在mainfile.lua中键入此代码(您不必姓名它):

require("tests/unit/unittest")
require("plugin/functions/helpers")

文件夹系统应该像这样:

`|-- new folder
    `|-- plugin
        `|-- functions
            `|-- helpers.lua
    `|-- tests
        `|-- integration
        `|-- unit
            `|-- unittest.lua
    `|-- mainfile.lua

这对我有用,不确定它是否对您有用。
希望这会有所帮助!

usually I have a main file in the same folder as where the other two folders are located.

first make a file named mainfile.lua (you don't have to name it that)

then try typing this code in mainfile.lua (you don't have to name it that):

require("tests/unit/unittest")
require("plugin/functions/helpers")

the folder system should look like this:

`|-- new folder
    `|-- plugin
        `|-- functions
            `|-- helpers.lua
    `|-- tests
        `|-- integration
        `|-- unit
            `|-- unittest.lua
    `|-- mainfile.lua

this works for me, not sure if it will work for you.
hopefully this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文