如何使用 Lua 中的 require 来访问 Luvit 的内置模块?
How can I use require in Lua to access Luvit's built-in modules?
我 运行 Ubuntu 16.04 服务器 VPS 上的 Luvit 环境用于托管我的项目。这是我当前文件树的图像
我目前在(通过 cd 命令)WrapperTest 文件夹和 运行 main.lua 文件中。这需要 net/socket.
内的服务器文件
感觉每次切换文件时Lua都在改变文件路径。网络在这个项目中是必须,我的文件甚至无法检测到内置模块。
Luvit 提供了很多内置模块如coro-http
,为Lua.
提供HTTP 支持
为什么当我需要一个不同的文件时,我无法检测到正常的模块并且我的整个文件路径都改变了?
编辑:当我在WrapperTest中require 'main'
时,它成功requires
WrapperTest/net/socket/server
。此服务器文件依赖于 WrapperTest/net/
中的 'discordio.lua'。 'discordio.lua' 需要 同一目录 中名为 http-lib
且路径为 require "net/http-lib"
的文件。在 http-lib's
的第一行,它需要一个名为 coro-http
的模块,该模块内置于 Luvit 的解释器中。这失败了,我不知道为什么。
堆栈跟踪(非官方,因为它是 Luvit 错误,不是纯粹的 Lua):
[string "bundle:deps/require.lua"]:278:
No such module 'net/discordio' in '/usr/local/WrapperTest/net/socket/server.lua'
./net/http-lib.lua:1: module 'coro-http' not found:
http
is the 'built-in' library provided by Luvit, mirroring the http
在 Node.
中找到的库
coro-http
is an auxiliary library available for install using the Luvit package manager, lit
,来自 public 软件包存储库。
$ lit install creationix/coro-http
lit
install
命令会将库下载并安装到名为 deps
的本地目录中。
Luvit 提供了一个自定义 require
,应该 在其搜索模式中包含 deps
(并递归递增 deps
目录)。
如果一切都失败了,您可以尝试通过更改 package.path
字段手动调整搜索路径:
package.path = './deps/?.lua;' .. package.path
我 运行 Ubuntu 16.04 服务器 VPS 上的 Luvit 环境用于托管我的项目。这是我当前文件树的图像
我目前在(通过 cd 命令)WrapperTest 文件夹和 运行 main.lua 文件中。这需要 net/socket.
内的服务器文件感觉每次切换文件时Lua都在改变文件路径。网络在这个项目中是必须,我的文件甚至无法检测到内置模块。
Luvit 提供了很多内置模块如coro-http
,为Lua.
为什么当我需要一个不同的文件时,我无法检测到正常的模块并且我的整个文件路径都改变了?
编辑:当我在WrapperTest中require 'main'
时,它成功requires
WrapperTest/net/socket/server
。此服务器文件依赖于 WrapperTest/net/
中的 'discordio.lua'。 'discordio.lua' 需要 同一目录 中名为 http-lib
且路径为 require "net/http-lib"
的文件。在 http-lib's
的第一行,它需要一个名为 coro-http
的模块,该模块内置于 Luvit 的解释器中。这失败了,我不知道为什么。
堆栈跟踪(非官方,因为它是 Luvit 错误,不是纯粹的 Lua):
[string "bundle:deps/require.lua"]:278:
No such module 'net/discordio' in '/usr/local/WrapperTest/net/socket/server.lua'
./net/http-lib.lua:1: module 'coro-http' not found:
http
is the 'built-in' library provided by Luvit, mirroring the http
在 Node.
coro-http
is an auxiliary library available for install using the Luvit package manager, lit
,来自 public 软件包存储库。
$ lit install creationix/coro-http
lit
install
命令会将库下载并安装到名为 deps
的本地目录中。
Luvit 提供了一个自定义 require
,应该 在其搜索模式中包含 deps
(并递归递增 deps
目录)。
如果一切都失败了,您可以尝试通过更改 package.path
字段手动调整搜索路径:
package.path = './deps/?.lua;' .. package.path