如何将Lua库添加到项目中并在Visual Studio Code中使用“require”

问题描述 投票:0回答:2

我对 Lua 还很陌生,无法了解如何将 Lua 库添加到项目中以及如何在 Visual Studio Code 中使用“require”

visual-studio-code lua require
2个回答
1
投票

您可以在项目的 launch.json 文件中定义 package.path

package.cpath

你的配置看起来像这样:

"configurations": [
    {
        "type": "lua",
        "request": "launch",
        "name": "Debug",
        "program": "${workspaceFolder}/test.lua",
        "path": "${workspaceFolder}/?.lua;C:\\lua\\?.lua"
    }
]

这些变量如何与

require
一起工作在 Lua 编程:8.1 – require 函数


0
投票

添加@Nifim 的答案。

我在使用

actboy168
制作的 Lua 调试器扩展“Lua Debug”时遇到了同样的问题。使用此扩展时,
package.path
package.cpath
变量默认仅包含您的工作区文件夹。因此,在 UNIX 系统上使用 luarocks 包管理器按 f5 调试 lua 脚本时,无法找到大多数安装在
/usr/local/lib/lua
中的包。

这是一个

launch.json
文件的示例,使您能够使用此类 lua 库:

"configurations": [
    {
        "type": "lua",
        "name": "launch lua debug",
        "cpath": "/usr/local/lib/lua/5.4/?.so",
        "cwd": "${workspaceFolder}",
        "program": "${file}",
        "request": "launch",
    },
]

字段

cpath
用于搜索.so(或者在Windows上可能是.dll)文件,而
path
用于搜索lua脚本。

© www.soinside.com 2019 - 2024. All rights reserved.