13

I need to call the require on a lua file that will not always be in the same place. I was trying to call require on the full path name but that doesn't seem to be working either. I even tried replacing one of my working normal requires with a correct full path name to the same file

example changing require "foo" to require "C:\Users\Me\MyLuaProject\foo"

but when i switched it to the full path name it could no longer find it. So I am wondering if you can even call require on a full path and if not how would i achieve the same result differently?

4

2 に答える 2

17

ファイルをロードする必要があるだけの場合dofileは、次のパスを使用します。

dofile("C:\\Users\\Me\\MyLuaProject\\foo")
于 2012-08-08T17:05:50.107 に答える
14

ファイルを含むディレクトリをpackage.pathに追加します。

package.path = package.path .. ";C:\\Users\\Me\\MyLuaProject"
require "foo"

LUA_PATH 環境変数に追加することもできますが、その場で変更するのはおそらく簡単ではありません。

モジュールの一般的なパターンは、abc.lua と abc/xyz.lua を持つことです。そのようなサブディレクトリ内のファイルを要求するには、次を使用します。

require "abc"
require "abc.xyz"
于 2012-08-08T16:34:25.300 に答える